Android Auto is also available on phone screens, giving users the full Android Auto experience entirely on the phone without needing to connect to a compatible vehicle. With this standalone, handheld version of Android Auto, users can still use voice to handle calls, messages, music, and navigation, using an interface designed for driving.
Android Auto也可以在手机屏幕上使用,让用户完全可以在手机上体验到完全的Android体验,而不需要连接到兼容的车辆。有了这个独立的,手持版本的Android Auto,用户仍然可以使用声音来处理呼叫,消息,音乐和导航,使用一个设计的接口来驱动。
You can enable your existing audio and messaging apps developed for phones and tablets to work in the car, without having to worry about vehicle-specific hardware differences. To enable your app for Auto, your app must target Android 5.0 (API level 21) or higher. Adding support for Android Auto to your existing app will enable it to work on both car and phone screens. Android Auto handles most of the work to adjust each application’s user interface to the screen on which it is displayed. Your app’s manifest must also declare the car capabilities that it uses, such as audio playback or messaging services.
你可以让你现有的音频和短信应用程序开发出来,用于手机和平板电脑,而无需担心特定于车辆的硬件差异。为了让你的app应用于车辆,你的target api必须大于等于21。
要开发应用于车辆的app,你必须做两件事
- Android 5.0 (API level 21) provides new APIs for implementing audio playback and messaging that is compatible with Auto. To access the new APIs, create a project or modify an existing project to target Android 5.0 (API level 21) or higher. This means you must set the manifest targetSdkVersion to 21 or higher.
- If you are building messaging apps for Auto, you need the NotificationCompat.CarExtender class contained in the v4 support library. This class allows you to create notifications that are compatible with Auto devices。
第一就是targetSdkVersion 大于等于21,第二就是在gradle中加入V4包。
Manifest相关配置
<application>
...
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
...
<application>
在 res/xml/ 的文件夹下创建 automotive_app_desc.xml,内容为
<automotiveApp>
<uses name="media"/>
</automotiveApp>