Android的通知后秀活动

编程入门 行业动态 更新时间:2024-10-25 10:24:54
本文介绍了Android的通知后秀活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

I'm尝试recieiving推送通知后,打开活动。

I´m trying to open an activity after recieiving a PUSH notification.

我recieive通知,但是当我选择它什么也没有发生!

I recieive the notification, but when i select it nothing happens!

问题轨迹是:

W/InputMethodManagerService(771): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@438ae618 attribute=null, token = android.os.BinderProxy@4319aab8

下面是我的code

public class GCMIntentService extends IntentService { private static final int NOTIF_ALERTA_ID = 1; public GCMIntentService() { super("GCMIntentService"); } @Override protected void onHandleIntent(Intent intent) { GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); Bundle extras = intent.getExtras(); if (!extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { mostrarNotification(extras.getString("message")); } } GCMBroadcastReceiverpleteWakefulIntent(intent); } private void mostrarNotification(String msg) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent notIntent = new Intent(this, OpenByNotificationActivity.class); PendingIntent contIntent = PendingIntent.getActivity(this, 1, notIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle("Notificación AppMovil") .setContentText(msg) .setContentIntent(contIntent); mNotificationManager.notify(NOTIF_ALERTA_ID, mBuilder.build()); }

和从来就推我的活动清单中

and i´ve putted my Activity in the Manifest

<activity android:name="es.blabla.appmovil.activity.OpenByNotificationActivity" > </activity>

在哪里错误???

Where is the mistake???

谢谢大家!

编辑:

修正   加入安卓出口=真正的我在清单活动

Fixed adding android:exported="true" to my activity in the Manifest

推荐答案

实施这样的:

private void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); String appname = context.getResources().getString(R.string.app_name); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification; PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, myactivity.class), 0); NotificationCompat.Builder builder = new NotificationCompat.Builder( context); notification = builder.setContentIntent(contentIntent) .setSmallIcon(icon).setTicker(appname).setWhen(0) .setAutoCancel(true).setContentTitle(appname) .setContentText(message).build(); notificationManager.notify(0 , notification); }

更多推荐

Android的通知后秀活动

本文发布于:2023-11-27 01:52:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636084.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!