美文网首页
安卓修改系统时间

安卓修改系统时间

作者: 大宇宙宙 | 来源:发表于2017-11-13 10:45 被阅读45次

做安卓机顶盒开发的时候,由于盒子重启过后时间会重置,回到1970年,无法进行接口签名认证,所以需求就来了。

1、修改时间的核心代码如下:

```

static Process createSuProcess() throws IOException  {

File rootUser = new File("/system/xbin/ru");

if(rootUser.exists()) {

return Runtime.getRuntime().exec(rootUser.getAbsolutePath());

} else {

return Runtime.getRuntime().exec("su");

}

}

static Process createSuProcess(String cmd) throws IOException {

DataOutputStream os = null;

Process process = createSuProcess();

try {

os = new DataOutputStream(process.getOutputStream());

os.writeBytes(cmd + "\n");

os.writeBytes("exit $?\n");

} finally {

if(os != null) {

try {

os.close();

} catch (IOException e) {

}

}

}

return process;

}

static void requestPermission() throws InterruptedException, IOException {

createSuProcess("chmod 666 /dev/alarm").waitFor();

}

public void setDateTime(int year, int month, int day, int hour, int minute) {

try {

requestPermission();

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Calendar c = Calendar.getInstance();

c.set(Calendar.YEAR, year);

c.set(Calendar.MONTH, month-1);

c.set(Calendar.DAY_OF_MONTH, day);

c.set(Calendar.HOUR_OF_DAY, hour);

c.set(Calendar.MINUTE, minute);

long when = c.getTimeInMillis();

if (when / 1000 < Integer.MAX_VALUE) {

SystemClock.setCurrentTimeMillis(when);

}

long now = Calendar.getInstance().getTimeInMillis();

Log.d(TAG, "set tm="+when + ", now tm="+now);

}

```

2、在应用程序的AndroidManifest.xml中的manifest节点中加入android:sharedUserId="android.uid.system"这个属性。

3、使用目标系统的platform密钥来重新给apk文件签名。将apk拷贝到当前目录下,然后执行Sign-platform.bat脚本,为apk进行系统签名。

执行完以上三步之后,采用普通安装方法,可以设置时间。

时间是可以设置了,但是签名也已经变了  不能更新升级。。。

相关文章

  • 安卓修改系统时间

    做安卓机顶盒开发的时候,由于盒子重启过后时间会重置,回到1970年,无法进行接口签名认证,所以需求就来了。 1、修...

  • 修改安卓设备系统时间

    项目中遇到了使用 System.currentTimeMillis()获取的系统时间不准确,原因是我们的安卓设备的...

  • 此应用专为旧版安卓打造

    解决方案:将targetSdkVersion修改为≥安卓系统的版本号,例如安卓5.0则修改为21及以上,以此类推。

  • 安卓系统签名修改

    1.安卓签名和密钥 Android OS 映像在两个地方使用加密签名: 映像中的所有 .apk 文件都必须经过签名...

  • android默认设置项的修改

    修改默认值 在安卓源码中,要对安卓的一些默认属性配置进行修改的话(比如:修改背光默认,修改默认锁屏开关,休眠时间等...

  • 安卓App测试简析及工具Emmagee介绍

    一、安卓系统知识概述 1.1 安卓系统架构 应用程序层 应用程序框架层 系统运行库库层 系统内核层 1.2 安卓权...

  • 印象笔记安卓系统同步失败怎么办?

    退出安卓系统印象笔记账号,重新登录! 退出安卓系统印象笔记账号,重新登录!! 退出安卓系统印象笔记账号,重新登录!!!

  • 2019-06-14

    手机操作系统 手机操作系统发展到今天,主要有谷歌的安卓和苹果的ios系统。除苹果外,其他手机都是安卓系统。安卓系统...

  • andorid与开发版的必经之路

    安装vm虚拟机 ubuntu系统安装ssh软件安卓ADB功能介绍 实战修改开机logo和动画

  • 1.androidmiao

    1.android studio是开发安卓系统很好的工具; 2.开发安卓最好用linux系统或者mac,因为安卓是...

网友评论

      本文标题:安卓修改系统时间

      本文链接:https://www.haomeiwen.com/subject/qmcpjxtx.html