Android代码一旦手机启动就启动我的应用程序

时间:2012-10-20 16:09:38

标签: android

任何人都可以在手机启动后立即给我提供启动应用程序的示例代码

1 个答案:

答案 0 :(得分:5)

你需要这样的BroadcastReceiver

public class MyBroadcastreceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Intent i = new Intent(YourClass)
            context.startService(i);
        }
    }
}

也是此用户权限

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

以及manifest.xml中标记中的recever

<receiver android:name="com.example.MyBroadcastReceiver">  
    <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />  
    </intent-filter>  
</receiver>