![](/img/trans.png)
[英]Bluetooth Enable Disable ADB command and Opening Android Activity with Android Driver not working in Some Android 7 devices
[英]How to enable Android permissions with adb for all devices
我希望在安裝應用程序時自動激活所有 Android 權限。
我知道我可以通過 adb 安裝 apk 在我的設備上啟用所有權限。
adb install -g test.apk
我可以對所有設備使用此方法還是可以自動啟用權限?
我想您必須 root 設備 android 才能為您的應用程序提供所有可用權限。 每次,為應用程序的 apk 安裝激活 ADB shell 都是不可行的。 為了避免這種情況,您可以簡單地編寫這段代碼:
private void AllowPerm()
{
Log.d(TAG,"Allow all permissions: Prompting User...");
// Defining the requierd permissions in the below String array.
String[] perm={Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,};
if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
perm[0])== PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(this.getApplicationContext(),
perm[1])==PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(this.getApplicationContext(),
perm[2])==PackageManager.PERMISSION_GRANTED)
{
return;
}
else
{
ActivityCompat.requestperm(MainActivity.this,perm,REQUEST_CODE);
}
}
@Override
public void onRequestpermResult(int requestCode, @NonNull String[] perm, @NonNull int[] grantResults) {
AllowPerm();
}
您可以通過查看此文檔在 String 數組中授予所需的權限
您也可以通過在AndroidManifest.xml
中手動聲明PERMISSIONS
來執行上述步驟(參考this )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.