diff --git a/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationClicker.java b/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationClicker.java index 27d18cb..ea99f18 100644 --- a/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationClicker.java +++ b/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationClicker.java @@ -1,21 +1,28 @@ package com.reindeercrafts.notificationpeek.peek; import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; import android.view.View; /** * OnClickListener class that performs launching apps from the notification. - * + *
* Created by zhelu on 5/18/14. */ public class NotificationClicker implements View.OnClickListener { + private Context mContext; + private PendingIntent mPendingIntent; private NotificationPeek mPeek; - public NotificationClicker(PendingIntent contentIntent, NotificationPeek peek) { + public NotificationClicker(Context context, PendingIntent contentIntent, + NotificationPeek peek) { + this.mContext = context; this.mPendingIntent = contentIntent; this.mPeek = peek; } @@ -26,7 +33,11 @@ public void onClick(View v) { try { mPendingIntent.send(); } catch (PendingIntent.CanceledException e) { - e.printStackTrace(); + // Something is wrong while sending the PendingIntent, just launch the app. + PackageManager packageManager = mContext.getPackageManager(); + Intent intent = + packageManager.getLaunchIntentForPackage(mPendingIntent.getCreatorPackage()); + mContext.startActivity(intent); } mPeek.onPostClick(); diff --git a/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeek.java b/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeek.java index 1387619..fc3821f 100644 --- a/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeek.java +++ b/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeek.java @@ -601,7 +601,8 @@ private void updateSelection(StatusBarNotification n) { final PendingIntent contentIntent = n.getNotification().contentIntent; if (contentIntent != null) { - mNotificationIcon.setOnClickListener(new NotificationClicker(contentIntent, this)); + mNotificationIcon + .setOnClickListener(new NotificationClicker(mContext, contentIntent, this)); } else { mNotificationIcon.setOnClickListener(null); } diff --git a/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeekActivity.java b/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeekActivity.java index 459c79b..105b481 100644 --- a/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeekActivity.java +++ b/NotificationPeekPort/src/main/java/com/reindeercrafts/notificationpeek/peek/NotificationPeekActivity.java @@ -197,7 +197,7 @@ private boolean updateNotification(String description) { final PendingIntent contentIntent = nextNotification.getNotification().contentIntent; if (contentIntent != null) { NotificationClicker mNotificationClicker = - new NotificationClicker(contentIntent, mPeek); + new NotificationClicker(this, contentIntent, mPeek); mNotificationIcon.setOnClickListener(mNotificationClicker); } else { mNotificationIcon.setOnClickListener(null);