2015-11-05 89 views
0

我正在使用桌面的头部单元,我有以下代码将对话推到单位,请记住我对挂起的意图设置null,因为我不需要任何挂钩/回调。我只想在android auto激活时发送通知。这里不工作的代码:Android自动 - 代码推unreadConversation不工作

private void pushAndroidAutoUnreadConversation(String msg) { 
// Build a RemoteInput for receiving voice input in a Car Notification 
RemoteInput remoteInput = new RemoteInput.Builder(MY_VOICE_REPLY_KEY) 
.setLabel(msg) 
.build(); 

// Create an unread conversation object to organize a group of messages 
// from a particular sender. 
UnreadConversation.Builder unreadConvBuilder = 
new UnreadConversation.Builder("my apps conversation") 
    .setReadPendingIntent(null) 
    .setReplyAction(null, remoteInput); 

unreadConvBuilder.addMessage(msg) 
.setLatestTimestamp(System.currentTimeMillis()); 


Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), 
R.drawable.icon); 


NotificationCompat.Builder notificationBuilder = 
new NotificationCompat.Builder(getApplicationContext()) 
    .setSmallIcon(R.drawable.icon) 
    .setLargeIcon(largeIcon).setContentTitle(msg); 

notificationBuilder.extend(new NotificationCompat.CarExtender() 
.setUnreadConversation(unreadConvBuilder.build())); 

NotificationManagerCompat msgNotificationManager = 
NotificationManagerCompat.from(this); 
msgNotificationManager.notify("my_apps_tag", 
Integer.parseInt(MY_VOICE_REPLY_KEY), notificationBuilder.build()); 

} 

MY_VOICE_REPLY_KEY只是一个数字,其9675

这里是我的build.gradle文件:

应用插件: 'com.android.application'

android { 
    compileSdkVersion 21 
    buildToolsVersion "23.0.1" 

    defaultConfig { 
     applicationId "org.myapp.easy" 
     minSdkVersion 9 
     targetSdkVersion 21 
    } 

    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('old_proguard-android.txt') 
     } 
    } 
} 

dependencies { 
    compile files('libs/GoogleAdMobAdsSdk-4.1.1.jar') 
    compile 'com.android.support:support-v4:21.0.2' 
} 

这里是清单的一部分:

<application 
     android:allowBackup="false" 
     android:icon="@drawable/icon" 
     android:label="@string/app_name" > 

     <meta-data android:name="com.google.android.gms.car.application" 
      android:resource="@xml/automotive_app_desc" /> 

,这里是automotive_app_desc.xml我放在XML文件夹:

<automotiveApp> 
    <uses name="notification"/> 
</automotiveApp> 

我下面的官方教程here

当我创建一个物理通知假设出现在通知我假设在Android自动仪表板上,我什么都看不到。但在移动设备上,我看到了我的通知。让我解释发生了什么。我在插入汽车之前创建消息方式。所以这个方法在用户从车上断开时运行。当用户连接到android auto im期望这个通知应该显示在仪表板上,但它不是,但我看到它在移动设备通知托盘上。

回答

1

终于找到了问题。我正在传递null以等待意图。它不想要那样。我不得不做出的消息听取和信息回复未决的意图和实际设置他们在UnreadConversation.Builder这样的:

UnreadConversation.Builder unreadConvBuilder = 
      new UnreadConversation.Builder("reminder note") 
        .setReadPendingIntent(msgHeardPendingIntent) 
        .setReplyAction(msgHeardPendingIntent, remoteInput); 

所以它不喜欢为null setReadPendingIntent & setReplyAction看来。