AIR Native Extension unable to start service intent Android GCM - android

Hey everyone I have been toying around with a native extension lately for Android and I need to add Google Cloud Messaging. I was able to get the Google Cloud Messaging app to work on its own. But now that I have integrated it into a native extension for Flash I have found an issue I can't resolve.
08-21 17:58:01.661: W/ActivityManager(180): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTRATION cat=[air.GCMAppTest.debug] flg=0x10 cmp=air.GCMAppTest.debug/com.xxxxxxxxx.extensions.GCM.GCMIntentService (has extras) }: not found
This error comes up when the GCM Broadcast Receiver receives the
08-21 17:58:01.661: V/GCMBroadcastReceiver(7604): GCM IntentService class: com.gamecloudstudios.popsportsandroidane.extensions.GCM.GCMIntentService
The error is caused by the Flash Package Context being the default package.
When I need the default package to be the package containing the GCMIntentService.
Has anyone been able to get the GCMIntentService to run in an Android Flash Native Extension? or any AndroidIntentService for that matter.

You need to make sure you add the Intent Service to the manifest additions of your AIR application descriptor, not the Android manifest of your native code library. For example, the following code is what we use in our example application of our GCM native extension available here if you're interested.
There are a few things to note in there, especially the "air." prefix on some of the android names. But as long as you have all these additions, the actual implementation of the Android code should be fairly similar to the Google examples.
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<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" />
<!-- Only this application can receive the messages and registration result -->
<permission android:name="air.com.distriqt.test.debug.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="air.com.distriqt.test.debug.permission.C2D_MESSAGE" />
<application>
<receiver android:enabled="true" android:exported="true" android:name="com.distriqt.extension.pushnotifications.PushNotificationsBroadcastReceiver" 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="air.com.distriqt.test.debug" />
</intent-filter>
</receiver>
<service android:enabled="true" android:exported="true" android:name="com.distriqt.extension.pushnotifications.gcm.GCMIntentService" />
</application>
</manifest>
]]></manifestAdditions>
</android>

Related

Android push notifications, not granting permission

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 to edit the Android.manifest.template.xml file to receive Push Notifications

Let me restructure this question. My objective is try and get some assistance with setting up Push Notifications on a cross-platform Delphi App (iOS & Android). I initially followed a blog post by Sarina Du Pont via Embarcadero here.
I gather that you have to adjust your Android.manifest.template.xml file with the additional permission entries, as explained quite well via this blog post. However, having done this exactly, my Android app still does not receive any Push Notifications. I have included my Android manifest template file here:
<?xml version="1.0" encoding="utf-8"?>
package="%package%"
android:versionCode="%versionCode%"
android:versionName="%versionName%">
<!-- This is the platform API where NativeActivity was introduced. -->
<uses-sdk android:minSdkVersion="%minSdkVersion%" />
<!-- 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" />
<!--
Creates a custom permission so only this app can receive its messages.
NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
where PACKAGE is the application's package name.
-->
<permission android:name="%package%.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="%package%.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:persistent="%persistent%"
android:restoreAnyVersion="%restoreAnyVersion%"
android:label="%label%"
android:installLocation="%installLocation%"
android:debuggable="%debuggable%"
android:largeHeap="%largeHeap%"
android:icon="%icon%"
android:theme="#style/MyTheme.NoTitleBar.SplashWindow">
<!-- Our activity is a subclass of the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="com.embarcadero.firemonkey.FMXNativeActivity"
android:label="%activityLabel%"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="%libNameValue%" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<receiver
android:name="com.embarcadero.gcm.notifications.GCMNotification" 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%" />
</intent-filter>
</receiver>
<service android:name="com.embarcadero.gcm.notifications.GCMIntentService" />
</activity>
<receiver android:name="com.embarcadero.firemonkey.notifications.FMXNotificationAlarm" />
</application>
Have I done something wrong?
Read the tutorial again more carefully, it gives you the download link:
On platforms that do not include OpenSSL libraries, such as iOS, you will need to download OpenSSL libraries.
If you follow that link, you will see an OpenSSLStaticLibs.7z file, which contains the 2 .a files you are looking for.

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 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