2016-08-13 5 views
1

알림을 클릭하면 주 활동을 시작하겠습니다. 사용자가 앱에없는 경우에도 마찬가지입니다. 어떻게해야합니까? 모든클릭 알림에서 활동 시작

NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this) 
         .setSmallIcon(R.drawable.diamond) 
         .setContentTitle("Crystallise") 
         .setContentText("making your thoughts crystal clear"); 
NotificationManager mNotificationManager = 
     (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(notifyID, mBuilder.build()); 

답변

1

먼저 당신이 PendingIntent 필요

당신의 NotificationCompat.Builder에서 다음
Intent intent=new Intent(mContext, Activity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
PendingIntent notificationIntent= PendingIntent.getActivity(mContext,requestCode, intent,PendingIntent.FLAG_UPDATE_CURRENT); 

이 추가 : 고유의 요청 코드를 사용하기 위해 .setContentIntent(notificationIntent)

을이 : int requestCode=(int)System.currentTimeMillis();

당신은이를 사용할 수 있습니다 비 활동 수업도 있습니다 (예 : Service, BroadcastReceiver). 그런 다음 닫힌 상태에서도 앱이 실행됩니다.

1

// 공개 활동을 위해 의도와 PendingIntent를 추가

Intent attendanceIntent = new Intent(getApplicationContext(), Details.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, 
       attendanceIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(this) 
        .setSmallIcon(R.drawable.diamond) 
        .setContentTitle("Crystallise") 
        .setContentIntent(pendingIntent) 
        .setContentText("making your thoughts crystal clear"); 
    NotificationManager mNotificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotificationManager.notify(notifyID, mBuilder.build()); 
관련 문제