2017-07-09 14 views
0

私はAndroidプログラミングの初心者です。クリックした通知でアクティビティが開かれない

私は通知を受け取りますが、私のmessageActivityが開かれていない

NotificationManager notificationManager = (NotificationManager) 
            getSystemService(NOTIFICATION_SERVICE); 
          NotificationCompat.Builder mbuilder = new NotificationCompat.Builder(getApplicationContext()) 
            .setContentTitle("Message from " + name) 
            .setContentText(message) 
            .setAutoCancel(true) 
            .setSmallIcon(R.mipmap.ic_launcher) 
            .setSound(soundUri); 
          if (strVibratePreference) 
           mbuilder.setVibrate(new long[]{100, 100}); 
          notificationManager.notify(110, mbuilder.build()); 
          Intent intent=new Intent(MessageService.this,MessageActivity.class); 
          intent.putExtra("name",name); 
          intent.putExtra("phno",_from); 
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
          PendingIntent pendingIntent = PendingIntent.getActivity(MessageService.this,0,intent,0); 
          mbuilder.setContentIntent(pendingIntent); 

答えて

0

Notification n = mbuilder.build(); 
notificationManager.notify(YOUR_NOTIF_ID, n); 
0
Intent intent = new Intent(MessageService.this, MessageActivity.class); 
          intent.putExtra("name",name); 
          intent.putExtra("phno",_from); 
          PendingIntent pIntent = PendingIntent.getActivity(MessageService.this, (int) System.currentTimeMillis(), intent, 0); 

          // Build notification 
          // Actions are just fake 
          Notification noti = new Notification.Builder(MessageService.this) 
            .setContentTitle("New mail from " + "[email protected]") 
            .setContentText("Subject") 
            .setContentIntent(pIntent) 
            .setSmallIcon(R.mipmap.ic_launcher) 
            .build(); 

          NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
          // hide the notification after its selected 
          noti.flags |= Notification.FLAG_AUTO_CANCEL; 

          notificationManager.notify(0, noti); 
この終了コードを追加します
関連する問題