2

嗨,谁能给我手机启动后立即启动应用程序的示例代码

4

1 回答 1

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 中标签中的接收器

<receiver android:name="com.example.MyBroadcastReceiver">  
    <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />  
    </intent-filter>  
</receiver>
于 2012-10-20T16:14:40.067 回答