/*Google AdSense自動広告*/

2013年11月16日土曜日

【Android開発Tips】Intentの無いNotificationを作る(通知のみを行いたいとき)

Notification notification = new Notification(android.R.drawable.ic_menu_view, null, System.currentTimeMillis());
        notification.flags = Notification.FLAG_NO_CLEAR;
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, null, 0);
        notification.setLatestEventInfo(this, null, null, pendingIntent);
        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, notification);

とすると機種によっては落ちる、アプリだけでなく端末が再起動してしまうこともある。
解決方法は
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, null, 0);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
とすること。なんだろうこの直感的でない挙動は・・・

http://stackoverflow.com/questions/7040742/android-notification-manager-having-a-notification-without-an-intent

0 件のコメント:

コメントを投稿