Android 6.0以上權(quán)限拒絕打開權(quán)限設(shè)置界面的解決方法
本人使用小米手機(jī),打開qq或者微信的時(shí)候,某個(gè)權(quán)限拒絕的話,會(huì)提示你開啟,點(diǎn)擊開啟會(huì)跳轉(zhuǎn)到app的權(quán)限設(shè)置界面,當(dāng)然了,這是國內(nèi)系統(tǒng)深層定制的原因,也就是說這個(gè)界面原聲的android沒有的!這里以小米和魅族作為示例講解如何讓用戶手動(dòng)打開權(quán)限,當(dāng)然了如果是原聲的android就讓他跳轉(zhuǎn)到應(yīng)用的詳情設(shè)置頁面(有點(diǎn)坑,因?yàn)槠胀ㄓ脩暨€是不知道怎么整)。
參考了很多零零碎碎的東西,網(wǎng)址已經(jīng)找不到了。。。。。。
ok,第一步是跳轉(zhuǎn)到系統(tǒng)的界面,下面基本上可以從9開始考慮了,可以簡化。
String SCHEME = "package"; //調(diào)用系統(tǒng)InstalledAppDetails界面所需的Extra名稱(用于Android 2.1及之前版本) final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName"; //調(diào)用系統(tǒng)InstalledAppDetails界面所需的Extra名稱(用于Android 2.2) final String APP_PKG_NAME_22 = "pkg"; //InstalledAppDetails所在包名 final String APP_DETAILS_PACKAGE_NAME = "com.android.settings"; //InstalledAppDetails類名 final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails"; Intent intent = new Intent(); final int apiLevel = Build.VERSION.SDK_INT; if (apiLevel >= 9) { // 2.3(ApiLevel 9)以上,使用SDK提供的接口 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts(SCHEME, getPackageName(), null); intent.setData(uri); } else { // 2.3以下,使用非公開的接口(查看InstalledAppDetails源碼) // 2.2和2.1中,InstalledAppDetails使用的APP_PKG_NAME不同。 final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22 : APP_PKG_NAME_21); intent.setAction(Intent.ACTION_VIEW); intent.setClassName(APP_DETAILS_PACKAGE_NAME, APP_DETAILS_CLASS_NAME); intent.putExtra(appPkgName, getPackageName()); } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
第二個(gè),miui,首先你得判斷是miui,親自測試,MIUI7穩(wěn)定版,MIUI8開發(fā)板本可行,工具類下面會(huì)提供下載
if (CheckPhoneSystemUtils.isMIUI()) { MLog.i("產(chǎn)品/硬件的制造商小米:"); intent.setAction("miui.intent.action.APP_PERM_EDITOR"); intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity"); intent.putExtra("extra_pkgname", getPackageName()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(intent); } catch (Exception e) { e.printStackTrace(); Toast.makeText(MediaRecoderService.this, "只有MIUI才可以設(shè)置哦", Toast.LENGTH_SHORT).show(); } }
第三個(gè),flyme(由于沒有flyme機(jī)子),采用的云手機(jī)測試的
else if (CheckPhoneSystemUtils.isFlyme()) { intent.setAction("com.meizu.safe.security.SHOW_APPSEC"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.putExtra("packageName", getPackageName()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(intent); } catch (Exception e) { e.printStackTrace(); Toast.makeText(MediaRecoderService.this, "只有Flyme才可以設(shè)置哦", Toast.LENGTH_SHORT).show(); } }
下面是工具類:BuildProperties
public class BuildProperties { private final Properties properties; private BuildProperties() throws IOException { properties = new Properties(); properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"))); } public boolean containsKey(final Object key) { return properties.containsKey(key); } public boolean containsValue(final Object value) { return properties.containsValue(value); } public Set<Map.Entry<Object, Object>> entrySet() { return properties.entrySet(); } public String getProperty(final String name) { return properties.getProperty(name); } public String getProperty(final String name, final String defaultValue) { return properties.getProperty(name, defaultValue); } public boolean isEmpty() { return properties.isEmpty(); } public Enumeration<Object> keys() { return properties.keys(); } public Set<Object> keySet() { return properties.keySet(); } public int size() { return properties.size(); } public Collection<Object> values() { return properties.values(); } public static BuildProperties newInstance() throws IOException { return new BuildProperties(); }
CheckPhoneSystemUtils
private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code"; private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name"; private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage"; /** * 檢測MIUI * * @return */ public static boolean isMIUI() { try { final BuildProperties prop = BuildProperties.newInstance(); return prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null || prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null; } catch (final IOException e) { return false; } } /** * 檢測Flyme * * @return */ public static boolean isFlyme() { try { // Invoke Build.hasSmartBar() final Method method = Build.class.getMethod("hasSmartBar"); return method != null; } catch (final Exception e) { return false; } }
以上這篇Android 6.0以上權(quán)限拒絕打開權(quán)限設(shè)置界面的解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android Animation之TranslateAnimation(平移動(dòng)畫)
這篇文章主要為大家詳細(xì)介紹了Animation之TranslateAnimation平移動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09Android判斷手機(jī)是否是小米MIUI系統(tǒng)的方法
這篇文章主要介紹了Android判斷手機(jī)是否是小米MIUI系統(tǒng)的方法的相關(guān)資料,需要的朋友可以參考下2016-02-02Android實(shí)現(xiàn)上下菜單雙向滑動(dòng)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)上下菜單雙向滑動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-10-10Android彈窗ListPopupWindow的簡單應(yīng)用詳解
這篇文章主要為大家詳細(xì)介紹了Android彈窗ListPopupWindow的簡單應(yīng)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11Android使用系統(tǒng)相機(jī)進(jìn)行拍照的步驟
這篇文章主要介紹了Android使用系統(tǒng)相機(jī)進(jìn)行拍照的步驟,幫助大家更好的進(jìn)行Android開發(fā),感興趣的朋友可以了解下2020-12-12Android Animation實(shí)戰(zhàn)之一個(gè)APP的ListView的動(dòng)畫效果
這篇文章主要介紹了Android Animation實(shí)戰(zhàn)項(xiàng)目,為大家分享了一個(gè)APP的ListView的動(dòng)畫效果,感興趣的小伙伴們可以參考一下2016-01-01Android實(shí)現(xiàn)自動(dòng)提取短信驗(yàn)證碼功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)自動(dòng)提取短信驗(yàn)證碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-01-01Flutter 首頁必用組件NestedScrollView的示例詳解
今天介紹的組件是NestedScrollView,大部分的App首頁都會(huì)用到這個(gè)組件。對Flutter 首頁必用組件NestedScrollView的相關(guān)知識(shí)感興趣的一起看看吧2020-05-05Android編程之?dāng)?shù)據(jù)庫的創(chuàng)建方法詳解
這篇文章主要介紹了Android編程之?dāng)?shù)據(jù)庫的創(chuàng)建方法,結(jié)合實(shí)例形式分析了Android數(shù)據(jù)庫創(chuàng)建的步驟、實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-08-08