1
我正在構建一個應用程序,該軟件在調用BroadcastReceiver時顯示帶有兩個選項「Dim」和「Full」的通知。每個按鈕都會廣播一個動作。軟糖果凍通知操作已禁用
到目前爲止一切皆有可能,對吧?
問題是,通知上顯示的按鈕不響應水龍頭,但整個通知確實(如果我點擊圖標或文字而不是按鈕)。
我有這個功能來構建通知:
private Notification buildReleaseNotification(NotificationManager nManager, Context context) {
Notification.Builder builder = new Builder(context);
builder.addAction(R.drawable.rate_star_big_half_holo_dark, "Dim", buildPendingIntent(context, DIM));
builder.addAction(R.drawable.rate_star_big_on_holo_dark, "Full", buildPendingIntent(context, FULL));
builder.setContentTitle("Car notification");
builder.setContentText("Freed");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setOngoing(true);
Notification notification = builder.build();
return notification;
}
和接收到廣播時,它被稱爲:
public void onReceive(Context context, Intent intent) {
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noty = null;
noty = buildReleaseNotification(context);
startService(context, RELEASE);
if (noty != null) {
nManager.notify(ChangeLockService.GLOBAL_TAG, ID, noty);
}
}
------編輯
只注意到下面的函數返回null ...那麼,我怎麼能建立一個掛起的意圖來執行廣播?
private PendingIntent buildPendingIntent(Context context, String action) {
Intent i = new Intent(action);
PendingIntent pi = PendingIntent.getBroadcast(context, ID, i, Intent.FLAG_RECEIVER_REPLACE_PENDING);
return pi;
}
請將代碼發佈到'buildPendingIntent()'。 – CommonsWare
@CommonsWare問題更新。謝謝! –
你是說這些按鈕甚至不會對觸摸做出響應(即按下時沒有瞬間突出顯示),或者您的廣播從未收到過? – dsandler