I create simple "ParseStarterProject" as default of parse.com project. It works. I send notification from one device to other device successfully via setchannel method.
But the problem is I do not use receiver class(I do not know how can I use that) so when a notification comes I need to get its message ? it is possible? or if I use set data can I get its data ?
I use this code to send message:
ParsePush push = new ParsePush();
String yourMessage = "Selam from LG G2";//I want to get this message from other device?
push.setChannel("device2");
push.setMessage(yourMessage);
//push.setData("exampledata"); if I use this can I get this data from other device?
push.sendInBackground();
my manifest file:
<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.parse.starter" to match your app's package name.
-->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
thanks in advance
Create a class that extends BroadcastReceiver, here we call it MyCustomReceiver. Declare the usage of this receiver in your manifest:
<receiver android:name="com.example.MyCustomReceiver" android:exported="false">
<intent-filter>
<action android:name="com.example.UPDATE_STATUS" />
</intent-filter>
</receiver>
I'm not sure what you mean by you have problems with "MyCustomReceiver class on the main activity", in your comment to #kingspeech's answer.
In the worst case, you can create your own Receiver which extends the ParseBroadcastReceiver (and reference the extended class in the manifest). Then it should work by default, but you'll be able to hook into onReceive(Context, Intent)
As Parse tutorial directs, you ca use JSONObject to set data and you can put whatever you want.
Then when you receive Push notification you can have a access to read the previously prepared JSONObject. Please look at the Android tutorial https://parse.com/docs/push_guide#options/Android.
Hope this helps,
Regards.
Related
I'm trying to send a push notification to my app using Parse back{4}app by following this tutorial. But when I get to step 3, they say to edit android push notification settings in the dashboard, but I cannot find this option in my dashboard.
Another thing I didn't understand is the last part of step 1, changing the red code with my own. What am I supposed to change this to?
<category android:name="**dominwong4.scm.back4apppushnotificationcloudcode**" />
It's from from this code:
<!--
IMPORTANT: Change "YOUR_SENDER_ID" to your GCM Sender Id.
DON't DELETE the "id:"-->
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:966437188652" />
<service android:name="com.parse.PushService" />
<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="**dominwong4.scm.back4apppushnotificationcloudcode**" />
</intent-filter>
</receiver>
<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.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
You change it to the package name of your application. There's a link at the top of that page to a github project.
If you look in there, you'd see code with
package dominwong4.scm.back4apppushnotificationcloudcode;
The instructions assume you've used a package name that identifies your own app when you created a project
Can't help with the dashboard... Haven't used Back4App
Regarding the push notification settings, after the changes to Back4App's site, it's located by following these steps:
After Login in your Back4App Account, click on "Features" below your AppName. Then you'll search for "Android Push notification" and click on "Server".
That should bring up the Push Notification settings for Android.
Checking the Online Chat is a great idea too, seems very useful.
migrating from Parse I got stuck by not being able to override PushBots notification creation code like I used to do with getNotification function in ParsePushBroadcastReceiver. My project needs multiline and separate push notifications, but PushBots default behavior is to show single line and group notifications by application.
I tried canceling notification in the onReceive function of BroadcastReceiver (PBConstants.EVENT_MSG_RECEIVE event), so I could create & display my own push, but I don't know notification ID and CancelAll() didn't work (also would be a bad idea).
Pushbots.sharedInstance() does have a setNotificationBuilder function, which accepts PBGenerate object, but I have no idea how to construct it properly and if this actually would help my case.
Couldn't find any documentation & get a response from support yet, so asking here if maybe someone knows a solution or a way to workaround this issue.
Here's how receivers are defined in AndroidManifest.xml
<receiver
android:name="com.pushbots.google.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.my.app" />
</intent-filter>
</receiver>
<receiver android:name="com.my.app.MyPushReceiver" />
<service android:name="com.pushbots.push.GCMIntentService" />
Thank you in advance!
This is my code to send a push notification using parse.com in android.
ParseQuery installQuery = ParseInstallation.getQuery();
installQuery.whereEqualTo("userId", recieverObjectID);
ParsePush androidPush = new ParsePush();
androidPush.setMessage(currentUser.getUsername());
androidPush.setQuery(installQuery);
androidPush.sendInBackground();
In emulator I am able to send and receive push notifications, but I am not able to receive push notification on device. I manage to retrieve that in Installation table of parse when push-type is gcm for those devices or emulators push notifications are not sent. Guide me with solution.
if you are having a Parse account please go through the docs provided over there that will help you alot. you will have to make a class of parse application
public class ParseApplication extends Application{
public void onCreate() {
super.onCreate();
Parse.initialize(this,"app_id","Client_id");
ParseUser.enableAutomaticUser();
}
}
then in your launcher activity you have to intialise parse like this:
ParseInstallation currentInstall=ParseInstallation.getCurrentInstallation();
Have you made Parse Installation table as given in the docs.? you will have to register your device on Parse.
firstly do this:
ParsePush androidPush = new ParsePush();
androidPush.setMessage(currentUser.getUsername());
androidPush.setQuery(installQuery);
androidPush.saveInBackground();
check your manifest then u are Missing with some permissions can be Internet Permission or given below:
then in the application tag:
<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="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<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>
OK. So then in Your parse Account go and click on Push You will surely get a push.
In my android application I am using the push notifications supplied by Parse.com. I have successfully got this working, however my application has multiple push notifications and different activities should be loaded depending on which push notification has been pressed. I expected to be able to get the message for the push notification from the intent parameter of the onPushOpen, but it seems to be empty? . Does anyone know how I could get the message in the onPushOpen method?.
For some context, I have added my current custom PushReceiver code below.
public class PushReceiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, Splash.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Thanks.
Make sure you've upgraded to Parse-1.8.2.
Then you'll also need to do two more things.
Add information into your AndroidManifest.xml (within )
<service android:name="com.parse.PushService" />
<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...ADD_PACKAGE_INFO_HERE..." />
</intent-filter>
</receiver>
<receiver android:name="com..ADD_PACKAGE_INFO_HERE....PushReceiver"
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>
Add this to AndroidManifest.xml outside the tags
Within the cloud code on Parse.com, set the uri of the broadcast to "com....ADD_PACKAGE_INFO_HERE...PushReceiver"
NB: #1 & #2 should be provided for you in the debug trace when you run your android app.
Hope this helps. I spent hours trying to get this to work and the key for me was updating to 1.8.2.
EDIT:
You should also look at overriding onReceive as well as onPushOpen...that actually gets called on a notification. Good luck.
i want receive all start app intents (i think MAIN/LAUNCHER, see below) to log how often i used the application. So i do not want create an activity... I tried several receiver blocks, but for now nothing works:
with, without priority, only the action, both, only the category and so on..
<receiver android:name=".Receiver" android:enabled="true"
android:process=".e">
<intent-filter priority="100000" android:priority="100000">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
Have anyone an idea?
Thanks
I want receive all start app intents
You cannot do that, sorry.