项目组需要学习下android auto。今天先把一些分享记录下来,暂时只能搞懂message例子,media的例子还在学习中。
android auto介绍
导航 (语音 导航 ,暂时用 Google map ,新版本会加入 Waze 地图 应用 ),
5. 用户使用过程:
a. 手机上装有 android auto 应用。
b. 使用 usb 将手机接入汽车中控。
Android auto调试和开发
一. 调试:
参考资料:
https://developer.android.com/training/auto/testing/index.html
1. 模拟器安装
打开android studio 的SDK Manager,选择SDK Tools,下载安DHU。
Open the SDK Manager and download theDHU packageAndroid Auto Desktop Head Unit emulator from the SDK Toolstab.
如下图:
android auto apisimulators:以前的模拟器,安装在手机上的,官网上不赞成使用。
Useof the Android Media Browser and Messaging Simulators for testing Android Auto app
Android auto Desktop Head Unit emulator :官方支持使用的模拟器。
2. 启动DHU
a. enableAndroid Auto developer mode,tapping the AndroidAuto toolbar title 10 times。点击android auto应用程序的标题栏10次。
b. 启动手机androidauto 的head unit server。
c. 使DHU连接到headutil server :
adb forward tcp:5277 tcp:5277
d. 启动DHU
cd <sdk>/extras/google/auto
./desktop-head-unit
注意:使用Android Auto必须安装Google地图,googleplay音乐…google应用。
二. Message app开发
1. 配置manifest.xml
<application>
….......
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/auto_desc "/>
….......
</application>
auto_desc.xml内容:
<automotiveApp>
<usesname=“notification”/> 只支持2种:media和notification。
</automotiveApp>
2. 导入依赖包
在build.gradle 中加入v4包,必须21版本或者以上的v4包。
{ ...
compile ‘com.android.support:support-v4:21.0.2’
}
3. 创建2个BroadcastReceiver,分别处理读取短信和回复事件。
4. 构造通知并发送。
主要使用NotifcationCompat.build产生Notification对象,这与普通的通知开发一样。唯一不同的是:android auto的nofitication中多了一个CarExtender对象数据。
UnreadConversation 封装了android auto需要的数据,
private final String[] mMessages; 短信内容
private final RemoteInput mRemoteInput; 远端输入
private final PendingIntent mReplyPendingIntent; 回复时触发
private final PendingIntent mReadPendingIntent; 读取时触发
private final String[] mParticipants; 发件人
private final long mLatestTimestamp; 时间戳
CarExtender:有成员变量mUnreadConversation,
是UnreadConversaiton 对象。
extend(NotificationCompat.Builder builder):
将mUnreadConversation的内容存到 builder的 mExtas(Bundle)中。
至此,将android auto所需的所有数据存到了NotifcationCompat.build
对象的mExtas中。最后发送通知。
NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(getApplicationContext());
mNotificationManager发送通知。
代码例子 http://download.csdn.net/detail/fengyun703/9535044