Android 通知后显示活动
我在收到推送通知后尝试打开活动 我收到了通知,但当我选择它时,什么也没有发生 问题是:Android 通知后显示活动,android,notifications,push-notification,Android,Notifications,Push Notification,我在收到推送通知后尝试打开活动 我收到了通知,但当我选择它时,什么也没有发生 问题是: 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 这是
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
这是我的密码
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"));
}
}
GCMBroadcastReceiver.completeWakefulIntent(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());
}
我已经把我的活动记录在清单上了
<activity android:name="es.blabla.appmovil.activity.OpenByNotificationActivity" >
</activity>
错在哪里
谢谢大家
编辑:
固定的
将android:exported=“true”添加到清单中的我的活动中实现以下操作:
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);
}
尝试以下操作:
pendingent contIntent=pendingent.getActivity(this,0,notIntent,0)代码>第二步,当您创建Intent notIntent
fixed时,您需要传递Context
!!将android:exported=“true”添加到Manifest@SV您的方法是正确的,但有一个问题是,用户正在将此操作传递到服务中,您需要在new Intent(context,myactivity.class)
中传递上下文,那么这是如何实现的呢?基本上,当您调用gcminentservice()时,您可以在其中传递context参数,并在其中指定this.context。@SV这就是我要说的+1为你的超棒asnwer加油。不起作用。。。我使用generateNotification(getApplicationContext(),extras.getString(“message”))调用该方法代码>是否在gcminentservice()内传递上下文?