Skip to content

Commit

Permalink
Added PendingIntent.CanceledException workaround.
Browse files Browse the repository at this point in the history
  • Loading branch information
lzanita09 committed Jun 7, 2014
1 parent d2afe9b commit 4aa1e53
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
* <p/>
* 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;
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4aa1e53

Please sign in to comment.