2013-03-27 3 views
-1

내 앱에서 알림을 설정했습니다. 잘 작동합니다. statusbar에서 알림을 클릭하면 앱에 걸립니다.
알림을 클릭하면 설정해야합니다. 어디에서 설정할 수 있습니까? 알림을 클릭 할 때 암시 적으로 호출 된 메서드가 있습니까?
또한 클릭 한 경우 해당 알림을 제거하려면 어떻게해야합니까? 알림을위한 onclicklistener

당신은에서 onCreate와 onNewIntent 방법에 대한 귀하의 활동 모습에서 그 의도에 몇 가지 여분의 데이터를 추가 할 수 내 코드

notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
Intent inty=getIntent(); 
note = new Notification(R.drawable.icon, "New E-mail", System.currentTimeMillis()); 
PendingIntent intent = PendingIntent.getActivity(MainActivity.this, 0, inty, 0); 
note.setLatestEventInfo(MainActivity.this, "New E-mail", "You have one unread message.", intent); 
notifManager.notify(R.string.search_hint, note); 

답변

1

입니다. 예를 들어

: 그런 다음 getIntent를 사용하여 onNewIntent 또는에서 onCreate에 전달 된 의도()를 사용해 그를 읽을 수

inty.putExtra("came from notification", true); 

.

intent.getBooleanExtra("came from notification", false); 
1

봅니다 브로드 캐스트 리시버를 전화로 할 수있다, 당신의 요구 사항에 대한 도움이

Intent notificationIntent = new Intent(this, dummy_activity.class); 
notificationIntent.setAction("android.intent.action.MAIN"); 
notificationIntent.addCategory("android.intent.category.LAUNCHER"); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
           notificationIntent, 
           PendingIntent.FLAG_UPDATE_CURRENT | 
           Notification.FLAG_AUTO_CANCEL); 

// Now, once this dummy activity starts send a broad cast to your parent activity and finish the pending activity 
//remember you need to register your broadcast action here to receive. 
BroadcastReceiver call_method = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     String action_name = intent.getAction(); 
     if (action_name.equals("call_method")) { 
      // call your method here and do what ever you want. 
     } 
    } 
}; 
registerReceiver(call_method, new IntentFilter("call_method"));