請您幫我解決下面的問題嗎?防止在通知中處理自定義操作時打開屏幕的設備
我創建了一個簡單的應用程序,顯示收到的SMS通知。在該通知中,我添加了一個按鈕來通過通知刪除SMS。
由於我有一個Samsung Gear S2,該智能手錶上顯示該刪除按鈕,我可以使用我的Gear S2刪除該SMS。
主要問題是,當我使用Gear S2刪除短信時,屏幕正在喚醒。當我使用Gmail進行測試時,同樣的情況就是刪除電子郵件並關閉屏幕。
所以,你可以請,幫我看看爲什麼屏幕打開?
這裏是我如何創建通知(收到短信後)。
// Intent used to delete the SMS
Intent deleteIntent = new Intent(context, MessagingService.class);
deleteIntent.putExtra("notiID", id);
deleteIntent.putExtra("address", address);
deleteIntent.putExtra("date", date);
deleteIntent.putExtra("body", body);
PendingIntent deletePendingIntent = PendingIntent.getService(
context,
id,
deleteIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Intent used to start the app
Intent clickIntent = new Intent(context, MainActivity.class);
PendingIntent clickPendingIntent = PendingIntent.getActivity(
context,
id + 1,
clickIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Notification
NotificationCompat.Builder notiBuilder = new NotificationCompat.Builder(context);
notiBuilder.setSmallIcon(R.drawable.ic_message_white_32dp)
.setContentTitle(address)
.setContentText(body)
.setContentIntent(clickPendingIntent)
.addAction(R.drawable.ic_delete_white_32dp, context.getString(R.string.delete), deletePendingIntent)
.setLights(Color.BLUE, 3000, 3000);
Notification mNotificationBar = notiBuilder.build();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
mNotificationManager.notify(id, mNotificationBar);
我測試:
現在,我動 「短信刪除」 代碼爲Service
。這就是爲什麼我使用:
Intent deleteIntent = new Intent(context, MessagingService.class);
PendingIntent deletePendingIntent = PendingIntent.getService(....);
但我也試圖刪除使用廣播接收器(相同的結果)的短信:
Intent deleteIntent = new Intent(context, SmsReceiver.class);
deleteIntent.setAction("com.test.simplesms.DELETE_MESSAGE");
PendingIntent deletePendingIntent = PendingIntent.getBroadcast(....);
所以,我不知道爲什麼被deletePendingIntent
配置的操作正在打開屏幕。