i m creating app that has permission to autostart with boot. and it is working fine on those mobile that does not contains Permission manager.
i want to start my app like Whats App and Wechat and other app does. But permission manager stop my app to auto start - MI Redme Note 4g mobile and Samsung mobile. Basically, i want to override the permission manager setting so that my app will start
currently i m using these code
<receiver
android:name=".BootComplete"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".AutoStartUp" >
</service>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Please Advice me to get my app auto start like Whats App, Wechat, Youtube and Other app does
thanks in Advance
What your code does here is that: When the device is booted it will tell the broadcast receiver, now the broadcast receiver needs to start the Service or App or whatever you want to start:
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent0) {
if(! isMyServiceRunning(MyFirstService.class, context)){//test
Intent startServiceIntent = new Intent(context, MyFirstService.class);
context.startService(startServiceIntent);
}
}
private boolean isMyServiceRunning(Class<?> serviceClass,Context context) {
ActivityManager manager = (ActivityManager)context. getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}
This code also checks if the Service is already running (for some reason) and you can remove that part if you want.