Android 2.2: How to make an app to run automaticly

2020-07-18 06:30发布

The topic pretty much says it all.

2条回答
Evening l夕情丶
2楼-- · 2020-07-18 06:40

Use BroadcastReceiver that receives Intent of action BOOT_COMPLETED.

in onReceive() method create an Intent for your activity:

@Override
public void onReceive(Context context, Intent intent) {

 Intent myIntent = new Intent(context, YourActivity.class);
 context.startActivity(myIntent);
}
查看更多
戒情不戒烟
3楼-- · 2020-07-18 06:43

For the application on startup, you need to add the permission

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

to your manifest. Then do as Vladimir wrote.

For starting another app, you need to know the (hopefully official) intent to start it. Otherwise see my reply on question calling an activity that is in another package(android)

For example, starting the LastFM app would be like this:

final Intent i = new Intent("android.intent.action.MAIN");                
i.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(i);
查看更多
登录 后发表回答