android引導(dǎo)用戶開啟自啟動權(quán)限的方法

前言:

從策劃到設(shè)計制作,每一步都追求做到細(xì)膩,制作可持續(xù)發(fā)展的企業(yè)網(wǎng)站。為客戶提供做網(wǎng)站、成都網(wǎng)站制作、網(wǎng)站策劃、網(wǎng)頁設(shè)計、國際域名空間、雅安服務(wù)器托管、網(wǎng)絡(luò)營銷、VI設(shè)計、 網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,以客戶的口碑塑造優(yōu)易品牌,攜手廣大客戶,共同發(fā)展進(jìn)步。

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

需求:

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

問題:

1.如何適配不同機(jī)型

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

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

4.在授權(quán)頁面點(diǎn)擊返回按鈕,怎么直接跳轉(zhuǎn)到主頁面

問題1:適配不同機(jī)型

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

public class MobileInfoUtils{
 private SettingDialogPermision dialog_per;
 //獲取手機(jī)類型
 private static String getMobileType() {
  return Build.MANUFACTURER;
 }

 //跳轉(zhuǎn)至授權(quán)頁面
 public void jumpStartInterface(Context context) {
  Intent intent = new Intent();
  try {
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   Log.e("HLQ_Struggle", "******************當(dāng)前手機(jī)型號為:" + 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,不允許被其他程序調(diào)用
    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");//跳轉(zhuǎn)到手機(jī)管家
    componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.SmartBGActivity");//跳轉(zhuǎn)到后臺管理頁面
   } else if (getMobileType().equals("OPPO")) { // OPPO R8205測試通過
    componentName = ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity");
   } else if (getMobileType().equals("ulong")) { // 360手機(jī) 未測試
    componentName = new ComponentName("com.yulong.android.coolsafe", ".ui.activity.autorun.AutoRunListActivity");
   } else {
    // 將用戶引導(dǎo)到系統(tǒng)設(shè)置頁面
    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) {//拋出異常就直接打開設(shè)置頁面
   Log.e("HLQ_Struggle", e.getLocalizedMessage());
   intent = new Intent(Settings.ACTION_SETTINGS);
   context.startActivity(intent);
  }
 }

//小米手機(jī)顯示彈窗
 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:不同機(jī)型的授權(quán)頁面顯示不同彈窗

在上面的問題中已經(jīng)解決。

思路如下:

①首先判斷當(dāng)前的機(jī)型

②判斷完機(jī)型之后,通過intent跳轉(zhuǎn)至不同的授權(quán)頁面

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

④小米手機(jī)在顯示彈窗的時候?qū)懮舷旅孢@一句話:

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

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

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

在問題2的第4步解決

問題4:在授權(quán)頁面點(diǎn)擊返回按鈕,怎么直接跳轉(zhuǎn)到主頁面

邏輯梳理:

Activity A——–點(diǎn)擊請求授權(quán)—–>跳轉(zhuǎn)至系統(tǒng)授權(quán)頁——–點(diǎn)擊back鍵——–>要求跳轉(zhuǎn)到主頁面(也就是MainActivity,注意不是Activity A)

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

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

在授權(quán)頁面,點(diǎn)擊返回鍵后,會再次跳轉(zhuǎn)到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();
 }

這次再次體現(xiàn)了基礎(chǔ)!基礎(chǔ)!基礎(chǔ)!是多么重要!

以上這篇android引導(dǎo)用戶開啟自啟動權(quán)限的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持創(chuàng)新互聯(lián)。

當(dāng)前標(biāo)題:android引導(dǎo)用戶開啟自啟動權(quán)限的方法
分享路徑:http://muchs.cn/article4/jcpjoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、虛擬主機(jī)、動態(tài)網(wǎng)站面包屑導(dǎo)航、企業(yè)建站、服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)