這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)如何實現(xiàn)靜默安裝Android應(yīng)用,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
成都創(chuàng)新互聯(lián)公司長期為千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為華陰企業(yè)提供專業(yè)的做網(wǎng)站、成都網(wǎng)站制作,華陰網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
1、root權(quán)限靜默安裝實現(xiàn)
實現(xiàn)實際使用的是su pm install -r filePath
命令。
核心代碼如下:
protected static void excuteSuCMD() { Process process = null; OutputStream out = null; InputStream in = null; String currentTempFilePath = "/sdcard/QQ.apk"; try { // 請求root process = Runtime.getRuntime().exec("su"); out = process.getOutputStream(); // 調(diào)用安裝 out.write(("pm install -r " + currentTempFilePath + "\n").getBytes()); in = process.getInputStream(); int len = 0; byte[] bs = new byte[256]; while (-1 != (len = in.read(bs))) { String state = new String(bs, 0, len); if (state.equals("Success\n")) { //安裝成功后的操作 } } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.flush(); out.close(); } if (in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); } } }
2、非root權(quán)限提示用戶安裝,代碼如下:
public static void openFile() { // 核心是下面幾句代碼 if (!isHasfile()) { downLoadFile(url); } Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType( Uri.fromFile(new File("/sdcard/update/updata.apk")), "application/vnd.android.package-archive"); mContext.startActivity(intent); }
上述就是小編為大家分享的如何實現(xiàn)靜默安裝Android應(yīng)用了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
名稱欄目:如何實現(xiàn)靜默安裝Android應(yīng)用
網(wǎng)頁鏈接:http://aaarwkj.com/article16/iggsgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、動態(tài)網(wǎng)站、建站公司、營銷型網(wǎng)站建設(shè)、微信公眾號、App設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)