免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Android]實現(xiàn)靜默安裝APK的兩種方法
  Android上的靜默安裝似乎是個很誘人的功能,好多人都問這個問題。今天分享下實現(xiàn)靜默安裝的兩種方法,但當(dāng)看完這篇文章后,仍會讓一些人失望滴。

      Android把所有的Permission依據(jù)其潛在風(fēng)險(屬性名為protectionLevel )劃分為四個等級,即"normal "、 "dangerous "、 "signature "、 "signatureOrSystem "。 INSTALL_PACKAGES屬于后兩者。讓我們看一下官方文檔對后兩類的描述吧。

 

"signature ": A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.

 

"signatureOrSystem ": A permission that the system grants only to applications that are in the Android system image   or   that are signed with the same certificates as those in the system image. Please avoid using this option, as thesignature   protection level should be sufficient for most needs and works regardless of exactly where applications are installed. The "signatureOrSystem " permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.

 

      所以,這兒介紹的兩種方法各自需要的苛刻條件如下:

      1.內(nèi)置到ROM。即APK包的安裝位置是/system/app下。

      2.使用APK的目標(biāo)安裝系統(tǒng)同樣的簽名。

 

 

      好了,先不管這些苛刻的條件,下面講下如何編寫直接安裝APK的代碼,這兒使用pm install <apk_path>命令,而不是繁雜的未公開的PackageManager.install()方法。

  1. String[] args = { "pm""install""-r", apkAbsolutePath };  
  2. String result = "";  
  3. ProcessBuilder processBuilder = new ProcessBuilder(args);  
  4. Process process = null;  
  5. InputStream errIs = null;  
  6. InputStream inIs = null;  
  7. try {  
  8.     ByteArrayOutputStream baos = new ByteArrayOutputStream();  
  9.     int read = -1;  
  10.     process = processBuilder.start();  
  11.     errIs = process.getErrorStream();  
  12.     while ((read = errIs.read()) != -1) {  
  13.         baos.write(read);  
  14.     }  
  15.     baos.write('/n');  
  16.     inIs = process.getInputStream();  
  17.     while ((read = inIs.read()) != -1) {  
  18.         baos.write(read);  
  19.     }  
  20.     byte[] data = baos.toByteArray();  
  21.     result = new String(data);  
  22. catch (IOException e) {  
  23.     e.printStackTrace();  
  24. catch (Exception e) {  
  25.     e.printStackTrace();  
  26. finally {  
  27.     try {  
  28.         if (errIs != null) {  
  29.             errIs.close();  
  30.         }  
  31.         if (inIs != null) {  
  32.             inIs.close();  
  33.         }  
  34.     } catch (IOException e) {  
  35.         e.printStackTrace();  
  36.     }  
  37.     if (process != null) {  
  38.         process.destroy();  
  39.     }  
  40. }  
  41. return result;  

      代碼執(zhí)行后,如果安裝成功的話獲取到的result值是“        pkg: /data/local/tmp/Calculator.apk  /nSuccess”,如果是失敗的話,則沒有結(jié)尾的“Success”。

      安裝代碼有了,現(xiàn)在開始介紹第一種方法,將你自己的APK內(nèi)置到ROM中。前提是,你這手機(jī)已經(jīng)刷機(jī)過并且保留了recovery-windows.bat/recover-linux.sh 文件。

      針對HTC-Legend的具體操作步驟為:

      1.USB連接你的設(shè)備然后在命令行輸入 "adb reboot recovery" ,機(jī)子重啟,啟動后將顯示一個紅色的三角形和箭頭圖標(biāo)   

      2 .(在PC下)進(jìn)入到你的刷機(jī)文件夾然后運(yùn)行 './recover-linux.sh' ,屏幕將顯示綠色的菜單

      3 .如果得到的結(jié)果是 "error:device not found" ,運(yùn)行 "./adb-linux kill-server" 后再一次運(yùn)行 './recovery-linux.sh' 直到顯示綠色菜單.

      4 .執(zhí)行 "adb shell mount /dev/block/mtdblock3 /system" ,至此,可對/system進(jìn)行寫操作。

      5.在PC上運(yùn)行命令:adb push <your_apk_path> /system/<your_apk_name>。至此,內(nèi)置成功。

 

 

      第二種方法,需要先打一個未簽名的APK包,然后用系統(tǒng)簽名對其進(jìn)行簽名。這個方面的東西在我之前的一篇博文已說明,這兒就不重復(fù)了 

      由于HTC-Legend是“原裝”的,所以靜默安裝倒是順利。但對于一些MOTO或樂Phone的手機(jī),一般上是不支持的。


      以上這兩種方法都在AndroidManifest中聲明android.permission.INSTALL_PACKAGES,有一點比較奇怪的是執(zhí)行“ int result = checkCallingOrSelfPermission(Intent.ACTION_PACKAGE_INSTALL) ”,result的值為android.content.pm.PackageManager.PERMISSION_DENIED而不是PERMISSION_GRANTED。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
android apk靜默安裝和卸載
異常信息全部轉(zhuǎn)換字符串
Android Permission 機(jī)制
Android ap goToSleep
android 4.0.4系統(tǒng)下實現(xiàn)apk的靜默安裝和啟動
Android 懸浮窗延時5秒返回APP問題
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服