I am working on one app which will start a service automatically at device start ( after boot complete ). i did code but i think something is going wrong with my code. i have tried google too and all the tricks while research. can you please help me? Thanx in advance.
here is my code :
My BroadcastReceiver is
public class AutostartReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Toast.makeText(this, "Booting Completed", Toast.LENGTH_LONG).show();
//context.startService(new Intent(context, MyService.class));
}
}
}
My AndroidMenifest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myhiddenapp"
android:installLocation="internalOnly"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/ic_launcher"
android:label="MyHiddenApp" >
<receiver
android:name=".AutostartReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".MyService" />
</application>
</manifest>
Note : I have not any Activity, i just want to start Service on Boot Complete.
You Must set android:installLocation="internalOnly"
https://developer.android.com/guide/topics/data/install-location.html#Should