GCMBroadcastReceiver lacks WAKE_LOCK permission that is declared in manifest - android

I've implemented GCM as closely to Google's examples as I can, but the default GCMBroadcastReceiver is throwing a SecurityException for lack of the WAKE_LOCK permission. I require it in the my manifest, though, so AFAIK it should have that permission at run-time. Here's the relevant portion of my manifest:
<permission
android:name="PACKAGENAME.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="PACKAGENAME.permission.C2D_MESSAGE" />
<permission
android:name="android.permission.WAKE_LOCK"
android:protectionLevel="signatureOrSystem" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:name=".App"
android:icon="#drawable/app"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<service android:name=".GCMIntentService" />
<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="PACKAGENAME" />
</intent-filter>
</receiver>
The exception I see in the log file is:
07-09 13:32:58.238: E/AndroidRuntime(2723): java.lang.RuntimeException: Unable to start receiver com.google.android.gcm.GCMBroadcastReceiver: java.lang.SecurityException: Neither user 10072 nor current process has android.permission.WAKE_LOCK.
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2126)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Looper.loop(Looper.java:137)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-09 13:32:58.238: E/AndroidRuntime(2723): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:32:58.238: E/AndroidRuntime(2723): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-09 13:32:58.238: E/AndroidRuntime(2723): at dalvik.system.NativeStart.main(Native Method)
07-09 13:32:58.238: E/AndroidRuntime(2723): Caused by: java.lang.SecurityException: Neither user 10072 nor current process has android.permission.WAKE_LOCK.
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Parcel.readException(Parcel.java:1327)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Parcel.readException(Parcel.java:1281)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:279)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.PowerManager$WakeLock.acquireLocked(PowerManager.java:285)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.PowerManager$WakeLock.acquire(PowerManager.java:264)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.google.android.gcm.GCMBaseIntentService.runIntentInService(GCMBaseIntentService.java:235)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.google.android.gcm.GCMBroadcastReceiver.onReceive(GCMBroadcastReceiver.java:46)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2119)
07-09 13:32:58.238: E/AndroidRuntime(2723): ... 10 more

I wasn't calling GCMRegistrar.onDestroy() in the onDestroy() method of the activity in which I registered to receive messages. For some reason that caused it to complain about not having WAKE_LOCK, but only on the 4.0.4 device.

You should use:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
instead of:
<permission
android:name="android.permission.WAKE_LOCK"
android:protectionLevel="signatureOrSystem" />

Related

Android App Crashes at Execution

please i tried coding an android app using eclipse luna. I am writing a client gcm codes to push notifications. I have finished without any compiling errors, but wen i execute it on the mobile phone, the app crashes. Please below is the log i have been getting. Thanks for helping
05-23 23:07:27.303: D/AndroidRuntime(18211): Shutting down VM
05-23 23:07:27.303: W/dalvikvm(18211): threadid=1: thread exiting with uncaught exception (group=0x41f522a0)
05-23 23:07:27.303: E/AndroidRuntime(18211): FATAL EXCEPTION: main
05-23 23:07:27.303: E/AndroidRuntime(18211): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.prgguru.example/com.prgguru.example.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.prgguru.example/com.prgguru.example.HomeActivity}; have you declared this activity in your AndroidManifest.xml? 05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.ActivityThread.access$700(ActivityThread.java:140)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.os.Looper.loop(Looper.java:137)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.ActivityThread.main(ActivityThread.java:4921)
05-23 23:07:27.303: E/AndroidRuntime(18211): at java.lang.reflect.Method.invokeNative(Native Method)
05-23 23:07:27.303: E/AndroidRuntime(18211): at java.lang.reflect.Method.invoke(Method.java:511)
05-23 23:07:27.303: E/AndroidRuntime(18211): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
05-23 23:07:27.303: E/AndroidRuntime(18211): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
05-23 23:07:27.303: E/AndroidRuntime(18211): at dalvik.system.NativeStart.main(Native Method)
05-23 23:07:27.303: E/AndroidRuntime(18211): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activityclass {com.prgguru.example/com.prgguru.example.HomeActivity}; have you declared this activity in your AndroidManifest.xml?
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Activity.startActivityForResult(Activity.java:3428)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Activity.startActivityForResult(Activity.java:3389)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Activity.startActivity(Activity.java:3599)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Activity.startActivity(Activity.java:3567)
05-23 23:07:27.303: E/AndroidRuntime(18211): at com.prgguru.example.MainActivity.onCreate(MainActivity.java:61)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Activity.performCreate(Activity.java:5188)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-23 23:07:27.303: E/AndroidRuntime(18211): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
05-23 23:07:27.303: E/AndroidRuntime(18211): ... 11 more
05-23 23:07:27.343: D/dalvikvm(18211): GC_CONCURRENT freed 224K, 13% free 7212K/8199K, paused 12ms+2ms, total 35ms
below is also my manifest file. this is how i make the manifest file
`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prgguru.example"
android:versionCode="1"
android:versionName="1.0" >
<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<!-- GCM connects to Internet 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. -->
<permission
android:name="com.prgguru.example.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.prgguru.example.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Main activity. -->
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- Register Activity -->
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.google.android.gcm.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="com.prgguru.example" />
</intent-filter>
</receiver>
<service android:name=".GCMNotificationIntentService" />
</application>
</manifest>`
Whenever you make a new Activity and are going to display it you need to add a reference to it in your AndroidManifest.xml
For example you can simply do
<activity name="your.package.activityname" />
For more information see, Declaring class names in the documentation.

Android : illegaljavaexception Could not execute the method for activity

I'm trying using intent to add class to an application. I have made SecondAcitivity class and modified the manifest file as well. My application is running i.e. First activity Containing the button works well, but onclick on button the error comes and it does not displays a second activity.
This is my MainActivity.java file
package com.intent.usingintent;
import android.os.Bundle;
import android.content.Intent;
import android.app.Activity;
import android.view.View;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view){
startActivity(new Intent("com.intent.SecondActivity"));
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.intent.usingintent"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.intent.usingintent.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>
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
<intent-filter>
<action android:name=".SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</application>
</manifest>
ERROR LOG
07-09 13:57:45.922: W/dalvikvm(20185): threadid=1: thread exiting with uncaught exception (group=0x40d8e2a0)
07-09 13:57:45.932: E/AndroidRuntime(20185): FATAL EXCEPTION: main
07-09 13:57:45.932: E/AndroidRuntime(20185): java.lang.IllegalStateException: Could not execute method of the activity
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$1.onClick(View.java:3699)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View.performClick(View.java:4223)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$PerformClick.run(View.java:17275)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Handler.handleCallback(Handler.java:615)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Handler.dispatchMessage(Handler.java:92)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Looper.loop(Looper.java:137)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
07-09 13:57:45.932: E/AndroidRuntime(20185): at dalvik.system.NativeStart.main(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): Caused by: java.lang.reflect.InvocationTargetException
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$1.onClick(View.java:3694)
07-09 13:57:45.932: E/AndroidRuntime(20185): ... 11 more
07-09 13:57:45.932: E/AndroidRuntime(20185): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.intent.SecondActivity }
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivityForResult(Activity.java:3446)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivityForResult(Activity.java:3407)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivity(Activity.java:3617)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivity(Activity.java:3585)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.intent.usingintent.MainActivity.onClick(MainActivity.java:17)
07-09 13:57:45.932: E/AndroidRuntime(20185): ... 14 more
07-09 13:57:57.072: I/Process(20185): Sending signal. PID: 20185 SIG: 9
In your App, your second activity in com.intent.usingintent package.And your intent action is com.intent.SecondActivity,and write <intent-filter> inside <activity> tag.
So in manifest file,Change
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
<intent-filter>
<action android:name=".SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
to
<activity
android:name="com.intent.usingintent.SecondActivity"
android:label="SecondActivity" >
<intent-filter>
<action android:name="com.intent.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
You have misplaced IntentFilter for the SecondActivity in the manifest. Put it insude <activity></activity>
Though you do no treally need that you can simply do startActivity(new Intent(this, SecondActivity.class));
in your manifest file instead of this
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
replace with
<activity
android:name="com.intent.usingintent.SecondActivity"
android:label="SecondActivity" >
</activity>
and even in your java class also
startActivity(new Intent("com.intent.SecondActivity"));
replace this with
startActivity(new Intent("com.intent.usingintent.SecondActivity"));
change in manifest file
<activity
android:name="com.intent.usingintent.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>
<activity android:name="SecondActivity"></activity>
change in click event
Intent n=new Intent(MainActivity.this,SecondActivity.class);
startActivity(n);

my test application of worklight for android stopped unexpectedly when i tried to run that on AVD?

I have developed test application Using worklight for android environment. When i test that on worklight server it works fine, but when i tried to run the same on android virtual device (AVD) it throws an error message like Sorry The application Test (process com.Test) has stopped unexpectedly. Please try again. and the application terminates.
I am using Eclipse 4.2 and android version for AVD is 2.3.3
What is the solution of this...???
`
06-21 10:59:28.407: W/dalvikvm(1209): Unable to resolve superclass of Lcom/Test/Test; (14)
06-21 10:59:28.407: W/dalvikvm(1209): Link of class 'Lcom/Test/Test;' failed
06-21 10:59:28.427: D/AndroidRuntime(1209): Shutting down VM
06-21 10:59:28.427: W/dalvikvm(1209): threadid=1: thread exiting with uncaught exception (group=0xb607d4f0)
06-21 10:59:28.467: E/AndroidRuntime(1209): FATAL EXCEPTION: main
06-21 10:59:28.467: E/AndroidRuntime(1209): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.Test/com.Test.Test}: java.lang.ClassNotFoundException: com.Test.Test in loader dalvik.system.PathClassLoader[/data/app/com.Test-1.apk]
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.os.Looper.loop(Looper.java:130)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.reflect.Method.invoke(Method.java:507)
06-21 10:59:28.467: E/AndroidRuntime(1209): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-21 10:59:28.467: E/AndroidRuntime(1209): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-21 10:59:28.467: E/AndroidRuntime(1209): at dalvik.system.NativeStart.main(Native Method)
06-21 10:59:28.467: E/AndroidRuntime(1209): Caused by: java.lang.ClassNotFoundException: com.Test.Test in loader dalvik.system.PathClassLoader[/data/app/com.Test-1.apk]
06-21 10:59:28.467: E/AndroidRuntime(1209): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
06-21 10:59:28.467: E/AndroidRuntime(1209): ... 11 more
`
Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Test"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="false"
android:normalScreens="true"
android:largeScreens="false"
android:resizeable="false"
android:anyDensity="false"
/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- Push permissions -->
<permission android:name="com.Test.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.Test.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:label="#string/app_name"
android:debuggable="true"
android:icon="#drawable/icon" >
<activity android:name=".Test"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.Test.Test.NOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Preference Activity -->
<activity
android:name="com.worklight.common.WLPreferences"
android:label="Worklight Settings">
</activity>
<!-- Push service -->
<!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver
It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. -->
<service android:name=".GCMIntentService" />
<!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it -->
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.Test" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.Test" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="10" />
</manifest>
Test.Java
package com.Test;
import android.os.Bundle;
import com.worklight.androidgap.WLDroidGap;
public class Test extends WLDroidGap {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
/**
* onWLInitCompleted is called when the Worklight runtime framework initialization is complete
*/
#Override
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
}
}
AVD 2.3.x has a known bug which prevents it from running WebView based apps. Use OS 4.x or 2.2.

Try to start library project Activity

I have a library project and Main project and I try to start the activity that is defined in library project from main project.
Intent intent = new Intent("isr.LAUNCH");
intent.setComponent(new ComponentName("com.ISR", "com.ISR.activity.CameraActivity"));
startActivity(intent);
But I receive the following exception:
05-14 17:13:42.853: E/AndroidRuntime(29217): java.lang.SecurityException: Permission Denial: starting Intent { act=isr.LAUNCH cmp=com.ISR/.activity.CameraActivity } from ProcessRecord{40aa7178 29217:com.ssbs.sw.SWE/10094} (pid=29217, uid=10094) requires null
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Parcel.readException(Parcel.java:1322)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Parcel.readException(Parcel.java:1276)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1351)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.Activity.startActivityForResult(Activity.java:2827)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.Activity.startActivity(Activity.java:2933)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.ssbs.sw.IR.view.MainActivity$1$1.onMenuItemClick(MainActivity.java:58)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.ssbs.sw.SWE.actionbarV5.menu.MenuButtonHelper$1.onClick(MenuButtonHelper.java:108)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.view.View.performClick(View.java:2492)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.view.View$PerformClick.run(View.java:9087)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Handler.handleCallback(Handler.java:587)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Looper.loop(Looper.java:130)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.ActivityThread.main(ActivityThread.java:3740)
05-14 17:13:42.853: E/AndroidRuntime(29217): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 17:13:42.853: E/AndroidRuntime(29217): at java.lang.reflect.Method.invoke(Method.java:507)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
05-14 17:13:42.853: E/AndroidRuntime(29217): at dalvik.system.NativeStart.main(Native Method)
This is my manifest from library project:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".activity.CameraActivity" android:exported="true" >
<intent-filter>
<action android:name="isr.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
How can I fix this?
EDIT
My main project manifest permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
EDIT 2
I have resolved my problem by coping to my main application manifest definition of called activity (but I would like to know if I can do this without adding this definition):
<activity android:name="com.ISR.activity.CameraActivity">
<intent-filter>
<action android:name="isr.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And now I can start my activity with following code:
Intent intent = new Intent("isr.LAUNCH");
startActivity(intent);
You can actually declare everything you want in the library's Manifest and then in your main project declare
manifestmerger.enabled=true
In your project.properties. What it does is actually merge your Manifests and you can see the resulting Manifest in your bin folder.
The manifest for your main app must contain all Activity definitions it wishes to use. They are not required in the library project as they are not called from there.
Any activity definitions you have in your library manifest actually do nothing at all.
Update: You can now merge manifest files as other answers have mentioned.

Sorry the application has stopped unexpectedly android

Can someone please tell me how to fix my problem? I'm building my first android app and below is the error codes I get when application is launched in Emulator.
Thank you
04-12 21:07:03.480: D/AndroidRuntime(327): Shutting down VM
04-12 21:07:03.480: W/dalvikvm(327): threadid=1: thread exiting with uncaught exception(group=0x40015560)
04-12 21:07:03.580: E/AndroidRuntime(327): FATAL EXCEPTION: main
04-12 21:07:03.580: E/AndroidRuntime(327): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{obd.gss.namespace/obd.gss.namespace.activity.Gssobdreadermainactivity}: java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity in loader dalvik.system.PathClassLoader[/data/app/obd.gss.namespace-1.apk]
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.os.Looper.loop(Looper.java:123)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.reflect.Method.invoke(Method.java:507)
04-12 21:07:03.580: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-12 21:07:03.580: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-12 21:07:03.580: E/AndroidRuntime(327): at dalvik.system.NativeStart.main(Native Method)
04-12 21:07:03.580: E/AndroidRuntime(327): Caused by: java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity in loader dalvik.system.PathClassLoader[/data/app/obd.gss.namespace-1.apk]
04-12 21:07:03.580: E/AndroidRuntime(327): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
04-12 21:07:03.580: E/AndroidRuntime(327): ... 11 more
Here are the contents of my manifest:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".Activity.Gssobdreadermainactivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity.Gssobdreaderconfigactivity"
android:label="#string/app_name">
</activity>
<activity android:name=".activity.Gssobdreadercommandactivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
<service android:name="io.GssobdReaderService"/>
</application>
The cause of your problem is:
java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity
Did you forget to add your Activity to your manifest?
Your Manifest should look something like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="obd.gss.namespace"
android:versionCode="1"
android:versionName="1.0" >
<!-- permissions and other stuff here -->
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".activity.Gssobdreadermainactivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--more activities and services here -->
</application>
</manifest>
Note that the combination of the manifest tag's package attribute and the activity tag's name attribute should be exactly the same as the fully qualified name of your class. Using my above example, you would wind up with:
obd.gss.namespace.activity.Gssobdreadermainactivity
I've had a similar issue, particularly with newly imported projects. The closest thing to a solution I've found is to make sure the .classpath file is writable, restart Eclipse(or whichever IDE you use), refresh the project, clean and build the project and try again. This doesn't always fix it, but doing it a couple times usually makes the error go away for me. The essence of the error is that the Android OS can't find the Activity, although it does know that the Activity should exist and is trying to launch it.
What does your source tree look like? You probably need to remove the .activity. and .Activity. prefixes from your applications fully quallified class name. Unless, of course, you have an "activity" and an "Activity" folder in your source tree (=

Categories

Resources