2013-09-02 2 views
0

원 푸시 알림 응용 프로그램을 개발해야합니다. 고객 로그인에 알림이 성공적으로 생성되고 여기안드로이드에서 다른 활동으로 이동할 때 알림 사용 안 함

@Override 
protected void onMessage(Context context, Intent intent) { 
    Log.i(TAG, "Received message"); 
    GCMRegistrar.checkDevice(this); 
    GCMRegistrar.checkManifest(this); 
    regId = GCMRegistrar.getRegistrationId(this); 
    String message = intent.getExtras().getString("offer"); 
    displayMessage(context, message); 
    // notifies user 
    if(Constants.response != null){ 
    generateNotification(context,message); 
    } 
     } 


    private static void generateNotification(Context context,String message) { 
    int icon = R.drawable.icon; 
    long when = System.currentTimeMillis(); 
    NotificationManager notificationManager = (NotificationManager) 
      context.getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notification = new Notification(icon, message, when); 
    String title = context.getString(R.string.app_name); 
    Intent notificationIntent = new Intent(context, MyDealProducts.class); 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
      Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent intent = 
      PendingIntent.getActivity(context, 0, notificationIntent, 0); 

    notification.setLatestEventInfo(context, title, message, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notification.defaults |= Notification.DEFAULT_SOUND; 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 
    notificationManager.notify(0, notification);  
} 

: 같은

은 내가했다.

이 알림을 방문하지 않은 것과 동시에 고객 양식을 로그 아웃 했으므로 알림을 사용할 필요가 없습니다.

하지만 알림이 활성화되었습니다. 고객을 로그 아웃 한 후 알림을 비활성화 할 수 있습니까 ???

제게 제안 해주세요 ???

답변

0

사용자가 로그 아웃 할 때마다 생성 한 알림을 취소 할 수 있습니다.

cancel(int id) (여기서 id는 알림 ID 인 0) 또는 cancelAll() (NotificationManager)입니다.

+0

감사합니다. 잘 작동합니다. – user2218667