Browse Source

1.处理安装包存在,但activity不存在的导致的崩溃问题。

20241218TB223FC(测试jar包)
wangwanlei 10 months ago
parent
commit
31cf72fd4f

+ 36
- 30
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

@@ -289,7 +289,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
289 289
                    val rxPermissions = RxPermissions(this@MainActivity)
290 290
                    rxPermissions.request(Manifest.permission.REQUEST_INSTALL_PACKAGES)
291 291
                        .subscribe { granted ->
292
-                           if (granted || ModelNameUtils.IS_LianxX505f()) {
292
+                           if (granted || ModelNameUtils.IS_LianxX505f()||ModelNameUtils.IS_LianxX6e6f()) {
293 293
                                // 权限已授予,执行安装操作
294 294
                                val appList = AppUtils.GetAppList(this@MainActivity)
295 295
                                getExternalFilesDir(null)?.let {
@@ -477,8 +477,8 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
477 477
             viewModel.autoAppData.collect{
478 478
                 it?.let {
479 479
                     //连接不为空,并且应用已安装则跳转应用
480
-                    /*  it.authUrl="com.xhkjedu.xh_control_browser.MainActivity"
481
-                      it.appPackage="com.xhkjedu.xh_control_browser"*/
480
+                      it.authUrl="com.xhkjedu.xh_control_browser.MainActivit111y"
481
+                      it.appPackage="com.xhkjedu.xh_control_browser"
482 482
                     LogShow("锁定了吧"+mainLockFlag)
483 483
                     if (!mainLockFlag){
484 484
                         if (it.authUrl!=null&&AppUtils.isAppInstalled(this@MainActivity,it.appPackage)){
@@ -512,38 +512,44 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
512 512
     }
513 513
 
514 514
     private fun startAutoApp(autoAppBean: AutoAppBean){
515
-        val launchIntent = Intent()
516
-        launchIntent.setComponent(
517
-            ComponentName(
518
-                autoAppBean.appPackage!!,
519
-                autoAppBean.authUrl!!
515
+        try {
516
+            val launchIntent = Intent()
517
+            launchIntent.setComponent(
518
+                ComponentName(
519
+                    autoAppBean.appPackage!!,
520
+                    autoAppBean.authUrl!!
521
+                )
520 522
             )
521
-        )
522
-        launchIntent.putExtra("authType",autoAppBean.authType)
523
-        userBean?.let {
524
-            when(autoAppBean.authType){
525
-                1->{
526
-                    val userid = it.userid
527
-                    launchIntent.putExtra("authData",userid.toString())
528
-                }
529
-                2->{
530
-                    val studentno = it.studentno
531
-                    launchIntent.putExtra("authData",studentno.toString())
532
-                }
533
-                3->{
534
-                    val userphone = it.userphone
535
-                    launchIntent.putExtra("authData",userphone.toString())
536
-                }
537
-                4->{
538
-                    val cardid = it.cardid
539
-                    launchIntent.putExtra("authData",cardid.toString())
540
-                }
541
-                else->{
523
+            launchIntent.putExtra("authType",autoAppBean.authType)
524
+            userBean?.let {
525
+                when(autoAppBean.authType){
526
+                    1->{
527
+                        val userid = it.userid
528
+                        launchIntent.putExtra("authData",userid.toString())
529
+                    }
530
+                    2->{
531
+                        val studentno = it.studentno
532
+                        launchIntent.putExtra("authData",studentno.toString())
533
+                    }
534
+                    3->{
535
+                        val userphone = it.userphone
536
+                        launchIntent.putExtra("authData",userphone.toString())
537
+                    }
538
+                    4->{
539
+                        val cardid = it.cardid
540
+                        launchIntent.putExtra("authData",cardid.toString())
541
+                    }
542
+                    else->{
542 543
 
544
+                    }
543 545
                 }
544 546
             }
547
+            startActivity(launchIntent)
548
+        }catch (e:Exception){
549
+            canClickFlag=true
550
+            LogShow("跳转问题是$e")
545 551
         }
546
-        startActivity(launchIntent)
552
+
547 553
     }
548 554
     private fun showSucessToast() {
549 555
         Toaster.show(R.string.updatetips)

+ 12
- 0
corelib/src/main/java/com/xhly/corelib/utils/AppUtils.java View File

@@ -2,6 +2,7 @@ package com.xhly.corelib.utils;
2 2
 
3 3
 import static com.xhly.corelib.utils.BaseUtilsKt.LogShow;
4 4
 
5
+import android.app.Activity;
5 6
 import android.content.ComponentName;
6 7
 import android.content.Context;
7 8
 import android.content.Intent;
@@ -69,4 +70,15 @@ public class AppUtils {
69 70
             return false;
70 71
         }
71 72
     }
73
+
74
+    public static boolean isActivityExist(Context context, Class<?> cls){
75
+       try{
76
+           PackageManager packageManager = context.getPackageManager();
77
+           Intent intent = new Intent(context, cls);
78
+           ResolveInfo resolveInfo = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
79
+           return resolveInfo != null;
80
+       }catch (Exception e){
81
+           return false;
82
+       }
83
+    }
72 84
 }

Loading…
Cancel
Save