Browse Source

1.打开应用时判断应用是否存在。

20241218TB223FC(测试jar包)
wangwanlei 8 months ago
parent
commit
f5c2832ca3

+ 10
- 1
app/src/main/java/com/xhly/manageapp/AppAdapter.kt View File

@@ -14,6 +14,7 @@ import com.xhkjedu.manageapp.databinding.ItemAppBinding
14 14
 import com.xhly.corelib.Const
15 15
 import com.xhly.corelib.bean.AppInfo
16 16
 import com.xhly.corelib.eventbus.UIEvent
17
+import com.xhly.corelib.utils.AppUtils
17 18
 import com.xhly.corelib.utils.LogShow
18 19
 import com.xhly.corelib.utils.SystemUtil
19 20
 import com.xhly.manageapp.utils.InstallUtils
@@ -66,6 +67,10 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
66 67
                 context.startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
67 68
             }else if (appInfo.packageName.equals(Const.STOREAPPPKG)){
68 69
                 //跳转应用商店
70
+                if (!AppUtils.isAppInstalled(context,appInfo.packageName)){
71
+                    Toaster.show("应用正在安装,请稍后。")
72
+                    return@setOnClickListener
73
+                }
69 74
                 var destroyFlag=false
70 75
                 try {
71 76
                     val launchIntent = Intent()
@@ -79,7 +84,7 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
79 84
                     destroyFlag=true
80 85
                 }catch (e:Exception){
81 86
                     destroyFlag=false
82
-                    Toaster.showLong("失败原因"+e.toString())
87
+                    LogShow("失败原因"+e.toString())
83 88
                 }finally {
84 89
                     if (destroyFlag){
85 90
                         DownLoadUtils.destroyDownLoad()
@@ -88,6 +93,10 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
88 93
                 }
89 94
             } else{
90 95
                 try {
96
+                    if (!AppUtils.isAppInstalled(context,appInfo.packageName)){
97
+                        Toaster.show("应用正在安装,请稍后。")
98
+                        return@setOnClickListener
99
+                    }
91 100
                     var instance = Calendar.getInstance()
92 101
                     instance.set(Calendar.HOUR_OF_DAY, 11)
93 102
                     instance.set(Calendar.MINUTE, 0)

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

@@ -56,4 +56,17 @@ public class AppUtils {
56 56
         }
57 57
         return list;
58 58
     }
59
+
60
+    /**
61
+     * 判断应用是否已经安装
62
+     */
63
+    public static boolean isAppInstalled(Context context, String packageName) {
64
+        try {
65
+            PackageManager pm = context.getPackageManager();
66
+            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
67
+            return true;
68
+        } catch (PackageManager.NameNotFoundException e) {
69
+            return false;
70
+        }
71
+    }
59 72
 }

Loading…
Cancel
Save