I am trying to implement a library for Android devices which will take care of push notification in your application.
I have a server which take care of storing AppToken and DeviceToken (I can can generate tokens and send it to my server). The problem is when I try to test it (sending a request to GCM https://gcm-http.googleapis.com/gcm/send the app with my library doesn't seem to receive it)
Request :
Content-Type: application/json
Authorization: key=AIza...N04 (correct value generated for library)
{
"data": {
"message": "test",
"title": "testTitle"
},
"to" : "ewud...UySu" (token send by device)
}
I was following GCM tutorial https://developers.google.com/cloud-messaging/android/client so I generate google-services.json (for library package) and set up everything like they say (keep in mind library) but I am struggling with the manifest (which I think is the problem).
This is the manifest:
...
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="cz.united121.notifit.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="cz.united121.notifit.permission.C2D_MESSAGE" />
...
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="cz.united121.notifit" />
</intent-filter>
</receiver>
<service
android:name="cz.united121.notifit.GCM.GcmListenerService"
android:exported="true" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="cz.united121.notifit" />
</intent-filter>
</service>
<service
android:name="cz.united121.notifit.GCM.InstanceIDListenerService"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
<category android:name="cz.united121.notifit" />
</intent-filter>
</service>
<service
android:name="cz.united121.notifit.GCM.RegistrationIntentService"
android:exported="true">
</service>
I have this code in app manifest, but it was even in lib manifest with no effect.
I rather upload whole project on github for better understanding https://github.com/petrLorenc/PushNotificationProject
Thank you in advance
Related
I recently set up local parse server on my machine following the github instructions on PARSE SERVER EXAMPLE repo. My server is up and running i have included the Parse.Initialise function in Main Activity.java file (See Screenshot)[MainActivity.java][1]
Question 1: The app_id env variable in parse. Initialise corresponds to app id set in index.js file of parse server example
question2: If my configuration is correct then why is the app not storing the data object on the server.?How to check if App has established contact with the server.Android Builds shows no errors. Also the Parse dashboard shows no change in data i.e. data is not being stored on parse server by app.My ultimate goal is to send Push Notification to the server. I have configured my app to GCM, got and configured app and server with correct GCM Project no. (Sender Id) and API key. Please tell what I am doing wrong? Or what needs to be done for get the server and app properly configured.
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hal_kumar.testapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".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" />
<category android:name="com.example.hal_kumar.testapp" />
</intent-filter>
</receiver>
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:5XXXXXXXXXX6" />;<!--GCM PROJECT NO -->
</application>
<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="com.google.android.c2dm.permission.RECEIVE" />
<!--
GET_ACCOUNTS is only required for GCM on devices running Android lower than
4.0.4. You may leave out this permission if you are targetting 4.0.4+.
-->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!--
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.hal_kumar.testapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.hal_kumar.testapp.permission.C2D_MESSAGE" />
</manifest>
index.js (Parse server)
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: 'XXXX',
masterKey: process.env.MASTER_KEY || 'XXXXX', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
push:{
android: {
senderId: '58XXXXXXXXXX26',
apiKey: 'AIXXXXXXO4'
}
}
});
[1]: http://i.stack.imgur.com/NnRwn.png
The possible reason for your problem can only be of internet permission.Try to build the project by placing permission code before the begin of code for application in manifest.
Moreover,I would recommend you to use firebase instead of parse since parse is going to dead soon in 2017.
I'm trying to enable notifications on my android app (built in react-native) using this package
Here is a part of my MANIFEST.XML file :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="{package_name}"
android:versionCode="1"
android:versionName="1.0.0"
android:minSdkVersion="21"
android:targetSdkVersion="23">
<permission
android:name="com.xxx.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.xxx.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_TASKS" />
...
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.xxx" />
</intent-filter>
</receiver>
<service android:name="com.oney.gcm.GcmRegistrationService"/>
<service android:name="com.oney.gcm.BackgroundService"></service>
<service
android:name="com.oney.gcm.RNGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<receiver
android:exported="false"
android:name="com.oney.gcm.GcmBroadcastReceiver">
<intent-filter>
<action android:name="com.oney.gcm.GCMReceiveNotification" />
</intent-filter>
</receiver>
<receiver android:name="io.neson.react.notification.NotificationEventReceiver" />
<receiver android:name="io.neson.react.notification.NotificationPublisher" />
<receiver android:name="io.neson.react.notification.SystemBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
Unfortunately, I have this in my logs when I install my app :
W/PackageManager( 873): Not granting permission com.google.android.c2dm.permission.SEND to package (protectionLevel=18 flags=0x8be46)
Any thoughts on the issue ?
Thanks.
There is a C2DM setup issue at your project level.Either go through official doc or follow this tutorial step by step.
Step to be made while changing your Manifest.xml
Permission to receive C2DM messages
Access to the internet
Restrict access to your C2DM messages so no other app can see them
Declare a Receiver, that we’ll create later, that will let us receive the C2DM events
Make sure that the minSdkVersion is set so that only 2.2 and higher can access your app
I think because you are using deprecated api
Important: C2DM was officially deprecated on June 26, 2012, and will
be shut down completely as of October 20, 2015. Existing C2DM
developers are encouraged to migrate to Google Cloud Messaging (GCM).
See the C2DM-to-GCM Migration document for more information.
Developers must use GCM for new development.
https://developers.google.com/android/c2dm/?csw=1#manifest
How should i register my android app (or) device to parse push site to get the notification.
now i was connected to GCM.
am not able to step ahead and register my device with parse...
Here's the best way to implement official Parse SDK for standard push notification based on my experiences and several trial and errors and also many SO and Parse threads reading. So I'll walk you through these steps:
Add the following dependencies to the app build.gradle file, and you can get the latest versions from Parse github blank projects or Parse SDK from docs category in the website. the latest versions until now is here:
compile 'com.parse.bolts:bolts-tasks:1.3.0'
compile 'com.parse:parse-android:1.11.0'
Add the following codes similar to the quick guide in the Application class's onCreate() method of the project, change the keys accordingly
--> Take attention that these two lines must be added after super.onCreate(); :
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(this, "YOUR APPLICATION ID", "YOUR CLIENT KEY");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
Add the following line after setContentView in your MainActivity class:
ParseAnalytics.trackAppOpenedInBackground(getIntent());
add the Parse service and receivers to AndroidManifest.xml immediately before the closing </application> tag and make the mentioned package names identical to the yours:
<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.parse.starter" />
</intent-filter>
</receiver>
add permissions like the quick guide instructions typically immediately before the opening <application> tag, and make the mentioned package names identical to the yours, too:
<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.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
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.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
LAST STEP) Well Done! Enjoy pushing your stuff. ;)
Add the following code to your manifest
<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" />
<permission
android:name="${your_application_package}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${your_application_package}.permission.C2D_MESSAGE" />
<application
android:name="${your_application_package}.ParseApplication"
android:allowBackup="true"
android:icon="#drawable/contact_image"
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>
<!-- Parse library -->
<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.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="${your_application_package}" />
</intent-filter>
</receiver>
Your ParseApplication should be like this
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
//TODO: replace application_id and ClientKey with your parse credentials
Parse.initialize(this, "application_id", "ClientKey");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Add the bolts-android-1.2.0 and Parse-1.9.2 libraries to your project. Now run the application and check in the parse dashborad you will find your device registered.
just i had downloaded a sample push application from parse site...and in that downloaded solution will have 2 projects ...1 for ios and 1 for android...ios wont push directly...so we need to make our android project as startup project and need to run our application...so that your phone will detect by your parse site and goto push tab in dashboard and select send push ...there in the textbox write what info you want to push and click on send now...so that push information will appear on your miobile
I am developing an AIR application and I implemented push notifications for Android using GCM. The service works perfectly on all devices except those having Android 5.0 or 5.1 OS. The application simply doesn't receive a registration id from GCM.
Neither PERMISSION_GIVEN_WITH_TOKEN_EVENT nor PERMISSION_REFUSED_EVENT are never raised. I am not getting any response from GCM.
Did anybody have this problem? Could you please help me?
I am using Air Native Extension for Push Notifications from Freshplanet github.com/freshplanet/ANE-Push-Notification
So this is my code:
PushNotification.getInstance().registerForPushNotification(GOOGLE_PROJECT_ID); PushNotification.getInstance().addEventListener(PushNotificationEvent.PERMISSION_REFUSED_EVENT, onPushNotificationTokenFailed);
function onPushNotificationToken(event:PushNotificationEvent):void {
trace("My push token is: " + event.token);
}
function onPushNotificationTokenFailed(event:PushNotificationEvent):void
{
trace(event.errorCode);
trace(event.errorMessage);
trace();
}
And my manifest file (partial):
<permission android:name="MY_APP_ID.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="MY_APP_ID.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application>
<activity android:name="com.freshplanet.nativeExtensions.NotificationActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<receiver android:name="com.freshplanet.nativeExtensions.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="MY_APP_ID" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="MY_APP_ID" />
</intent-filter>
</receiver>
<service android:name="com.freshplanet.nativeExtensions.LocalNotificationService"/>
<receiver android:name="com.freshplanet.nativeExtensions.LocalBroadcastReceiver" android:process=":remote">
</receiver>
Thanks in advance!
I have an application where I'm implementing Google Cloud Messaging notifications, but in a specific device the messages don't arrive. This device has the minimum requirements to use GCM (Android version 2.2, Play Store installed and an Google Account logged). In the log I see that the device is receiving the registration id and sending to the back-office where I have a list of devices registered.
My question is: Do I need to make extra configurations to make the device receive these notifications?
Here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.testegcm"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<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="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application
android:name="TesteGCM"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name="br.com.testegcm.GcmBroadcastReceiver"
android:exported="true"
android:enabled="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="br.com.testegcm" />
</intent-filter>
</receiver>
<service android:name="br.com.testegcm.GcmIntentService" />
<activity
android:name="br.com.testegcm.Home"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#style/notitle" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Change this :
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
to :
<permission android:name="br.com.testegcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="br.com.testegcm.permission.C2D_MESSAGE" />
Add the same issue and i eventually i realized that i need to change in the manifest, the broadcast receiver package name from com.example.gcm to my package name :
<!-- Push notifcations-->
<receiver
android:name=".BroadcastRecivers.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.example.gcm"/>
</intent-filter>
</receiver>
To
<!-- Push notifcations-->
<receiver
android:name=".BroadcastRecivers.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="MY PACKAGE NAME"/>
</intent-filter>
</receiver>
No apart from Android version 2.2, Play Store app installed and an Google Account logged in no other configuration is needed, Now there are only two cases left
1) Either there is some ambiguity in your code.
2) or may be it is a device specific issue.
I had the very same problem.My code would work on nexus4(Kitkat) but would fail to get me a notification from the appln server(via gcm server).For versions less that 4.0.4 you should make sure that you have your google account setup on your device for gcm to work. I had google account on my phone but the mistake I made was that my Account and Sync settings in my galaxy ace was 'Off'.When I turned it ON and ran my code, i received the notification.
Please check the following solution. if still didn't work, let me know.
Add RECEIVE and REGISTRATION Intent in two different intent filters
<receiver
android:name=“<.GCM BroadcastReceiver Name>“ // Name of your BroadcastReceiver, define in code.
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name=“<Package Name>" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name=“<Package Name>" />
</intent-filter>
</receiver>
<service android:name=“<.GCM IntentService Name>" /> // Name of your IntentService, define in code.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Add RECEIVE and REGISTRATION Intent in two different intent filters as shown as above otherwise it won’t work for some devices(Ex. HTC).