国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android引導用戶開啟自啟動權限的方法

2019-10-21 21:44:23
字體:
來源:轉載
供稿:網友

前言:

最近在做項目的過程中遇到了以下一個需求,雖然看起來不難實現,但是在實現的過程中遇到了各種坑,記錄一下,今后方便查看!!!

需求:

用戶第一次安裝APP,點擊授權按鈕,跳轉至授權的頁面(不同手機跳轉到不同的授權頁面),用戶授權成功之后,點擊返回按鈕,直接進入主頁面

問題:

1.如何適配不同機型

2.不同機型的授權頁面顯示不同彈窗(比如三星顯示懸浮窗,小米顯示彈窗)

3.小米彈窗始終無法顯示

4.在授權頁面點擊返回按鈕,怎么直接跳轉到主頁面

問題1:適配不同機型

這個是借鑒的一篇博文(忘記地方了,后邊找到了再添加~~)

public class MobileInfoUtils{ private SettingDialogPermision dialog_per; //獲取手機類型 private static String getMobileType() {  return Build.MANUFACTURER; } //跳轉至授權頁面 public void jumpStartInterface(Context context) {  Intent intent = new Intent();  try {   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   Log.e("HLQ_Struggle", "******************當前手機型號為:" + getMobileType());   ComponentName componentName = null;   if (getMobileType().equals("Xiaomi")) { // 紅米Note4測試通過    componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");   } else if (getMobileType().equals("Letv")) { // 樂視2測試通過    intent.setAction("com.letv.android.permissionautoboot");   } else if (getMobileType().equals("samsung")) { // 三星Note5測試通過    //componentName = new ComponentName("com.samsung.android.sm_cn", "com.samsung.android.sm.ui.ram.AutoRunActivity");    //componentName = ComponentName.unflattenFromString("com.samsung.android.sm/.ui.ram.RamActivity");// Permission Denial not exported from uid 1000,不允許被其他程序調用    componentName = ComponentName.unflattenFromString("com.samsung.android.sm/.app.dashboard.SmartManagerDashBoardActivity");   } else if (getMobileType().equals("HUAWEI")) { // 華為測試通過    //componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");//鎖屏清理    componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity");//跳自啟動管理    //SettingOverlayView.show(context);   } else if (getMobileType().equals("vivo")) { // VIVO測試通過    componentName = ComponentName.unflattenFromString("com.iqoo.secure/.safeguard.PurviewTabActivity");   } else if (getMobileType().equals("Meizu")) { //萬惡的魅族    //componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.PermissionMainActivity");//跳轉到手機管家    componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.SmartBGActivity");//跳轉到后臺管理頁面   } else if (getMobileType().equals("OPPO")) { // OPPO R8205測試通過    componentName = ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity");   } else if (getMobileType().equals("ulong")) { // 360手機 未測試    componentName = new ComponentName("com.yulong.android.coolsafe", ".ui.activity.autorun.AutoRunListActivity");   } else {    // 將用戶引導到系統設置頁面    if (Build.VERSION.SDK_INT >= 9) {     Log.e("HLQ_Struggle", "APPLICATION_DETAILS_SETTINGS");     intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");     intent.setData(Uri.fromParts("package", context.getPackageName(), null));    } else if (Build.VERSION.SDK_INT <= 8) {     intent.setAction(Intent.ACTION_VIEW);     intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");     intent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());    }   }   intent.setComponent(componentName);   context.startActivity(intent);   if (getMobileType().equals("Xiaomi")) {    showtip();//顯示彈窗(**特別注意**)   }   if (getMobileType().equals("samsung")){    new SettingOverlayView().show(context);//顯示懸浮窗   }  } catch (Exception e) {//拋出異常就直接打開設置頁面   Log.e("HLQ_Struggle", e.getLocalizedMessage());   intent = new Intent(Settings.ACTION_SETTINGS);   context.startActivity(intent);  } }//小米手機顯示彈窗 private void showtip() {  try {   dialog_per=new SettingDialogPermision(context, R.style.CustomDialog4);   dialog_per.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);//注意這里改成吐司類型   dialog_per.show();   Log.e("HLQ_Struggle","顯示彈窗");  } catch (Exception e) {   e.printStackTrace();   Log.e("HLQ_Struggle", "沒有顯示彈窗"+e.getMessage());  } }}

問題2:不同機型的授權頁面顯示不同彈窗

在上面的問題中已經解決。

思路如下:

①首先判斷當前的機型

②判斷完機型之后,通過intent跳轉至不同的授權頁面

③在startActivity()之后顯示懸浮窗或者是彈窗

④小米手機在顯示彈窗的時候寫上下面這一句話:

getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST)

因為這里類型沒有用“吐司”,所以在授權頁面一直不顯示彈窗

問題3:小米彈窗始終無法顯示

在問題2的第4步解決

問題4:在授權頁面點擊返回按鈕,怎么直接跳轉到主頁面

邏輯梳理:

Activity A——–點擊請求授權—–>跳轉至系統授權頁——–點擊back鍵——–>要求跳轉到主頁面(也就是MainActivity,注意不是Activity A)

在實現的過程中,就一直鉆牛角尖,這個授權頁面的Activity我也拿不到,怎么監聽返回按鈕呢???(黑人問號臉)

所以啊,這時候就體現出Activity生命周期的重要性了。

在授權頁面,點擊返回鍵后,會再次跳轉到Activity A頁面,這時候只需要在Activity A中寫上以下代碼就完美的解決了:

protected void onRestart() {  super.onRestart();  Intent intent = new Intent(SelfStartAcitity.this,MainActivity.class);  startActivity(intent);  overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);  finish(); }

這次再次體現了基礎!基礎!基礎!是多么重要!

以上這篇android引導用戶開啟自啟動權限的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平凉市| 东辽县| 增城市| 成都市| 长丰县| 林州市| 西藏| 岚皋县| 公安县| 天津市| 新民市| 胶州市| 唐河县| 菏泽市| 璧山县| 兴安县| 民权县| 尚志市| 绥中县| 鲁甸县| 祁门县| 定结县| 龙井市| 嘉义市| 上林县| 静乐县| 江川县| 营口市| 平和县| 堆龙德庆县| 罗甸县| 大港区| 定西市| 彭水| 敖汉旗| 建湖县| 舒兰市| 正阳县| 天台县| 万宁市| 西和县|