2017-05-29 15 views
1

こんにちは私は私のアプリケーションで通知を表示する以下の機能を持っていますが、突然私が指定したアクティビティに私を連れてこない.setContentIntentは()、これは私のコードです:保留中のインテントが動作しない、アクティビティがアクティビティを開かない

@TargetApi(Build.VERSION_CODES.LOLLIPOP) 
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) 
private void getNotifications() { 
    ArrayList<com.xxxxxx.app234929.models.Notification> notifications = mNotificationsTable.get(); 

    int requestId = (int) System.currentTimeMillis(); 
    Intent notificationsIntent = new Intent(getApplicationContext(), NotificationsActivity.class); 
    notificationsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), requestId, 
      notificationsIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(getApplicationContext()) 
      .setSmallIcon(R.drawable.ic_stat_mtgh_notification) 
      .setColor(getResources().getColor(R.color.colorPrimary)) 
      .setContentTitle("xxxxxx") 
      .setContentText("You have "+(notifications.size() > 1 ? "new updates" :"a new update")) 
      .setNumber(notifications.size()) 
      .setContentIntent(intent) 
      .setDefaults(Notification.DEFAULT_VIBRATE | 
        Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)) 
      .setBigContentTitle("xxxxxx"); 

    for (int i=0; i < notifications.size(); i++) { 
     inbox.addLine(notifications.get(i).getMessage()); 
    }; 

    Notification notification = inbox.build(); 

    NotificationManager notificationManager = (NotificationManager) getApplicationContext() 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(1, notification); 
} 

私はソリューションの多くをGoogleで検索し、それらを試してみましたが、それらのどれもが、今私は私がここで間違ってやっているかわからないので、私のために働いていないきました。

+0

を私は彼の活動の名称を変更し、それが働いた、戻ってそれを変更し、それ私はそれがちょうどそれらのものの一つだと言うつもりだ、後で私のコードを通過し、本当の問題があったかを確認します。 – user3718908

答えて

0

これは私が使用したコードであると完璧に動作し、私はサービスにそれを持っていますが、何らかの活動に使用することができます。

Intent myIntent = new Intent(MyActivity.this, ActivityIWantToOpenOnClick.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(MyActivity.this, 0, myIntent, Intent.FLAG_ACTIVITY_NEW_TASK); 

NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(MyActivity.this); 
ncomp.setContentTitle("Message Tittle"); 
ncomp.setContentText("Message Text"); 
ncomp.setTicker("Message Ticker");         
ncomp.setSmallIcon(R.drawable.your_icon); 
ncomp.setAutoCancel(true); 
ncomp.setContentIntent(pendingIntent); 
nManager.notify((int) System.currentTimeMillis(), ncomp.build()); 
関連する問題