parse custom receiver not getting called

Wednesday, July 2, 2014

I am trying to implement parse push notification in my android project. to understand, I am giving some project flow.



  • saving user details on personal server using php API

  • server send me some push notification.


I get notification but I am not getting any action, data in that push notification in my custom broadcast receiver.


Here is my Android Manifest.xml



<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />



<permission
android:name="com.mypackage.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

<uses-permission android:name="com.mypackage.myapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
android:name="com.mypackage.myappe.MyApplication"
android:allowBackup="true"
android:icon="@drawable/dwtlogo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<service android:name="com.parse.PushService" />
<receiver
android:name="com.mypackage.myapp.MyCustomReceiver"
android:exported="false" android:enabled="true">
<intent-filter>
<action android:name="com.mypackage.myapp.MESSAGE" />
</intent-filter>
</receiver>



<category android:name="com.mypackage.myapp" />



</application>


Here is MyApplication.java



@Override
public void onCreate() {
super.onCreate();

Parse.initialize(this, "xxxxxxxx", "xxxxxxxxxx");

ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);

PushService.setDefaultPushCallback(getApplicationContext(), DashBoardActivity.class);

ParseInstallation.getCurrentInstallation().saveInBackground();

ParseUser.enableAutomaticUser();
//String deviceToken= (String) installation.get("deviceToken");
//Toast.makeText(this, "Device token="+deviceToken, Toast.LENGTH_LONG).show();
PushService.subscribe(this, "Wake_up", DashBoardActivity.class);
}


And here is my custom receiver in which i am trying to get action and data which server sending me but my custom receiver not getting called.



String action = intent.getAction();
Log.d(TAG, "got action " + action );
if (action.equals("com.mypackage.myapp.MESSAGE"))
{
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
//if (key.equals("customdata"))
//{
Intent pupInt = new Intent(context, ShowPopup.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.getApplicationContext().startActivity(pupInt);
//}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
}
}

} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}


Even no any log getting printed. Here is php server code which sending me push notification.



$data = array(
'channel' => $chnl,
'action' => 'com.mypackage.myapp.MESSAGE',
'data' => array(
'alert' => $message,
'sound' => 'push.caf',
'photourl' => $imageurl,
)
);


But i don't understand where i need to get this data so i can show image after receiving push notification.


Please give me any hint or reference.







http://ift.tt/1lS4RPS