arash moeen
arash moeen

Reputation: 4693

Android gcm notification doesn't open application

I'm using the below code as my receiver and I want to open the application with let's say the specific activity but it doesn't work and nothing happens on notification click:

PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0) 

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification n = builder.setContentIntent(pIntent)
    .setSmallIcon(R.drawable.ic_launcher)
    .setTicker(title)
    .setWhen(System.currentTimeMillis())
    .setAutoCancel(true)
    .setContentTitle(title)
    .setContentText(msg)
    .build();
n.defaults |= Notification.DEFAULT_VIBRATE;
n.defaults |= Notification.DEFAULT_SOUND;
mNotificationManager.notify(0, n);

and this is my intent initialized earlier:

Intent intent = new Intent(this, Activity_Notification.class);

here are my manifest's permissions:

<permission
    android:name="com.rahil.googlemapsv2.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.rahil.aidapp.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="com.rahil.aidapp.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.rahil.aidapp.permission.C2D_MESSAGE" />

and here's the receiver:

<receiver
        android:name="com.rahil.gcm.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.rahil.gcm" />
        </intent-filter>
    </receiver>
    <service android:name="com.rahil.gcm.GcmIntentService" />

Upvotes: 0

Views: 498

Answers (1)

Somasundaram Mahesh
Somasundaram Mahesh

Reputation: 915

Intent resultIntent = new Intent(this, ResultActivity.class);
... 
// Because clicking the notification opens a new ("special") activity, there's 
// no need to create an artificial back stack. 
PendingIntent resultPendingIntent =
    PendingIntent.getActivity(
    this,
    0, 
    resultIntent,
    PendingIntent.FLAG_UPDATE_CURRENT
); 

From Android docs

Upvotes: 1

Related Questions