0
A
回答
1
您可以通過註冊廣播接收器來完成此操作。這樣,您可以在點擊通知時在接收器中運行代碼,而無需顯示任何UI。
基本接收器代碼:
public class Provider extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
//Your code here
}
}
在清單:
public static void showNotification(Context context) {
CharSequence title = "title";
CharSequence message = "text";
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(<image>, title, System.currentTimeMillis());
notification.flags = Notification.FLAG_ONGOING_EVENT;
Intent notificationIntent = new Intent(context, Provider.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, pendingIntent);
notificationManager.notify(<notification id>, notification);
}
:爲通知
<receiver android:name="Provider" />
示例代碼
相關問題
- 1. 點擊通知區域沒有顯示消息在活動
- 2. 點擊通知沒有打開活動
- 3. 沒有點擊事件的Android通知?
- 4. mouseDown事件沒有顯示點擊
- 5. ACRA顯示通知,然後沒有對話框通知點擊
- 6. 如何在沒有點擊通知的情況下顯示活動
- 7. 點擊通知沒有啓動預期的活動?
- 8. 如何在點擊通知時顯示相同的活動?
- 9. 爲什麼點擊通知時不顯示活動?
- 10. 當通知點擊事件時致電活動
- 11. 點擊通知沒有打開提到的活動
- 12. 從AppWidget顯示現有活動點擊
- 13. 點擊通知未啓動活動
- 14. 點擊通知不啓動活動
- 15. 信息沒有顯示在通知上點擊android
- 16. 無法打開通知點擊活動
- 17. 當點擊通知時更新活動
- 18. 當點擊通知時恢復活動
- 19. 當通知的點擊,打開活動
- 20. 打開新的活動通知點擊
- 21. 點擊通知開始活動兩次
- 22. On Item點擊gridview我的下一個活動沒有顯示
- 23. 通過點擊通知圖標在鎖屏上方顯示Android活動
- 24. asp.net點擊事件沒有啓動
- 25. jBox沒有顯示通知
- 26. Mozilla通知顯示點擊瀏覽器
- 27. 活動沒有顯示
- 28. Android活動沒有顯示
- 29. Android通知PendingIntent每通知點擊打開活動
- 30. 打開通知活動時點擊通知與firebase