2015-11-05 84 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看來。