android new intent,android - pendingIntent Don't call OnNewIntent() - Stack Overflow

I receive message in my gcmlistener service and when app is in background , I receive notification but when i tap on it my intent doesn't call OnNewIntent in my main activity . Here is details what I've done

public class MyGcmPushReceiver extends GcmListenerService {

private static final String TAG = MyGcmPushReceiver.class.getSimpleName();

private NotificationUtils notificationUtils;

@Override

public void onMessageReceived(String from, Bundle bundle) {

String title = bundle.getString("title");

String message = bundle.getString("message");

String image = bundle.getString("image");

String timestamp = bundle.getString("timestamp");

Log.e(TAG, "From: " + from);

Log.e(TAG, "Title: " + title);

Log.e(TAG, "message: " + message);

Log.e(TAG, "image: " + image);

Log.e(TAG, "timestamp: " + timestamp);

if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {

.

.

} else {

Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);

resultIntent.setAction(Config.PUSH_NOTIFICATION);

pushNotification.putExtra("message", message);

pushNotification.putExtra("PushReceive","PushReceive");

pushNotification.putExtra("message", message);

pushNotification.putExtra("title", title);

pushNotification.putExtra("timestamp",timestamp);

showNotificationMessage(getApplicationContext(), title, message, timestamp, resultIntent);

}

}

/**

* Showing notification with text only

*/

private void showNotificationMessage(Context context, String title, String message, String timeStamp, Intent intent) {

notificationUtils = new NotificationUtils(context);

notificationUtils.showNotificationMessage(title, message, timeStamp, intent);

}

}

NotificationUtils.class

public void showNotificationMessage(final String title, final String message, final String timeStamp, Intent intent, String imageUrl) {

// Check for empty push message

if (TextUtils.isEmpty(message))

return;

// notification icon

final int icon = R.mipmap.ic_launcher;

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

int requestID = (int) System.currentTimeMillis();

final PendingIntent resultPendingIntent =

PendingIntent.getActivity(

mContext,

requestID,

intent,

PendingIntent.FLAG_UPDATE_CURRENT

);

final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(

mContext);

final Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE

+ "://" + mContext.getPackageName() + "/raw/notification");

if (!TextUtils.isEmpty(imageUrl)) {

.

.

.

} else {

showSmallNotification(mBuilder, icon, title, message, timeStamp, resultPendingIntent, alarmSound);

playNotificationSound();

}

}

private void showSmallNotification(NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) {

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

if (Config.appendNotificationMessages) {

// store the notification in shared pref first

MyApplication.getInstance().getPrefManager().addNotification(message);

// get the notifications from shared preferences

String oldNotification = MyApplication.getInstance().getPrefManager().getNotifications();

List messages = Arrays.asList(oldNotification.split("\\|"));

for (int i = messages.size() - 1; i >= 0; i--) {

inboxStyle.addLine(messages.get(i));

}

} else {

inboxStyle.addLine(message);

}

Notification notification;

notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)

.setAutoCancel(true)

.setContentTitle(title)

.setContentIntent(resultPendingIntent)

.setSound(alarmSound)

.setStyle(inboxStyle)

.setWhen(getTimeMilliSec(timeStamp))

.setSmallIcon(R.mipmap.ic_launcher)

.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))

.setContentText(message)

.build();

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(Config.NOTIFICATION_ID, notification);

}

Manifest.xml

package="hdiz.designnotification" >

android:name="hdiz.designnotification.permission.C2D_MESSAGE"

android:protectionLevel="signature" />

android:allowBackup="true"

android:name=".MyApplication"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/Theme.DesignDemo">

android:noHistory="true"

android:launchMode="singleTask"

android:name=".MainActivity"

android:label="@string/app_name"

>

android:parentActivityName=".MainActivity">

android:value=".MainActivity" />

android:name="com.google.android.gms.gcm.GcmReceiver"

android:exported="true"

android:permission="com.google.android.c2dm.permission.SEND">

android:name="gcm.MyGcmPushReceiver"

android:exported="false">

android:name="gcm.MyInstanceIDListenerService"

android:exported="false">

android:name="gcm.GcmIntentService"

android:exported="false">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值