本文介绍了通知 Android 后显示活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在收到推送通知后尝试打开一个活动.

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

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

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

这是我的代码

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());
}

我已经把我的活动放在清单中

and i´ve putted my Activity in the Manifest

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

错在哪里???

谢谢大家!!

已修复android:exported="true" 添加到我在 Manifest 中的活动

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 后显示活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:00