0

ユーザーがウィンドウを表示せずに通知バーのテキストをクリックしたときにアプリを閉じるにはどうすればよいですか?

4

2 に答える 2

1

通知の使用を作成するgetBroadcast

Intent intent = new Intent("action_close_app");

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

通知をクリックすると、アクションaction_close_appでブロードキャストが送信されます。受信を処理するには、ブロードキャストレシーバーを登録する必要がありaction_close_appます。アプリを閉じるだけです。

于 2012-02-10T04:11:16.450 に答える
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)
于 2012-02-10T05:46:15.890 に答える