通知をクリックした時に、任意のアクティビティを起動させるには

10 views
Skip to first unread message

rag...@gmail.com

unread,
Feb 11, 2016, 10:29:16 PM2/11/16
to Android Developers Japan
初めて投稿させて頂きます。

環境としてはandroid 6.0.1 の nexus6で開発しています。
やりたいこととしては、Notification(通知)を表示し、その通知を選択した場合に、任意のアクティビティを表示させる・・ということです。
以下のソースは通知処理の抜粋になりますが、サービスのonStartCommand()の中に記載しています。

様々なサイトを参考にし、PendingIntent.getActivityの第二引数を0にしたり、1000以上にしたりランダムにしたり、
第四引数を「FLAG_UPDATE_CURRENT」や「FLAG_CANCEL_CURRENT」に変えたりとやりましたが動きませんでした。

「動かない」とは、通知をタッチすると、MainActivityが起動するのではなく、「アプリ情報」が起動する挙動となります。
「アプリ情報」とはバージョン情報とともに「強制停止」や「アンインストール」などのボタンが表示されているandroid設定の中にある?画面です。

もし、対応方法ご存じの方いらっしゃいましたら、以下のソースをどのように変更すればいいのか?ご教授お願いしたく思います

ソース =========================================================================================

Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(100);

Intent notificationIntent = new Intent(this.getApplicationContext(), MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), randomInt, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

Notification notification = new NotificationCompat.Builder(this.getApplicationContext())
    .setContentTitle("Test")
     .setTicker("Test")
    .setContentText("Back Service")
    .setContentIntent(contentIntent)
    .setOngoing(true)
    .build();

startForeground(101, notification);

ソース =========================================================================================

以上、よろしくお願い致します。
Reply all
Reply to author
Forward
0 new messages