C2D_MESSAGE permission error? - android

This seems to be a fairly common question without a good answer. I've just followed the google guide for GCM push messaging and am getting this error:
E/AndroidRuntime(21779): java.lang.RuntimeException: Unable to start activity ComponentInfo{eric.bander.app/eric.bander.app.MenuScreen}: java.lang.IllegalStateException: Application does not define permission eric.bander.app.permission.C2D_MESSAGE
E/AndroidRuntime(21779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
E/AndroidRuntime(21779): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
E/AndroidRuntime(21779): at android.app.ActivityThread.access$600(ActivityThread.java:127)
E/AndroidRuntime(21779): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
E/AndroidRuntime(21779): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21779): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(21779): at android.app.ActivityThread.main(ActivityThread.java:4507)
E/AndroidRuntime(21779): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21779): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(21779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
E/AndroidRuntime(21779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
E/AndroidRuntime(21779): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(21779): Caused by: java.lang.IllegalStateException: Application does not define permission eric.bander.app.permission.C2D_MESSAGE
E/AndroidRuntime(21779): at com.google.android.gcm.GCMRegistrar.checkManifest(GCMRegistrar.java:137)
E/AndroidRuntime(21779): at eric.bander.app.MenuScreen.onCreate(MenuScreen.java:43)
E/AndroidRuntime(21779): at android.app.Activity.performCreate(Activity.java:4469)
E/AndroidRuntime(21779): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime(21779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
Here is my manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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="eric.bander.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="eric.bander.app.permission.C2D_MESSAGE" />
<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="eric.bander.app" />
</intent-filter>
</receiver>
This is the piece of code in MainMenu:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "808426403545");
} else {
Toast.makeText(this, GCMRegistrar.getRegistrationId(this), Toast.LENGTH_LONG).show();
}
And I don't know if its relevant but my app strucutre is like this with the GCM intent service in another package:
eric.bander
-MainMenu.class
eric.bander.misc
-GCMIntentService.class
I hope someone can help with this, always frustrating when you are following a tutorial.
TIA

My error was having GCMIntentService in a different package to the class that registered the GCM.

Related

NullPointerException while trying to create a new intent in WakefulBroadcastReceiver after reboot

I have written a subclass of WakefulBroadcastReceiver that receives the "android.intent.action.BOOT_COMPLETED" action when user device is rebooted.It is working fine in my Nexus device but not on some other devices like Samsung, Verizon etc. For those devices, I am getting a NullPointerException in onReceive() at this line Intent service = new Intent(context, MyAlarmOnBootService.class); as
java.lang.RuntimeException: Unable to start receiver com.android.myapp.receiver.MyWakefulAlarmOnBootReceiver: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2244)
at android.app.ActivityThread.access$1500(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4854)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.os.Bundle.putAll(Bundle.java:303)
at android.content.Intent.putExtras(Intent.java:5762)
at com.android.myapp.receiver.MyWakefulAlarmOnBootReceiver.onReceive(MyWakefulAlarmOnBootReceiver.java:30)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2237)
... 10 more
This is my receiver class:
public class MyWakefulAlarmOnBootReceiver extends
WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("MyApp", "receiver started after reboot");
Intent service = new Intent(context, MyAlarmOnBootService.class);//this is the line where I am getting NPE.
service.putExtras(intent.getExtras());
startWakefulService(context, service);
}
}
My Manifest file (only the parts related are shown in this file):
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<receiver android:name=".receiver.MyWakefulAlarmOnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".service.MyAlarmOnBootService"
android:enabled="true" />
...
Is this related to Smart Manager app of Samsung that kills apps and alarms? If yes, how is my receiver fired? Is there some problem in the context parameter in onReceive()? Please help me. It is working fine on my Nexus 5.
Intent service = new Intent(context, MyAlarmOnBootService.class);//this is the line where I am getting NPE.
actually this is not the line. the exception raised from next line
service.putExtras(intent.getExtras());
you created new intent which has no extras, and you pass it as a parameter to putExtra() this is where you are wrong.

Error Recieving Broadcast intent. Eclipse Paho

I am trying to use eclipse paho library for the android app designed for my IoT project. Android app is simply sending gyroscope and accelerometer data to the broker at iot.eclipse.org.
I use the following code to establish a connection with the MQTT Server.
`public void establishMQTTConnection(){
clientId = MqttClient.generateClientId();
Log.d(TAG,clientId+"");
client =
new MqttAndroidClient(this.getApplicationContext(), "iot.eclipse.org:1883",
clientId);
// MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("aiupvrxz");
//options.setPassword("dOW0vFQzRGKA".toCharArray());
try {
token = client.connect();
token.setActionCallback(new IMqttActionListener() {
#Override
public void onSuccess(IMqttToken asyncActionToken) {
// We are connected
Log.d(TAG, "onSuccess");
}
#Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
// Something went wrong e.g. connection timeout or firewall problems
Log.d(TAG, "onFailure");
}
});
} catch (MqttException e) {
e.printStackTrace();
}
}`
Problem is app never establishes the connection.
I get the following error in the logcat.
05-24 12:48:20.772 10236-10236/iot.dulanga.com.androidclientv2 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x10000010 (has extras) } in org.eclipse.paho.android.service.MqttService$NetworkConnectionIntentReceiver#41fc9348
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4573)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
android.permission.WAKE_LOCK
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Neither user 10121 nor current process has android.permission.WAKE_LOCK.
at android.os.Parcel.readException(Parcel.java:1327)
at android.os.Parcel.readException(Parcel.java:1281)
at android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:432)
at android.os.PowerManager$WakeLock.acquireLocked(PowerManager.java:295)
at android.os.PowerManager$WakeLock.acquire(PowerManager.java:264)
at org.eclipse.paho.android.service.MqttService$NetworkConnectionIntentReceiver.onReceive(MqttService.java:794)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
at android.os.Handler.handleCallback(Handler.java:605) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4573) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 
at dalvik.system.NativeStart.main(Native Method)
AndroidManifest....
`
<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"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>
</application>
`
Can anyone please help me to figure out the problem with my code. Thank you a lot!!!!
The exception has the key section in the middle:
Caused by: java.lang.SecurityException: Neither user 10121 nor current process has android.permission.WAKE_LOCK.
Make sure you have added the required section to the application manifest
<uses-permission android:name="android.permission.WAKE_LOCK" />
In my case i forgot add below 2 lines to Manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Of course you need add these permisions too:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
and in application scope add this line :
<service android:name="org.eclipse.paho.android.service.MqttService" />

Google Cloud Messaging Unknown source exception

Hello I want to implement Google's GCM into my android application.
I linked to google play services lib
I wrote the following permissions :
<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.torasecurity.mobile.alarm.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.torasecurity.mobile.alarm.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.torasecurity.mobile.alarm.C2D_MESSAGE" />
A simple broadcast receiver:
<receiver android:name=".MyReceiver" 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="YOUR_PACKAGE_NAME" />
</intent-filter>
</receiver>
But I get this stack trace when trying to register:
08-07 11:43:12.806: W/System.err(19067): java.io.IOException: MAIN_THREAD
08-07 11:43:12.826: W/System.err(19067): at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
08-07 11:43:12.826: W/System.err(19067): at com.torasecurity.mobile.alarm.SplashScreen.register(SplashScreen.java:27)
08-07 11:43:12.826: W/System.err(19067): at com.torasecurity.mobile.alarm.SplashScreen.onCreate(SplashScreen.java:56)
08-07 11:43:12.826: W/System.err(19067): at android.app.Activity.performCreate(Activity.java:5206)
08-07 11:43:12.826: W/System.err(19067): at
Does any body know what I am doing wrong ?
Most probably you are trying to register to GCM directly from the activity.
But the register() method accesses the network, and like any other method that performs network operations, it should run in a separate thread otherwise an exception is thrown.
The solution is to put the registration to GCM in a thread, for example in a AsyncTask, like in docs. (registerBackground() method).

PhoneGap APK runs fine but crashes on each run after Google Play deployment

I have built an application for a large multicultural festival in my city that kicks off on Saturday. I've tweaked a lot of bugs in the iPhone version and we are waiting for Apple to approve it. I have taken that perfected version as the basis for the Android version.
The Android version looks and works great. I can run it on my Samsung Galaxy S II by either "Run as Android Application" in Eclipse or by uploading it to a server and downloading it into the phone. I can also email the app to myself and it works, too. I submitted it to the Google Play store and once it got into the wild (this is advertised on billboards, buses, everywhere) it crashes the minute it is opened.
I'm not really sure how to troubleshoot this when it works fine on the device before publication. I read about how it has to do with the MainActivity activity name, but everything looks like it lines up.
Error 1 [ClassNotFoundException in PathClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader
dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
at java.lang.ClassLoader.loadClass(ClassLoader.java:548)
at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
Error 2 [ClassNotFoundException in BaseDexClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
Any help would be greatly appreciated! I am in quite the pickle.
Edit - Here is the AndroidManifest.xml from the bin folder
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:resizeable="false" android:anyDensity="true" />
<uses-permission android:name="android.permission.VIBRATE" />
<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_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.encode.EncodeActivity" android:label="#string/share_name">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
It turned out my main Java file was named "MainActivity.java" but it was being called as "Folklorama.java" throughout the project files. I renamed the file to Folklorama.java.

UrbanAirship android broadcastreceiver

com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime java.lang.RuntimeException: Unable to start service com.urbanairship.push.PushService#40cfdc08 with Intent { act=com.urbanairship.push.START cmp=com.myapp.myapp/com.urbanairship.push.PushService }: java.lang.IllegalStateException: UAirship.takeOff() must be called every time Application.onCreate() is invoked.
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2499)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.app.ActivityThread.access$1900(ActivityThread.java:132)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1220)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:99)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.os.Looper.loop(Looper.java:137)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:4575)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at java.lang.reflect.Method.invokeNative(Native Method)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at java.lang.reflect.Method.invoke(Method.java:511)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at dalvik.system.NativeStart.main(Native Method)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime Caused by: java.lang.IllegalStateException: UAirship.takeOff() must be called every time Application.onCreate() is invoked.
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at com.urbanairship.push.PushService.onStart(Unknown Source)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.app.Service.onStartCommand(Service.java:438)
23:03:56.422 21926 com.myapp.myapp:com.urbanairship.process ERROR AndroidRuntime at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2482)
I'm trying to integrate UrbanAirship into my app, the above exception is thrown after I call takeOff, if I modify the line:
<service android:name="com.urbanairship.push.PushService" android:process=":com.urbanairship.process"/>
.. to become without the android:process part it works but when the push message arrives my PushBroadcastReceiver is not called (The breakpoint isn't hit)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="3.61 beta 1"
android:versionCode="71"
android:installLocation="auto" package="com.myapp.myapp">
<uses-sdk android:minSdkVersion="3"
android:targetSdkVersion="4"/>
<uses-feature android:name="android.hardware.camera"/>
<application
android:label="#string/app_name">
<activity android:name=".client.android.SplashScreen"
android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.myapp.myapp.client.android.CaptureActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".client.android.PreferencesActivity"
android:label="#string/preferences_name"
android:screenOrientation="portrait">
</activity>
<activity android:name=".client.android.PushBroadcastReceiver">
</activity>
<activity android:name=".client.android.AboutActivity"
android:label="#string/menu_about">
<intent-filter>
<action android:name="com.myapp.myapp.client.android.AboutActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="com.urbanairship.CoreReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
<receiver android:name="com.urbanairship.push.c2dm.C2DMPushReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.myapp.myapp" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.myapp.myapp" />
</intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService" android:process=":com.urbanairship.process"/>
<receiver android:name="com.myapp.myapp.client.android.PushBroadcastReceiver" />
</application>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="com.myapp.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.myapp.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
</manifest>
Where are you calling takeOff from? Looks like you are not using AutoPilot or providing a custom application that calls takeoff in the onCreate method.
First create a CustomApplication class that calls takeOff:
public class CustomApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Optionally, customize your config at runtime:
//
// AirshipConfigOptions options = new AirshipConfigOptions();
// options.inProduction = false;
// options.developmentAppKey = "Your Development App Key";
// options.developmentAppSecret "Your Development App Secret";
//
// UAirship.takeOff(this, options);
UAirship.takeOff(this, new UAirship.OnReadyCallback() {
#Override
public void onAirshipReady(UAirship airship) {
// Perform any airship configurations here
}
});
}
}
Then set the application in the manifest:
<application name="CustomApplication"
I would also remove the use of processes from your manifest. They are almost never a good idea to use anymore. They will complicate the application logic and waste more resources.
For more info about Urban Airship - http://docs.urbanairship.com/platform/android.html.

Categories

Resources