2017-12-28 18 views
-1

간단한 알림을 만들려면 어떻게해야합니까? 클릭하면 응용 프로그램이 닫힙니다 (멀티 태스킹)? 감사. 에서 onCreate (에 그런클릭하면 앱을 종료하는 알림을 어떻게 만듭니 까?

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); 
} 

) 클래스의이 수행 :

Bundle extras = getIntent().getExtras(); 

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

완전히에 대한을 (자바, 안드로이드)

+2

가능한 복제본 응용 프로그램을 닫으려면 [알림 표시 줄을 클릭하십시오] (https://stackoverflow.com/questions/9222406/notification-bar-click-to-close-app) –

답변

0

먼저 우리가 활동을 호출 알림을 만들어야합니다 당신이 프로세스를 죽일 수있는 가까운 응용 프로그램 :

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