欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2018年07月30日 16:12:43   作者:yanerly  
今天小編就為大家分享一篇android引導(dǎo)用戶開(kāi)啟自啟動(dòng)權(quán)限的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

前言:

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

需求:

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

問(wèn)題:

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

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

3.小米彈窗始終無(wú)法顯示

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

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

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

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

 //跳轉(zhuǎn)至授權(quán)頁(yè)面
 public void jumpStartInterface(Context context) {
  Intent intent = new Intent();
  try {
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   Log.e("HLQ_Struggle", "******************當(dāng)前手機(jī)型號(hào)為:" + getMobileType());
   ComponentName componentName = null;
   if (getMobileType().equals("Xiaomi")) { // 紅米Note4測(cè)試通過(guò)
    componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");

   } else if (getMobileType().equals("Letv")) { // 樂(lè)視2測(cè)試通過(guò)
    intent.setAction("com.letv.android.permissionautoboot");
   } else if (getMobileType().equals("samsung")) { // 三星Note5測(cè)試通過(guò)
    //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")) { // 華為測(cè)試通過(guò)
    //componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");//鎖屏清理
    componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity");//跳自啟動(dòng)管理
    //SettingOverlayView.show(context);
   } else if (getMobileType().equals("vivo")) { // VIVO測(cè)試通過(guò)
    componentName = ComponentName.unflattenFromString("com.iqoo.secure/.safeguard.PurviewTabActivity");
   } else if (getMobileType().equals("Meizu")) { //萬(wàn)惡的魅族
    //componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.PermissionMainActivity");//跳轉(zhuǎn)到手機(jī)管家
    componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.SmartBGActivity");//跳轉(zhuǎn)到后臺(tái)管理頁(yè)面
   } else if (getMobileType().equals("OPPO")) { // OPPO R8205測(cè)試通過(guò)
    componentName = ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity");
   } else if (getMobileType().equals("ulong")) { // 360手機(jī) 未測(cè)試
    componentName = new ComponentName("com.yulong.android.coolsafe", ".ui.activity.autorun.AutoRunListActivity");
   } else {
    // 將用戶引導(dǎo)到系統(tǒng)設(shè)置頁(yè)面
    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) {//拋出異常就直接打開(kāi)設(shè)置頁(yè)面
   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);//注意這里改成吐司類(lèi)型
   dialog_per.show();
   Log.e("HLQ_Struggle","顯示彈窗");
  } catch (Exception e) {
   e.printStackTrace();
   Log.e("HLQ_Struggle", "沒(méi)有顯示彈窗"+e.getMessage());
  }
 }
}

問(wèn)題2:不同機(jī)型的授權(quán)頁(yè)面顯示不同彈窗

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

思路如下:

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

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

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

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

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

因?yàn)檫@里類(lèi)型沒(méi)有用“吐司”,所以在授權(quán)頁(yè)面一直不顯示彈窗

問(wèn)題3:小米彈窗始終無(wú)法顯示

在問(wèn)題2的第4步解決

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

邏輯梳理:

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

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

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

在授權(quán)頁(yè)面,點(diǎn)擊返回鍵后,會(huì)再次跳轉(zhuǎn)到Activity A頁(yè)面,這時(shí)候只需要在Activity A中寫(xiě)上以下代碼就完美的解決了:

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)用戶開(kāi)啟自啟動(dòng)權(quán)限的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論