我想用進度條和刪除按鈕創建自定義通知。Android 4.0自定義通知,如谷歌音樂
截圖:
我成功創建了進度條的自定義通知,但我沒能創造刪除事件。我想取消通知並停止上傳,一旦用戶點擊「x」(如在谷歌音樂中,所以我不想開始一個活動來清除通知)。
這是我工作的代碼:
notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(context, UploadEventsReceiver.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.contentView = new RemoteViews(context.getPackageName(), R.layout.upload_progress);
notification.contentView.setOnClickPendingIntent(R.id.text, contentIntent);
notificationManager.notify(this.notificationId, notification);
在生產線
Intent notificationIntent = new Intent(context, UploadEventsReceiver.class);
我與廣播接收機嘗試沒有「廣播」,但我不知道這是否是做的正確方法它和我沒有成功,使其工作。我應該使用什麼以及如何使用它?
尼斯,我正要實現我剛纔在你的屏幕截圖發現:整潔的硬件控制切換,例如WiFi,旋轉或飛行模式。你正在運行定製ROM還是你在市場上找到了?感謝您的幫助,祝您的項目順利。 – stfn 2012-01-03 16:48:47