2016-12-26 65 views
0

我的代码应该安装我的应用程序,名为“xadb-build.apk”,但它什么都不做,没有错误,没有强制关闭,我只看到授予烤面包的超级用户权限。这里是我的方法如何从SD卡安装应用程序?

File sdCard = Environment.getExternalStorageDirectory(); 
    String fileStr = sdCard.getAbsolutePath() + "/download";// + 
                  // "app-release.apk"; 

    File file = new File(fileStr, "xadb-build.apk"); 

    if (file.exists()) { 
     try { 
      String command; 
      command = "adb install -r " + file; 
      Process proc = Runtime.getRuntime().exec(
        new String[] { "su", "-c", command }); 
      proc.waitFor(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

} 

我得到这个代码here(见PALAK的答案)

+0

您是否尝试使用'pm install'而不是'adb install'作为palak答案中的一条评论建议? –

+0

'getExternalStorageDirectory();'。这不是SD卡,而是外部存储器。你在说什么? – greenapps

回答

0

Android支持此方法。

File apkFile = new File({path to APK}); 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); 
     startActivity(intent); 

而且不推荐您的方法。

+0

只有根。谢谢 –

+0

你必须完成答案,对吧? –

+0

“你必须完成答案,对吧?”什么? –

相关问题