2012-02-10 72 views

回答

1

使用下面的代碼,並在你的活動註冊廣播接收器:

NotificationManager mNotificationManager = (NotificationManager)_context.getSystemService(Context.NOTIFICATION_SERVICE); 

Notification notification = new Notification(R.drawable.icon,"",System.currentTimeMillis()); 
notification.flags = Notification.FLAG_AUTO_CANCEL; 


Context context = _context.getApplicationContext(); 


/** Set the intent extras to be passed to calling activity*/ 
Intent notificationIntent = new Intent("action_close_app"); 



/** Create a pending intent, requires to generate a notification */ 

PendingIntent contentIntent = PendingIntent.getBroadcase(
    _context.getApplicationContext(), requestCode, 
    notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 


/** Set notification with required fields */ 

notification.setLatestEventInfo(context, "", "", contentIntent); 



/** notify manager to generate notification on status bar*/ 

mNotificationManager.notify(NOTIFICATION_ID, notification) 
+0

謝謝!它很棒!我希望有一個來自vb6天的人有更優雅的解決方案。 – Daniel 2012-02-10 14:58:01

1

創建通知使用getBroadcast

Intent intent = new Intent("action_close_app");

PendingIntent closeIntent = PendingIntent.getBroadcast(context, requestCode, intent, flags)

當您單擊該通知,將發送一個廣播一起行動action_close_app,你需要註冊一個廣播接收器來處理action_close_app接受,只是關閉你的應用。

相關問題