2016-12-26 63 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

「你必須完成答案,對吧?」什麼? –

相關問題