automatically run an application on Android phone startup

后端 未结 4 1414
一整个雨季
一整个雨季 2020-12-18 16:59

I want to start my application when phone startup

I just follow tutorial from here but it doesn\'t work in my device. Please see my method:

public c         


        
4条回答
  •  梦毁少年i
    2020-12-18 17:42

    I've done something similiar, but I was starting activity. Here is how I done it:

    In Manifest:

    
    

    In Java code:

    public class BootUpReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            PendingIntent i = PendingIntent.getActivity(context, 0, new Intent(
                    context,MainActivity.class),
                    Intent.FLAG_ACTIVITY_NEW_TASK);
            AlarmManager mgr = (AlarmManager) context
                    .getSystemService(Context.ALARM_SERVICE);
            mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 20000, i);
        }
    }
    

    Your code seems to be correct, but try using PendingIntent ;) Hope it helps you

提交回复
热议问题