很简单,我们只要实现开机自启动即可,android实现开机自启动可能是移动操作系统中最简单的了,我们只需要监听一个开机启动的 Broadcast(广播)即可。首先写一个Receiver(即广播监听器),继承BroadcastReceiver,如下所示:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
//如果开机启动完成则启动你的应用界面
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent splash=new Intent(context,SplashScreen.class);
splash.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(splash);
}
}
}
接着在应用程序配置文件AndroidManifest.xml中注册这个Receiver来监听系统启动事件
<receiver android:name=".BootReceiver">
<intent-filter>
<!-- 系统启动完成后会调用-->
<action android:name="android.intent.action.BOOT_COMPLETED">
</action>
</intent-filter>
</receiver>
android程序开机启动【转帖】
最新推荐文章于 2024-07-25 19:04:18 发布