android 开机启动_关机_重启

来源:百度文库 编辑:神马文学网 时间:2024/10/02 21:26:19
file 1 :(采用BroadcastReceiver 发送广播可以在每次开机时跑到你指定的class)
public class Boot_Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context,Intent intent){
Intent i=new Intent(Intent.ACTION_RUN);
i.setClass(context,C.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
file 2 :(shutdown 功能的实现)
case R.id.Coldboot : {
mPowerCycleType="Coldboot";
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}break;
(restart功能的实现)
case R.id.Warmboot : {
mPowerCycleType="Warmboot";
//Get the current system time
mTime=GetSystemDate().toString();
boot_SharedPreferences_put();
Intent i=new Intent();
i.setClass(B.this,C.class);
startActivity(i);
}break;
AndroidManifest.xml :(声明权限)
package="wistron.mojo"
android:sharedUserId="android.uid.system"
>





。。。。。。。。
。。。。。。。。