2017-12-28 5 views

Antwort

0

zuerst sollten wir die Mitteilung erstellen, die eine Tätigkeit nennen:

Intent intent = new Intent(this, YourClass.class); 
intent.putExtra("NotiClick",true); 
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { 
    Notification Noti; 
    Noti = new Notification.Builder(this) 
      .setContentTitle("YourTitle") 
      .setContentText("YourDescription") 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentIntent(pIntent) 
      .setAutoCancel(true).build(); 

    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

    notificationManager.notify(0, Noti); 
} 

Dann in dem onCreate() Ihre Klasse dies zu tun:

Bundle extras = getIntent().getExtras(); 

if(extras == null) 
{ 
    //not being clicked on 
} 
else if (extras.getBoolean("NotiClick")) 
{ 
    //being clicked 
} 

und für vollständig Schließen Sie die Anwendung können Sie töten Prozess:

android.os.Process.killProcess(android.os.Process.myPid()); 
Verwandte Themen