Android GCM instanceID.getToken() throws TIMEOUT exception on Gingerbread - android

As the title indicates I get a TIMEOUT exception when trying to get token using Google Cloud Messaging on API 10 emulator. I have added my google account on the device, checked that "Sync" is ON, also added the
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/> in the manifest in the receiver and still cannot find out what is causing this:
11-25 17:35:00.896 29750-29774/com.example.alexis.myapplication W/InstanceID/Rpc: No response android.os.ConditionVariable#b667bc18
11-25 17:35:00.896 29750-29774/com.example.alexis.myapplication E/MYAPP: TIMEOUT
Here is the manifest declaration for permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:name="com.example.alexis.myapplication.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.alexis.myapplication.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
And receiver:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
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.alexis.myapplication" />
</intent-filter>
</receiver>
Any help would be highly appreciated.
Note: I am using genymotion emulator with 2.3.7, I don't have a hardware device to test.

Used a hardware device and everything worked so it was emulator's fault.

Related

GCM messages are not received with android app at all

I have an old problem: I cannot receive GCM messages with android app. According to the server log they are succesfully delivered to the GCM server and are sent further, but my client side app doesn't seem to have received them.
This is the GCM-relevant fragment of my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_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" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<permission
android:name="my.package.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="my.package.permission.C2D_MESSAGE" />
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.GCM_RECEIVED_ACTION" />
<category android:name="my.package" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
This is my service-class GcmIntentService:
public class GcmIntentService extends GcmListenerService {
private String TAG = "myReceiver";
#Override
public void onMessageReceived(String from, Bundle data) {
Log.d(TAG, "message received");//this log is never shown
if (!data.isEmpty()) {
Log.d(TAG, "interesting message receiver");
}
}
}
This is my project build.gradle dependency:
classpath 'com.google.gms:google-services:1.3.0-beta1'
I think I forgot to add something, that's why it doesn't work at all. I tried with WLAN and SIM-card internet. so the promblem is not in internet firewall. Sender API and GCM-token seem to be correct (they were copied and pasted from the corresponding settings of the developer account).
Thank you for your help in advance.
Edit: see the answer below
Do following changes in manifest
Replace following code
<service android:name=".GcmIntentService" />
with
<service
android:name="packagename.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
and in
<uses-permission android:name="your.package.name.permission.C2D_MESSAGE" />
write whatever youer packagename is in place of
"your.package.name"
A few things are wrong / might be wrong. You need the sender id in the gcm registration code of the main activity.And you have 3 times the C2D_MESSAGE permission, which is the first time wrong (put.your.package.name). The second time it is correct for the production stage but will not work for development, and the third time you have the permission correct for development.
You should only have it once.
And indeed like #Android india suggests change your service declaration in the manifest.
Please see this
your receiver declaration has some bug
<receiver
android:name="yourpackage.receiver.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="yourpackage" />
</intent-filter>
</receiver>
Android Manifest fragment that works:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<permission
android:name="my.package.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="my.package.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="my.package" />
</intent-filter>
</receiver>
<service
android:name="my.package.GcmListener"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>

Registering but not receiving push notifications on Android

I'm running an sample application on AIR using EasyPush extension from milkman games, and using urban airship as 3rd party server.
In IOS everything works fine, but in Android I'm not receiving the push notification. I can register the token, it appears on project menu in my urban airship account, but when i send a test message, i'm not receiving it on device.
I've checked many times my android manifest xml, but everything seems to be ok.
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<permission android:name="air.com.cafundo.testpush.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="air.com.cafundo.testpush.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-sdk android:minSdkVersion="8"/>
<uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>
<application>
<activity android:name="air.com.cafundo.testpush.PushPreferencesActivity" />
<activity android:name="air.com.cafundo.testpush.LocationActivity" />
<receiver android:name="com.urbanairship.CoreReceiver" />
<receiver android:name="com.urbanairship.push.GCMPushReceiver" 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="com.cafundo.testpush" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService" android:label="Push Notification Service"/>
<service android:name="com.urbanairship.analytics.EventService" android:label="Event Service"/>
<provider android:name="com.urbanairship.UrbanAirshipProvider"
android:authorities="air.com.cafundo.testpush.urbanairship.provider"
android:exported="false"
android:multiprocess="true" />
<receiver android:name="air.com.cafundo.testpush.IntentReceiver" />
<receiver android:name="com.milkmangames.extensions.android.push.MmgPushReceiver" />
</application>
</manifest>
]]></manifestAdditions>
Hope somebody can help me.
Thanks.
I'm not sure if you're still having this issue, but I made the mistake of creating a Key for Android applications when I should've been creating a Key for server applications within the Google developers console.
As soon as I used the generated server API key within UrbanAirship's "Configure Notification Services / Google Cloud Messaging (GCM)" section I started to receive the push messages.
Hope that helps.

Not getting android push notification messages from gcm

I am developing an android application with push notification using GCM (step by step: http://developer.android.com/google/gcm/index.html) but not all devices getting notifications from GCM server.
I debugged it and I saw that my 3d-party server sends the message successfully.
When i send to my Galaxy-S4 device I get the notification but in my Galaxy-S2 i don't get.
AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<receiver
android:name=".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.freco" />
</intent-filter>
</receiver>
<service android:name=".gcm.GcmIntentService" />
I think the other code its not necessary here because its works fine in Galaxy-S4.
What do you think is it ?
What's the package of your app, com.freco (as defined in the category of the broadcast receiver) or com.example.gcm (as defined in your permissions)?
You should use the package name of your app in both places. For some reason, this mismatch only causes problems in older Android versions. Newer versions work either way.
Looks like a copy paste error. In your manifest, change com.example to your actual package name

GCM Push RECEIVE category Name on Android OS < 4.1

I have push enabled for my application and my manifest is as seen below:
Package Name:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.norton.mobile"
android:versionCode="1"
android:versionName="1.0" >
My receiver is as below:
<receiver
android:name="com.pravaa.mobile.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.stanley.mobile" />
</intent-filter>
</receiver>
With the above configuration i am able to receive notifcation succesfully on any device with OS > 4.1, but not on devices with OS < 4.1. On modifying the receiver category configuration to **<category android:name="com.norton.mobile" />** i was able to sucessfully receive notifications even on devices with OS < 4.1. I do understand that the docs say "A receiver for com.google.android.c2dm.intent.RECEIVE, with the category set as applicationPackage." But how does it work for devices with OS > 4.1 although the category does not match the applicationPackage.
Does someone know the reasoning behind this? Thanks in advance.
Maybe you wrote a wrong category name, and it worked cause a category name is not required above OS 4.1.
"
Notice that android:name in the category tag must be replaced by your application's package name (and the category tag is not required for applications targeted to minSdkVersion 16 and higher).
http://developer.android.com/google/gcm/helper.html#android-app
"
Confirm your configuration with
<!-- GCM PERMISSIONS START -->
<permission
android:name="com.norton.mobile.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.norton.mobile.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission
android:name="com.norton.mobile.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.norton.mobile.permission.C2D_MESSAGE" />
<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" />
<!-- GCM PERMISSIONS END -->
<!-- GCM RECEIVER And SERVICE START -->
<receiver
android:name="com.google.android.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" />
<action android:name="com.google.android.c2dm.intent.GCM_RECEIVED_ACTION" />
<category android:name="com.norton.mobile" />
</intent-filter>
</receiver>
<service
android:name="com.norton.mobile.GCMIntentService"
android:enabled="true" />
<!-- GCM RECEIVER And SERVICE END -->

GCM Activity getting force closed

I am a beginner with Google cloud messaging. I was developing a demo app to check the functionality of GCm. I have created a GCM project and i am checking whether the device is registered or not. I am using the following code,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "483910217912");
Log.d(tag, "Registered");
} else {
Log.v(tag, "Already registered");
}
}
and my Manifest file is,
<uses-sdk android:minSdkVersion="8" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 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" />
<permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="my_app_package.permission.C2D_MESSAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name="com.google.android.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="my_app_package" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
<activity
android:name=".GCmExampleActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I have included the gsm jar files into my project.
The Logcat error it gives is,
10-11 13:44:59.001: E/AndroidRuntime(339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kochar.it.GCM/com.kochar.it.GCM.GCmExampleActivity}: java.lang.UnsupportedOperationException: Device does not have package com.google.android.gsf
The error is on the line,
GCMRegistrar.checkDevice(this);
It seems that you're using the wrong emulator. The default emulator uses a regular Android emulator that doesn't have any Google packages and can't run all sorts of things like maps, c2dm and all sorts of stuff like that. What you want to do, is create a new emulator that can support the Google APIs.
Don't run this in an emulator. Because it needs Google account.
Try one of below,
Create Emulator with Google api
Run it on real android phones
Run it on Bluestack (http://bluestacks.com/)
It will solve your problem. :)

Categories

Resources