我希望在我的应用程序中进行静默更新,无需任何用户交互。
但我总是收到错误代码 139。
硬件已root!
有人可以帮忙吗?
这是代码:
public class UpdateAPK extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.updateapk);
if (isRooted() == true) {
Toast.makeText(UpdateAPK.this, "Hardware is rooted", Toast.LENGTH_LONG).show();
try {
Process install = Runtime.getRuntime().exec(new String[] {"su", "-c", "pm install -r /mnt/sdcard/app.apk"});
install.waitFor();
if (install.exitValue() == 0) {
// Success :)
Toast.makeText(UpdateAPK.this, "Success!", Toast.LENGTH_LONG).show();
} else {
// Fail
Toast.makeText(UpdateAPK.this, "Failure. Exit code: " + String.valueOf(install.exitValue()), Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
System.out.println(e.toString());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
//Do soemthing else
}
}
谢谢你!
我会避免对整个 SD 卡路径进行硬编码。尝试这样的事情:
String filePath = Environment.getExternalStorageDirectory().toString() + "/your_app_directory/your_app_filename.apk";
Process installProcess = null;
int installResult = -666;
try
{
installProcess = Runtime.getRuntime().exec("su -c pm install -r " + filePath);
}
catch (IOException e)
{
// Handle IOException the way you like.
}
if (installProcess != null)
{
try
{
installResult = installProcess.waitFor();
}
catch(InterruptedException e)
{
// Handle InterruptedException the way you like.
}
}
if (installResult == 0)
{
// Success!
}
else
{
// Failure. :-/
}
另外,请注意权限...您可以添加:
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)