I've configured Push notifications in Android for an app following all the instructions in:
https://github.com/ParsePlatform/Parse-Server/wiki/Push-Configuring-Clients
https://parseplatform.github.io/docs/android/guide/#push-notifications
But no matter what I do, the mobile phone I'm using can't seem to get any push notifications at all.
The same app is configured to receive the notifications on iOS and works perfectly.
These are the relevant bits in the Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxy.xxy">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<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" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission
android:name="com.xxy.xxy.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.xxy.xxy.permission.C2D_MESSAGE" />
<application
android:name="com.xxy.xxy.MiXXYApplication"
android:allowBackup="true"
android:icon="#drawable/logoapp"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<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.xxy.xxy" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.push.gcm_sender_id"
android:value="id:123456789012" />
</application>
This is the Application class (with the AppID and Client Key replaced with the current value given by Back4App):
public class MiXXYApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("back4App_AppID")
.clientKey("back4App_ClientKey")
.server("https://parseapi.back4app.com/")
.build()
);
}
}
These are the methods I call to register the installation (I can't do it on the Application class because I need the userId, after login)
public void enablePush(final String userId) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("GCMSenderId", "123456789012");
installation.put("userId", userId);
installation.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.i("push", "ok");
subscribe("");
subscribe(userId);
} else {
Log.i("push", "nok");
e.printStackTrace();
}
}
});
}
public void subscribe(String channel){
ParsePush.subscribeInBackground(channel, new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.i("Push", "subscribed");
} else {
Log.i("push", "nok");
e.printStackTrace();
}
}
});
}
This is the installation registry on the Parse DB:
ObjectID: l1tkO3YM2r
GCMSenderID: 123456789012
deviceToken: APA91bHeKnj...
localeIdentifier: en-US
badge: (undefined)
parseVersion: 1.13.1
ACL: Public Read + Write
appIdentifier: com.xxy.xxy
appName: appName
deviceType: android
channels: ["","CyTPw5xc4r"]
pushType: gcm
installationId: 8cf9c606-5a0e...
userId: CyTPw5xc4r
In the google developer console, the project number is 123456789012, I've created an API key and added the API key + the project number in the Back4App dashboard's Android Push Notification Settings.
The logcat in verbose mode is showing the following:
09-21 09:29:19.863 10721-10721/com.xxy.xxy V/com.parse.ManifestInfo: Using gcm for push.
09-21 09:29:19.884 10721-10885/com.xxy.xxy V/com.parse.CachedCurrentInstallationController: Successfully deserialized Installation object
09-21 09:29:19.899 10721-10886/com.xxy.xxy V/com.parse.GcmRegistrar: Sending GCM registration intent
09-21 09:29:29.782 10721-11340/com.xxy.xxy V/com.parse.GcmRegistrar: Received deviceToken <APA91bHeKnj...> from GCM.
For what I can tell, everything's good to go, but I'm not getting any notification in my phone.
Is there anything wrong with my setup?
Thanks!
Solved it!
The thing is that, instead of getting the Api key the way all the guides say, you should get it from https://developers.google.com/mobile/add.
It generated another API key and activated the service, and then, it worked.
Related
I want to send push Notification using Parse API and GCM. I have done successfully configuration on server and test via sending push notification form Parse terminal and receive at android device.
But when i'm sending push programmatically then got an Exception: "unauthorized: master key is required".
I using following code:
ParseQuery query = ParseInstallation.getQuery();
query.whereEqualTo("channels", "testing");
// Notification for Android users
query.whereEqualTo("deviceType", "android");
ParsePush androidPush = new ParsePush();
androidPush.setMessage("Your suitcase has been filled with tiny robots!");
androidPush.setQuery(query);
androidPush.sendInBackground(new SendCallback() {
#Override
public void done(ParseException e) {
if ( e == null ) {
Log.d("GARG","Parse Notification Done. : ");
} else {
Log.d("GARG","Notification failed.: "+e.getMessage());
e.printStackTrace();
}
}
});
android manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demo">
<permission
android:name="com.demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.demo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<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="com.demo.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.demo.permission.C2D_MESSAGE" />
<application
android:name=".AppInitializer"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true">
<service android:name="com.parse.PushService" />
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_cast_light" />
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:211671060483" />
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="#string/parse_app_id" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="#string/parse_client_key" />
<meta-data
android:name="com.parse.X-Parse-Master-Key"
android:value="#string/parse_master_key" />
<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.demo" />
</intent-filter>
</receiver>
</application>
Initialize Parse SDK in android
public class AppInitializer extends Application {
public static JSONObject errorDataProvider;
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId(Utility.ApplicationId)
.clientKey(Utility.ClientKey)
.server(Utility.Server_URL)
.build()
);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground(Utility.PARSE_CHANNEL, new SaveCallback() {
#Override
public void done(ParseException e) {
Log.e("GARG", "Successfully subscribed to Parse!");
}
});
}
}
UPDATED ANSWER
Hi, i investigate it a bit and found that currently the only to send Push is by using the masterKey and that's exactly the reason why you are getting this error
In order to send push with master key the best approach will be to create a cloud code function and trigger this function from the client side.
so you need to do the following:
Inside your cloud code main.js file create a new function
Parse.Cloud.afterSave("SendPush", function(request) {
var query = new Parse.Query(Parse.Installation);
query.exists("deviceToken");
// here you can add other conditions e.g. to send a push to sepcific users or channel etc.
var payload = {
alert: "YOUR_MESSAGE"
// you can add other stuff here...
};
Parse.Push.send({
data: payload,
where: query
}, {
useMasterKey: true
})
.then(function() {
response.success("Push Sent!");
}, function(error) {
response.error("Error while trying to send push " + error.message);
});
});
After you created the cloud code function restart your server
Trigger this cloud code function from your android app in the following way:
HashMap<String,String> map = new HashMap<String, String>();
map.put("PARAM1KEY","PARAM1VALUE");
// here you can send parameters to your cloud code functions
// such parameters can be the channel name, array of users to send a push to and more...
ParseCloud.callFunctionInBackground("SendPush",map, new FunctionCallback<Object>() {
#Override
public void done(Object object, ParseException e) {
// handle callback
}
});
This will trigger a call to the cloud code function that you created above and inside the cloud code the useMasterKey is true so it should work.
update: spelling
useMasterKey: true
that will enable parse server to use master key to push notification from client side.
I've implemented GCM push notifications in my app according to the documentation, and it works randomly. Usually though, it spews out this error:
W/GMPM: Service connection failed: ConnectionResult{statusCode=SERVICE_MISSING_PERMISSION, resolution=PendingIntent{dee6afb: android.os.BinderProxy#c3e3718}, message=null}
After this error, it usually starts working after a while.
I haven't found any information about this, but I'd assume something is wrong with my manifest... But it's pretty much exactly the same as on the google-GCM sample.
<manifest package="fi.pauli.myapp"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<permission
android:name="fi.pauli.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="fi.pauli.myapp.permission.C2D_MESSAGE"/>
<application
...
<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"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="fi.pauli.myapp"/>
</intent-filter>
</receiver>
<service
android:name="fi.pauli.myapp.PushNotificationReceiverService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<service
android:name="fi.pauli.myapp.InstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="fi.pauli.myapp.RegistrationIntentService"
android:exported="false">
</service>
</application>
</manifest>
Help, anyone? :)
Update: My RegistrationIntentService looks like this, and it does get a token each time:
public class RegistrationIntentService extends IntentService
{
public RegistrationIntentService()
{
super("RegistrationIntentService");
}
public RegistrationIntentService(String name)
{
super(name);
}
#Override
protected void onHandleIntent(Intent intent)
{
try
{
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE);
if(MainActivity.userData != null ? MainActivity.userData.getId() != 0 : false)
{
if(!token.equals(MainActivity.userData.getPush_notification_id()))
{
MainActivity.userData.setPush_notification_id(token);
MainActivity.userData.setDeviceOS(2);
DataClient.writeFile("userData.json", new Gson().toJson(MainActivity.userData), getApplicationContext());
MainActivity.updatePushIdToServer(token);
}
}
}
catch (Exception e)
{
Log.e("RegistrationService", e.getMessage());
}
}
}
I have this permission more in my manifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
I recently upgraded my parse-*.jar files to version 1.10.0
After cleaning up my project at android studio and syncing with gradle, suddenly my app freezes at start... blackscreen, without any button working (I need to force-close the app)
I searched the net and this site for solutions, but couldn't find anything.
Any help will be much appreciated!
My Application class:
public class Application extends android.app.Application {
#Override
public void onCreate() {
super.onCreate();
Log.d("app", "reached1");
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Log.d("app", "reached2");
ParseObject.registerSubclass(FoodListItem.class);
Log.d("app", "reached3");
Parse.initialize(this, "STRING1", "STRING2");
Log.d("app", "reached4");
ParseInstallation.getCurrentInstallation().saveInBackground();
Log.d("app", "reached5");
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("app", "successfully subscribed to the broadcast channel.");
} else {
Log.e("app", "failed to subscribe for push", e);
}
}
});
}
logcat:
08-17 21:46:58.554 17633-17633/il.ac.huji.freefood D/dalvikvm﹕ Late-enabling CheckJNI
08-17 21:46:58.594 17633-17633/il.ac.huji.freefood W/ActivityThread﹕ Application il.ac.huji.freefood can be debugged on port 8100...
08-17 21:46:58.604 17633-17633/il.ac.huji.freefood D/app﹕ reached1
08-17 21:46:58.604 17633-17633/il.ac.huji.freefood D/app﹕ reached2
08-17 21:46:58.614 17633-17633/il.ac.huji.freefood D/app﹕ reached3
Thanks in advance!
EDIT:
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="il.ac.huji.freefood" >
<uses-sdk android:minSdkVersion="11" />
<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.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<permission
android:name="il.ac.huji.freefood.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="il.ac.huji.freefood.permission.C2D_MESSAGE" />
<application
android:name="il.ac.huji.freefood.Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity android:name=".activities_one_class.MainActivity" />
<activity android:name=".activities_one_class.NoFoodFoundActivity" />
<activity android:name=".activity_choose_food.ChooseFoodActivity" />
<activity android:name=".activity_add_food.AddFoodActivity" />
<activity android:name=".GPS_tracker_Activity" />
<activity android:name=".activities_one_class.SignUpActivity" />
<activity android:name=".activities_one_class.LoginActivity">
<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.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="il.ac.huji.freefood" />
</intent-filter>
</receiver>
<receiver
android:name="il.ac.huji.freefood.PushNotificationsReceiver"
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.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/pooh_icon" />
<!--TODO once it was android:resource="#drawable/ic_launcher" />-->
</application>
</manifest>
Shouldn't you initialize the parse sdk before anything else
public class Application extends android.app.Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "STRING1", "STRING2");
Parse.enableLocalDatastore(this);
ParseObject.registerSubclass(FoodListItem.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("app", "successfully subscribed to the broadcast channel.");
} else {
Log.e("app", "failed to subscribe for push", e);
}
}
});
}
To anyone who might be concerned, Apparently there was no Internet connection for the phone (because it automatically went into USB tethering and something went wrong over there) so that when parse got initialized it tried to connect to the server AT THE MAIN THREAD without success, causing the freeze effect.
The solution was to check for the phone's connectivity BEFORE starting parse, so my final solution was -
public class Application extends android.app.Application {
#Override
public void onCreate() {
super.onCreate();
Log.d("app", "reached1");
if (!connectedToInternet()) {
Log.e("app", "not connected to internet. exiting");
exitAppWithDialog(this);
}
....
}
I chose one of the methods to check connectivity which exist here -
How to check internet access on Android? InetAddress never times out
Have a good day!
I am developing simple android app and very new to parse. I followed parse documentation in adding back-end functionalities. Parse CORE was an easy part but I can’t send push notifications from android device. But push-notifications are received when sent from parse dashboard.
My Manifest file is as below:
<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" />
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />
<!--
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="loaniistar.loaniistar.permission.C2D_MESSAGE" />
<uses-permission android:name="loaniistar.loaniistar.permission.C2D_MESSAGE" />
<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="loaniistar.loaniistar" />
</intent-filter>
</receiver>
Application Class:
public class MApplication extends Application {
String applicationiId = "5npdddECsGdDk49OttttuHq6iZdZpddI0cHDsz";
String clientKey = "SjF1BWamssstycthSjf2dddduhcuwW2VccccCCuFlE";
public UserAccounts userAccount = null;
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
ParseCrashReporting.enable(this);
Parse.initialize(this, applicationiId, clientKey);
PushService.startServiceIfRequired(this);
}
}
Subscribing for channel in an activity class:
ParsePush.subscribeInBackground("manager", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
}
else
{
btnLoginEnable();
}
}
});
Sending Push Notification in another activity class:
// Sending Push
ParsePush push = new ParsePush();
push.setChannel("manager");
push.setMessage(m.getMessage().substring(0, (int) m.getMessage().length() / 3));
//push.sendInBackground();
push.sendInBackground(new SendCallback() {
#Override
public void done(ParseException e) {
if(e == null)
{
Toast.makeText(getActivity(), "Notification sent", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getActivity(), "Notification Not sent", Toast.LENGTH_SHORT).show();
}
}
});
Row is added in “Installation” class and GCMSenderId is empty!! Is this the issue?
Please help me out why I can’t receive notifications when sent from my android device?
Libs used:
Bolts-android-1.1.4.jar
Parse-1.8.2.jar
ParseCrashReporting-1.8.2.jar
If you have just created the App in Parse and integrated in your App, It generally not works immediately Same thing happened to me. I was not getting the data, but after some time I got the requests when I saw the Parse Dashboard
It will take Approx 20 mins. You can try to see the Parse Analytics.(if you have implemented it) if Parse shows Requests in your Analytics Dashboard then It will work completely fine
I'm trying to register my android app with GCM, I followed the instructions in this link in order to obtain an api key, I did what is written in numbers 1-7 but in step 8 I can't find
the Android Key section.
What should I do?
p.s.
When I try to register my device with gcm gcm.register(SENDER_ID) I get error saying service not available, are those to problems connected? or this error is something else? (I didn't write the server part of the application)
android manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appspot.smartgan"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.appspot.smartgan.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.appspot.smartgan.permission.C2D_MESSAGE" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light" >
<activity
android:name="com.appspot.smartgan.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=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.appspot.smartgan" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.appspot.smartgan.LoginActivity"
android:label="#string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<activity
android:name="com.appspot.smartgan.ChildActivity"
android:label="#string/title_activity_child" >
</activity>
</application>
</manifest>
registration code: (I used the code from an example Google published)
private void registerInBackground() {
new AsyncTask<Void, Void, String>() {
String str = "";
#Override
protected String doInBackground(Void... params) {
String message = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
message = "Device registered, registration ID=" + regid;
Log.d("SMARTGAN_PLAY", "register completed");
// send registration id to the server
sendRegistrationIdToServer();
// Persist the regID - no need to register again.
storeRegistrationId(context, regid);
} catch (IOException e) {
message = "Error:" + e.getMessage();
}
str = message;
return message;
}
#Override
protected void onPostExecute(String message) {
childrenTextView.setText(str);
}
}.execute(null, null, null);
}
You don't need an API Key in order to register to GCM. You only need a Sender ID (which is the Project ID of the Google API Project you created for your app). The API Key is only needed in the server side for sending GCM messages to your app.
The reason for getting service not available can be many things. You'll have to post your manifest and client registration code to get more help.
//Subtitute with your own project ID
String SENDER_ID = "46086692976";
See screenshot: