Stuck while sending user to user push notification in android using parse

I am trying to send user to user notification on click of a button to specific users but getting this issue while sending notification from last 4 days in android, and with this, whenever i uninstall the app from my phone which i am using as emulator, and reinstall it for debugging, it doesnt create new installation id and take the old one: i Guess this is the problem, please it will be great help if anybody help me in a elaborated way

enter image description here

My Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.parsecomlogin"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission
        android:name="com.example.parsecomlogin.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.parsecomlogin.permission.C2D_MESSAGE" />

    <permission
        android:name="com.example.parsecomlogin.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.parsecomlogin.permission.MAPS_RECEIVE" />

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="21" />

    <application
        android:name=".ParseApp"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



        <activity
            android:name=".Welcome"
            android:label="@string/title_activity_welcome" >
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_login" >
        </activity>
        <activity
            android:name=".LoginSignupActivity"
            android:label="@string/title_activity_login_signup" >
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDZ5TG28QJnN5zMyIdezPllvrfrwg7ElQs" />

        <service android:name="com.parse.PushService" />
        <receiver android:name="com.parse.ParseBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>


        <receiver android:name="com.parse.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" />


                <!--
                  IMPORTANT: Change "com.example.parsecomlogin" to match your app's package name.
                -->
                <category android:name="com.example.parsecomlogin" />
            </intent-filter>
        </receiver>


        <receiver
            android:name="com.example.parsecomlogin.ParseCustomBroadcastReceiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>


    </application>

</manifest>

MyCustomReceiverClass

public class ParseCustomBroadcastReceiver extends BroadcastReceiver {
   private static final String TAG = "ParseCustomBroadcastReceiver";
   public static final String intentAction = "SEND_PUSH";


   @Override
   public void onReceive(Context context, Intent intent) {
       if (intent == null) {
           Log.d(TAG, "Receiver intent null");
       } else {
          // Parse push message and handle accordingly
          processPush(context, intent);
       }
   }

   private void processPush(Context context, Intent intent) {
       String action = intent.getAction();
       Log.d(TAG, "got action " + action );
       if (action.equals(intentAction))
       {
           String channel = intent.getExtras().getString("com.parse.Channel");
           try {        
               JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
               Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
               // Iterate the parse keys if needed
               Iterator<String> itr = json.keys();
               while (itr.hasNext()) {
                   String key = (String) itr.next();
               // Extract custom push data
               if (key.equals("customdata")) {    
                // Handle push notification by invoking activity directly
                launchSomeActivity(context, json.getString(key));
                // OR trigger a broadcast to activity
                triggerBroadcastToActivity(context);
                // OR create a local notification
                createNotification(context);
                }
                    Log.d(TAG, "..." + key + " => " + json.getString(key));
               }
            } catch (JSONException ex) {
            Log.d(TAG, "JSON failed!");
            }
       }
   }

   public static final int NOTIFICATION_ID = 45;
   // Create a local dashboard notification to tell user about the event
   private void createNotification(Context context) {
       NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(
               R.drawable.ic_launcher).setContentTitle("Successfully logged in");
       NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
       mNotificationManager.notify(45, mBuilder.build());
   }

   // Handle push notification by invoking activity directly
   private void launchSomeActivity(Context context, String datavalue) {
       Intent pupInt = new Intent(context, Welcome.class);
       pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
       pupInt.putExtra("customdata", datavalue);
       context.getApplicationContext().startActivity(pupInt);   
   }

   // Handle push notification by sending a local broadcast 
   // to which the activity subscribes to
   private void triggerBroadcastToActivity(Context context) {
       LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(intentAction));
   }
}


Source: eclipse

Leave a Reply