0
A
回答
0
試試這個:
private void generateNotification(Context context, String message,
long when, String query) {
int icon = R.drawable.icon;
long when = System.currentTimeMillis();
String appname = context.getResources().getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;
Intent intent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
intent, 0);
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
notification = new Notification(icon, message, when);
notification.setLatestEventInfo(context, appname, message,
contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify((int) when, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(appname).setWhen(when)
.setAutoCancel(true).setContentTitle(appname)
.setContentText(message).build();
notificationManager.notify((int) when, notification);
}
希望這有助於。
相關問題
- 1. Android上的捕獲通知
- 2. 在StandOutWindow android中捕獲事件關閉通知?
- 3. 在AspectJ中捕獲通知執行(通知建議)
- 4. 如何捕獲Facebook通知?
- 5. 如何從活動中捕獲通知
- 6. 在Android中獲取通知時間
- 7. 如何在android中獲取BLE通知?
- 8. 關於通知的Android捕獲事件(長按)
- 9. 未捕獲ReferenceError:$未定義Bootsrap通知
- 10. 如何在手機中捕獲本地通知onclick事件
- 11. 在Eclipse/Java應用程序中被捕獲的異常通知
- 12. 獲取通知標題Android
- 13. 獲取當前通知android
- 14. 在Android上獲取MYSQL更新通知
- 15. 在Android中的通知
- 16. 通知計數在android中
- 17. 在android中顯示通知
- 18. 在android中發送通知
- 19. 在android中點擊通知
- 20. android在android中的webView通知android
- 21. Android:從通知欄中刪除通知
- 22. 從android通知欄中刪除通知
- 23. Android的通知中
- 24. 在Android中,如何獲取給定通知ID的當前顯示通知?
- 25. Android onCreate()未通知通知
- 26. 捕通知,並做一些
- 27. 如何捕捉C2DM通知?
- 28. iphone動畫 - 捕通知
- 29. 如何在Android webview中通過ID捕獲元素點擊?
- 30. 在Android中捕獲圖像並通過彩信發送
看看[這](http://stackoverflow.com/a/13716784/896038),我想這就是你需要的。 –