Android实现app内部更改系统时间(需要手机root)

时间:2022-06-29 16:02:05

Android可通过shell脚本修改系统时间(测试可行)

1、root手机一部

2、封装修改时间代码

public void testDate(String time){
textView.setText(getDate(timeLong));
try {
Process process = Runtime.getRuntime().exec("su");
String datetime = time; //测试的设置的时间【时间格式 yyyyMMdd.HHmmss】
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("setprop persist.sys.timezone GMT\n");
os.writeBytes("/system/bin/date -s "+datetime+"\n");
os.writeBytes("clock -w\n");
os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
3、注册当音量发生变化时接收的广播 

    private void myRegisterReceiver(){        mVolumeReceiver = new MyVolumeReceiver() ;        IntentFilter filter = new IntentFilter() ;        filter.addAction("android.media.VOLUME_CHANGED_ACTION");        registerReceiver(mVolumeReceiver, filter) ;        System.out.print("android.media.VOLUME_CHANGED_ACTION");    }