Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

show activity after notification Android

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

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

The problem trace is:

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

Here is my 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"));
        }
    }

    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>

Where is the mistake???

Thanks to everyone!!

Edit:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Implement this :

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

  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...