android auto 学习分享

项目组需要学习下android auto。今天先把一些分享记录下来,暂时只能搞懂message例子,media的例子还在学习中。

                                                  android auto介绍

1. 本质上:手机 app ,平台级应用。
2. android 版本要求: 5.0 以上
3. 作用:能将手机中符合 android auto 的应用延伸到汽车。
4. 主要功能
    导航
(语音 导航 ,暂时用 Google map ,新版本会加入 Waze 地图 应用 ),
    电话( 接听电话和 语音 拨号)
    短信 (语音 和回复 短信),
    音乐
5. 用户使用过程:
   a. 手机上装有
android auto 应用。
   b. 使用 usb 将手机接入汽车中控。
   c. 中控屏幕上会出现 android auto 的图标,点击进入 android auto 界面。


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

is deprecated.

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



  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值