用代碼的方式打開“允許安裝來自未知來源的應用”


在手機上,當然可以通過系統的設置來將其打開,但是如果某個設備上沒有該設置呢?

以下的代碼需要平台的簽名或者作為系統應用來運行才行(adb push <your apk files> /system/app/<your apk files>) ---當然

需要先運行 adb root

1.需要添加的權限

        <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
    <uses-permission android:name="android.permission.READ_SECURE_SETTINGS"/>
    <uses-permission android:name="android.permission.READ_SETTINGS"/> 

2.

import android.provider.Settings;
import android.content.ContentValues;

     ContentValues values = new ContentValues(); values.put("value", 1);
    Cursor cursor = null;
try{ int value = 0; cursor = getContentResolver().query(Settings.Secure.CONTENT_URI,
          new String[] { "value",}, "name=?", new String[] {Settings.Secure.INSTALL_NON_MARKET_APPS}, null); if(cursor != null && cursor.moveToNext()){ value = cursor.getInt(cursor.getColumnIndex("value")); }
if(cursor != null){
          cursor.close();
         cursor = null;
       }
if(0 == value){ int i = getContentResolver().update(Settings.Secure.CONTENT_URI, values,"name=?", new String[] {Settings.Secure.INSTALL_NON_MARKET_APPS} ); if(i > 0){ Log.e("", "success"); }else{ Log.e("", "fail"); } } }catch (Exception e) { e.printStackTrace(); }finally{
if(cursor != null){
          cursor.close();
         cursor = null;
       }
     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM