Why my custom receiver is not working? - android

I use parse.com api.
What my problem is :
When other client send push notification I did not receive anything on my broadcastreceiver.
My manifest
<service android:name="com.parse.PushService" />
<receiver
android:name=".MainActivity$MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.yy.xx.UPDATE_STATUS" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
and my receiver in mainactivity is here:
public static class MyReceiver extends BroadcastReceiver {
public final String TAG = "MyReceiver";
#Override
public void onReceive(Context context, Intent intent) {
//this is not working,
try {
if (intent == null)
{
Log.d(TAG, "Receiver intent null");
}
else
{
String action = intent.getAction();
if (action.equals("com.yy.xx.UPDATE_STATUS"))
{
//....
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
and my push notification send code is here:
JSONObject obj;
try {
obj =new JSONObject();
obj.put("action","com.yy.xx.UPDATE_STATUS");
obj.put("customdata","message...");
push_p = new ParsePush();
#SuppressWarnings("rawtypes")
ParseQuery query = ParseInstallation.getQuery();
// Notification for Android users
//query.whereEqualTo("deviceType", "android");
push_p.setQuery(query);
push_p.setData(obj);
push_p.setChannel("channel_111");
push_p.sendInBackground();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I read parse.com api and tutorial but I do not understand what is the problem.
thanks in advance

Add all this declarations in manifest
<!-- PARSE SERVICE AND RECEIVERS -->
<service
android:name="com.parse.PushService"
android:enabled="true" />
<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:enabled="true"
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.example.app" />
</intent-filter>
</receiver>
<receiver android:name=".MainActivity$MyReceiver" >
<intent-filter>
<action android:name="com.example.update.UPDATE_STATUS" />
</intent-filter>
</receiver>
And add permissions
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
<permission
android:name="com.example.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

Related

Parse Push Notification for android not working

I have looked into many questions but i didn't get any push notifications.
I have added all the permissions and have simple receiver. When i debug it shows the device token to be null. In parse the device is detected and the notification is marked to be sent but not received in my device.
I am sharing the code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Parse.initialize(this, "", "");
}
catch (Exception e){
e.printStackTrace();
}
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Log.e("Tag 1", e == null ? "Succeed to register the app" : "Failed to register the app", e);
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
Log.d("Tag 2", "Device token: " + deviceToken);
}
});
Manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.arpan.push_notifivations">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:protectionLevel="signature"
android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.example.arpan.push_notifivations.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
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>
<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.parse.starter" to match your app's package name.
-->
<category android:name="com.example.arpan.push_notifivations" />
</intent-filter>
</receiver>
</application>
</manifest>
The dependencies i added are
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'

Push notification is not working using parse.com android?

I have created simple push notification app using parse.com.
devices registered successfully on parse.com but when i try to send push notification through parse.com no notification have come.
AndroidMainifest.xml Code:
<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.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
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>
<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" />
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />
Reciever Code:
public class Receiver extends ParsePushBroadcastReceiver {
private Intent parseIntent;
public Receiver() {
super();
}
#Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
if (intent == null)
return;
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
parseIntent = intent;
} catch (JSONException e) {
Log.d("PushJsonException", "" + e.getMessage());
}
}
}
MainActivity Code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// Call Methods to Update Your Stuff
}
};
#Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter("com.example.harrypotter.pushnotificationdemo"));
}
#Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
}
Application Class :
public class ParseApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
You have not changed the Category attribute in your Manifest file:
<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.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
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>
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
<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" />
<category android:name="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />
Parse.com Hosted Service is fully retiring on January 28, 2017. If you have an existing application, refer to this link and create your own push notification server. Parse release a database migration tool that lets you migrate data from your Parse app to any MongoDB database.
For More Information Check The LInk

Android Manifest code for Parse Push Receiver

I have followed the guidelines mentioned in parse.com and tried all helps from stackoverflow. But I am unable to receive any Parse Push Notification. The Dashboard shows Pushes Sent 0. Can anyone help me out on this. The code for
manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.phpand"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.phpand.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.phpand.permission.C2D_MESSAGE" />
<application
android:name=".MainApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light" >
<activity android:name=".ParseMainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
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>
<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" />
<category android:name="com.phpand" />
</intent-filter>
</receiver>
<receiver
android:name=".MyCustomReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<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>
where MainAppp initializes the Parse, ParseMainActivity's button click sends the push message and MyCustomReceiver is the BroadCastReceiver Class.
MyCustomReceiver class has:
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
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 {
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:");
Iterator<String> itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
if (key.equals("customdata")) {
launchSomeActivity(context, json.getString(key));
triggerBroadcastToActivity(context);
createNotification(context);
}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
} catch (JSONException ex) {
Log.d(TAG, "JSON failed!");
}
}
}
public static final int NOTIFICATION_ID = 45;
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());
}
private void launchSomeActivity(Context context, String datavalue) {
Intent pupInt = new Intent(context, ShowPopUp.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
pupInt.putExtra("customdata", datavalue);
context.getApplicationContext().startActivity(pupInt);
}
private void triggerBroadcastToActivity(Context context) {
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(intentAction));
}
}
Probably I must be missing something in the Manifest file, any help would save my week's due.

I got below error when impliment GCM

i have try to implement GCM in android studio got below error in my logcat.
LogCat:
onReceive: com.google.android.c2dm.intent.REGISTRATION GCM
IntentService class: com.project.GCMIntentService Acquiring wakelock
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project">
<permission
android:name="com.project.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.project.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.project.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.project.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:name="com.project.App"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/FullScreenThemes">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.project.core.account.ManageAccounts" />
<activity android:name=".projectActivity"/>
<activity android:name=".projectLogin"/>
<activity android:name="fieldatom.controls.SearchableItemActivity" />
<activity android:name="com.project.SettingsActivity" />
<activity
android:name="com.project.core.account.AppIntro"
android:screenOrientation="portrait" />
<activity
android:name=".base.addons.mail.widget.MailDetailDialog"
android:theme="#style/Theme.AppCompat.Light.Dialog" />
<activity
android:name=".base.addons.mail.widget.MailChatterCompose"
android:theme="#style/Theme.AppCompat.Light.Dialog" />
<activity
android:name=".core.account.FieldAtomAccountQuickManage"
android:theme="#style/Theme.AppCompat.Light.Dialog"
android:windowSoftInputMode="adjustPan" />
<activity android:name="com.project.core.account.About" />
<activity android:name="com.project.core.account.Profile" />
<!-- Reminder Receivers// -->
<receiver android:name="com.project.core.utils.reminder.ReminderReceiver" />
<receiver android:name="com.project.core.utils.reminder.ReminderActionReceiver" />
<!--<receiver android:name=".server.notifications.OdooServerNotificationReceiver">
<intent-filter>
<action android:name="com.project.odoo.mobile.SERVER_NOTIFICATION" />
</intent-filter>
</receiver>-->
<service android:name="com.project.core.auth.OdooAuthService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/authenticator" />
</service>
<provider
android:name="com.project.core.orm.provider.BaseModelProvider"
android:authorities="com.project.core.provider.content"
android:multiprocess="true" />
<provider
android:name="com.project.base.addons.ir.providers.IrModelProvider"
android:authorities="com.project.core.provider.content.sync.ir_model"
android:multiprocess="true" />
<!-- Sync Customer Provider & Service // -->
<provider
android:name="com.project.addons.customers.providers.CustomersSyncProvider"
android:authorities="com.project.core.provider.content.sync.res_partner"
android:label="#string/sync_label_customers"
android:multiprocess="true" />
<service
android:name="com.project.addons.customers.services.CustomerSyncService"
android:exported="true"
android:process=":sync_customer">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/customer_sync_adapter" />
</service>
<!-- Sync Request Provider & Service // -->
<provider
android:name="com.project.addons.requests.providers.RequestSyncProviders"
android:authorities="com.project.core.provider.content.sync.fa_service_request"
android:label="#string/sync_label_request"
android:multiprocess="true" />
<service
android:name="com.project.addons.requests.services.RequestSyncService"
android:exported="true"
android:process=":sync_request">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/request_sync_adapter" />
</service>
<!-- Sync Stage Provider & Service // -->
<provider
android:name="com.project.addons.stages.providers.StageSyncProviders"
android:authorities="com.project.core.provider.content.sync.fa_service_stage"
android:label="#string/sync_label_stages"
android:multiprocess="true" />
<service
android:name="com.project.addons.stages.services.StageSyncService"
android:exported="true"
android:process=":sync_stage">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/stage_sync_adapter" />
</service>
<!-- Sync Account Analytic Provider & Service // -->
<provider
android:name="com.project.addons.accountanalytics.providers.AccountAnalyticSyncProviders"
android:authorities="com.project.core.provider.content.sync.account_analytic_line"
android:label="#string/sync_label_accountAnalytic"
android:multiprocess="true" />
<service
android:name="com.project.addons.accountanalytics.services.AccountAnalyticSyncService"
android:exported="true"
android:process=":sync_account_analytic">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/account_analytic_sync_adapter" />
</service>
<!-- Sync Product Provider & Service // -->
<provider
android:name=".addons.products.providers.ProductsSyncProviders"
android:authorities="com.project.core.provider.content.sync.product_product"
android:label="#string/sync_label_product"
android:multiprocess="true" />
<service
android:name=".addons.products.service.ProductsSyncService"
android:exported="true"
android:process=":sync_account_analytic">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/product_sync_adapter" />
</service>
<!-- Sync QUOTATION Provider & Service // -->
<provider
android:name=".addons.quotes.providers.QuotationSyncProviders"
android:authorities="com.project.core.provider.content.sync.sale_order"
android:label="#string/sync_label_quotation"
android:multiprocess="true" />
<service
android:name=".addons.quotes.services.QuotationSyncService"
android:exported="true"
android:process=":sync_quotation">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/quote_sync_adapter" />
</service>
<!-- Sync QUOTATIONLine Provider & Service // -->
<provider
android:name=".addons.quotes.providers.QuotationLineSyncProviders"
android:authorities="com.project.core.provider.content.sync.sale_order_line"
android:label="#string/sync_label_quotation_line"
android:multiprocess="true" />
<service
android:name=".addons.quotes.services.QuotationLineSyncService"
android:exported="true"
android:process=":sync_quotation_line">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/quote_line_sync_adapter" />
</service>
<!-- Sync Attachment Provider & Service // -->
<provider
android:name=".addons.attachment.providers.IrAttachmentSyncProviders"
android:authorities="com.project.core.provider.content.sync.ir_attachment"
android:label="#string/sync_label_attachment"
android:multiprocess="true" />
<service
android:name=".addons.attachment.service.IrAttachmentSyncService"
android:exported="true"
android:process=":sync_attachment">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/attachment_sync_adapter" />
</service>
<!-- Sync MailMessage Provider & Service // -->
<provider
android:name=".base.addons.mail.providers.MailMessageSyncProviders"
android:authorities="com.project.core.provider.content.sync.mail_message"
android:label="#string/sync_label_mail_message"
android:multiprocess="true" />
<service
android:name=".base.addons.mail.service.MailMessageSyncService"
android:exported="true"
android:process=":sync_mail_message">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/mail_message_sync_adapter" />
</service>
<!-- Sync Maps Provider & Service // -->
<provider
android:name=".addons.maps.providers.MapsSyncProviders"
android:authorities="com.project.core.provider.content.sync.fa_map"
android:label="#string/sync_label_map_message"
android:multiprocess="true" />
<service
android:name=".addons.maps.service.MapsSyncService"
android:exported="true"
android:process=":sync_map">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/maps_sync_adapter" />
</service>
<service android:name=".addons.requests.services.TimeUpdateService"></service>
<activity
android:name="com.project.addons.customers.CustomerDetailActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden|adjustPan" />
<activity
android:name=".addons.requests.utils.RequestTabDetailAcitivty"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden|adjustPan"
/>
<activity
android:name=".addons.accountanalytics.VisitDetailActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:theme="#style/CustomActionBar"
android:windowSoftInputMode="stateHidden" />
<activity
android:name=".addons.accountanalytics.CreateVisitActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.AddPartActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.AddNoteActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.AddQuoteActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.utils.CaptureSignature"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.utils.ProductRequestListActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.quotes.QuoteDetailActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.products.ProductDetails"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<!-- Map Related Metadata -->
<uses-library
android:name="com.google.android.maps"
android:required="false" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCpjJtPYoeVN2dGqCVMCDEoR847OEwzgME" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- Push Notification -->
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.project" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService"></service>
</application>
<!--CB:A6:E7:26:97:08:37:4A:D6:60:1B:9B:2C:D0:9A:3B:9F:DF:02:D3;com.project-->
</manifest>
This is my project structure details below.
com.projcet
App.java
ProjcetLogin.java
GCMIntentService.java
This code working perfect in eclipse & android studio...finally i can do it.
MainActivity.java
public class MainActivity extends Activity implements View.OnClickListener{
//Notification Constant
Context context;
Button btn_GCMRegister, btn_Post;
GoogleCloudMessaging gcm;
public static String URL = "192.168.1.39:12069";
String regId;
public final String GOOGLE_PROJECT_ID = "your project id";
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
init();
}
private void init() {
btn_GCMRegister = (Button) findViewById(R.id.btn_gcm_register);
btn_GCMRegister.setOnClickListener(this);
btn_Post = (Button) findViewById(R.id.btn_post_on_server);
btn_Post.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_gcm_register:
registerGCM();
break;
case R.id.btn_post_on_server:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Map<String, Object> params = new HashMap<String, Object>();
params.put("regId", regId);
params.put("user_id", 1);
String server_url = URL;
try {
post(server_url, params);
}catch (IOException e){
e.printStackTrace();
}
break;
default:
break;
}
}
/*
* Issue a POST request to the server.
*/
private static void post(String endpoint, Map<String, Object> params)
throws IOException {
URL url;
try {
url = new URL(endpoint);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("invalid url: " + endpoint);
}
StringBuilder bodyBuilder = new StringBuilder();
Iterator<Map.Entry<String, Object>> iterator = params.entrySet().iterator();
// constructs the POST body using the parameters
while (iterator.hasNext()) {
Map.Entry<String, Object> param = iterator.next();
bodyBuilder.append(param.getKey()).append('=')
.append(param.getValue());
if (iterator.hasNext()) {
bodyBuilder.append('&');
}
}
String body = bodyBuilder.toString();
//Log.v(Config.TAG, "Posting '" + body + "' to " + url);
byte[] bytes = body.getBytes();
HttpURLConnection conn = null;
try {
Log.e("URL", "> " + url);
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setFixedLengthStreamingMode(bytes.length);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
// post the request
OutputStream out = conn.getOutputStream();
out.write(bytes);
out.close();
// handle the response
int status = conn.getResponseCode();
System.out.println("Json Data--->" + status);
// If response is not success
if (status != 200) {
throw new IOException("Post failed with error code " + status);
}
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
private void registerGCM() {
// TODO Auto-generated method stub
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regId = gcm.register(GOOGLE_PROJECT_ID);
Log.d("Reg Id----->", "" + regId);
Toast.makeText(MainActivity.this,"Register Key from server : " +regId,Toast.LENGTH_LONG).show();
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
Log.d("MainActivity", "Error: " + msg);
}
Log.d("MainActivity", "AsyncTask completed: " + msg);
return msg;
}
#Override
protected void onPostExecute(String msg) {
Toast.makeText(getApplicationContext(),
"Registered On GCM Server." + msg, Toast.LENGTH_LONG)
.show();
}
}.execute(null, null, null);
}
}
GCMIntentService.java
public class GCMIntentService extends GCMBaseIntentService {
#Override
protected void onError(Context arg0, String arg1) {
// TODO Auto-generated method stub
Log.e("onError", "gcm...error");
}
public GCMIntentService() {
super("your project id");
}
#Override
protected String[] getSenderIds(Context context) {
return super.getSenderIds(context);
}
#Override
protected void onMessage(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i(TAG, "Received message");
if (intent.getExtras() != null) {
String message = intent.getExtras().getString("message");
String title = intent.getExtras().getString("title");
String ticker = intent.getExtras().getString("ticker");
generateNotification(context,message,title,ticker);
}
}
#Override
protected void onRegistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
Log.e("onRegistered", "gcm Registered");
}
#Override
protected void onUnregistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
Log.e("onUnregistered", "gcm...Unregistered...");
}
/**
* Create a notification to inform the user that server has sent a message.
*/
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void generateNotification(Context context, String message,String title,String ticker) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context);
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
builder.setContentTitle(title)
.setContentText(message)
.setLargeIcon(
BitmapFactory.decodeResource(context.getResources(),
icon))
.setStyle(new Notification.BigTextStyle().bigText(message))
.setContentIntent(intent).setSmallIcon(icon).setTicker(ticker)
.setLights(0xff00ff00, 300, 100)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setAutoCancel(true).setWhen(when);
Notification notification = builder.build();
notificationManager.notify(0, notification);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxx.gcmnotification" >
<!-- GCM connects to Internet Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="com.example.xxx.gcmnotification.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.xxx.gcmnotification.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.xxx.gcmnotification" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
build.gradle(Module:app)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:+'
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:gravity="center"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:id="#+id/btn_gcm_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="Register On GCM Server" />
<Button
android:id="#+id/btn_post_on_server"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="Post On Server" />
</LinearLayout>

Android Studio: App does not receive push notifications from parse.com

I know that this question has been asked many times but i am still unable to get push notifications from parse.com
The push Notifications are being successfully sent from parse.com but my app does not receive them.
Most people have their problem resolved using this: I can't receive push notifications in app from Parse bt that doesnt work for me.
I also tried Android - Can not Receive Push from Parse.com.
Some people suggest changing names of packages, i did that and even made a new app but didnt help.
Note: i have imported parse-1.9.1.jar and bolts-android-1.2.0.jar
Here is my MainActivity
package com.example.user.parsetest;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.Parse;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this, "********", "********");
}
}
I tried adding custom PushReceiver as suggested in many answers
package com.example.user.parsetest;
import android.app.Activity;
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import com.parse.ParsePushBroadcastReceiver;
public class Receiver extends ParsePushBroadcastReceiver {
#Override
protected Notification getNotification(Context context, Intent intent) {
// TODO Auto-generated method stub
return super.getNotification(context, intent);
}
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
#Override
protected void onPushReceive(Context context, Intent intent) {
//here You can handle push before appearing into status e.g if you want to stop it.
super.onPushReceive(context, intent);
}
}
And the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<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.example.user.parsetest.Receiver"
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>
<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.parse.starter" to match your app's package name.
-->
<category android:name="com.example.user.parsetest" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<meta-data android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher"/>
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.example.user.parsetest.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.user.parsetest.permission.C2D_MESSAGE" />
</application>
Unable to figure out the problem. pleaseeee help.
In your Application class just after the line for Parse.initialize(appkey,clientkey); just add the following line and it should work.
// Current installation object
ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();
// Save the updated installation object
parseInstallation.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
MyLog.e(MainApplication.class.getSimpleName(), "Installation object saved "+((e!=null)?"failed":"successfully"));
}
});
Try downloading this project: https://www.dropbox.com/s/fpp22fi2o7c8vai/PushParse.zip?dl=0
It contains the 1.4.3 lib jar file. It's outdated but it's working.
I did, with a bit of tweaking, managed to update it to the latest library (1.9.2).
Watch out for errors that appear in your logcat. I got this: error setting up push notification using parse.com and android studio
If fixed by making sure my android manifest is very clean and organized. Follow the structure.
Here's my code for the updated parse library:
public class ParsePushNotification extends Application {
public ParsePushNotification() {
}
public void onCreate(){
super.onCreate();
Log.d("!!!", "This was called. Parse");
Parse.initialize(this, "paste your app id here", "paste your client id her");
// PushService.setDefaultPushCallback(this, LoginActivity.class);
// ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
}
That class should be used here in your manifest:
<application
android:name="com.example.app.ParsePushNotification"
Here's my receiver class:
public class Receiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, LoginActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Here's my manifest:
<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.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
<application
android:name="com.example.app.ParsePushNotification"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.NoTitle">
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher" />
<activity
android:name=".LoginActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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" />
<category android:name="com.example.app" />
</intent-filter>
</receiver>
<receiver android:name="com.example.app.Receiver"
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>
Good luck!

Categories

Resources