(打开应用)的按钮修复
This commit is contained in:
		| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Sat May 03 03:51:17 GMT 2025 | ||||
| #Sat May 03 05:20:15 GMT 2025 | ||||
| stageCount=1 | ||||
| libraryProject= | ||||
| baseVersion=15.2 | ||||
| publishVersion=15.2.0 | ||||
| buildCount=59 | ||||
| buildCount=65 | ||||
| baseBetaVersion=15.2.1 | ||||
|   | ||||
| @@ -20,6 +20,7 @@ import cc.winboll.studio.autoinstaller.models.APKModel; | ||||
| import cc.winboll.studio.autoinstaller.models.AppConfigs; | ||||
| import cc.winboll.studio.autoinstaller.services.MainService; | ||||
| import cc.winboll.studio.autoinstaller.utils.NotificationUtil; | ||||
| import cc.winboll.studio.autoinstaller.utils.PackageUtil; | ||||
| import cc.winboll.studio.autoinstaller.views.ListViewForScrollView; | ||||
| import cc.winboll.studio.libappbase.LogUtils; | ||||
| import cc.winboll.studio.libappbase.LogView; | ||||
| @@ -142,7 +143,7 @@ public class MainActivity extends Activity { | ||||
|         } | ||||
|         return ""; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public void onOpenAPP(View view) { | ||||
|         String szInstalledPackageName = getLastApkPackageName(); | ||||
|         if (szInstalledPackageName.trim().equals("")) { | ||||
| @@ -150,18 +151,28 @@ public class MainActivity extends Activity { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         Intent intent = getPackageManager().getLaunchIntentForPackage(mszInstalledPackageName); | ||||
|         if (intent != null) { | ||||
|             //ToastUtils.show("startActivity"); | ||||
|             startActivity(intent); | ||||
|         } else { | ||||
|             // 若没能获取到启动意图,可进行相应提示等操作,比如跳转到应用商店让用户下载该应用(示例) | ||||
|             Intent marketIntent = new Intent(Intent.ACTION_VIEW); | ||||
|             marketIntent.setData(Uri.parse("market://details?id=" + mszInstalledPackageName)); | ||||
|             startActivity(marketIntent); | ||||
|         } | ||||
|         PackageUtil.openAPP(this, szInstalledPackageName); | ||||
|     } | ||||
|  | ||||
| //    public void onOpenAPP(View view) { | ||||
| //        String szInstalledPackageName = getLastApkPackageName(); | ||||
| //        if (szInstalledPackageName.trim().equals("")) { | ||||
| //            ToastUtils.show("Installed APP package name is null."); | ||||
| //            return; | ||||
| //        } | ||||
| // | ||||
| //        Intent intent = getPackageManager().getLaunchIntentForPackage(mszInstalledPackageName); | ||||
| //        if (intent != null) { | ||||
| //            //ToastUtils.show("startActivity"); | ||||
| //            startActivity(intent); | ||||
| //        } else { | ||||
| //            // 若没能获取到启动意图,可进行相应提示等操作,比如跳转到应用商店让用户下载该应用(示例) | ||||
| //            Intent marketIntent = new Intent(Intent.ACTION_VIEW); | ||||
| //            marketIntent.setData(Uri.parse("market://details?id=" + mszInstalledPackageName)); | ||||
| //            startActivity(marketIntent); | ||||
| //        } | ||||
| //    } | ||||
|  | ||||
|     public void onInstallAPK(View view) { | ||||
|         installAPK(); | ||||
|     } | ||||
|   | ||||
| @@ -6,8 +6,10 @@ package cc.winboll.studio.autoinstaller.utils; | ||||
|  * @Describe 一个获取安卓APK安装文件的应用包名的函数 | ||||
|  */ | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.pm.PackageInfo; | ||||
| import android.content.pm.PackageManager; | ||||
| import android.content.pm.ResolveInfo; | ||||
| import cc.winboll.studio.libappbase.LogUtils; | ||||
|  | ||||
| public class PackageUtil { | ||||
| @@ -27,4 +29,18 @@ public class PackageUtil { | ||||
|         } | ||||
|         return ""; | ||||
|     } | ||||
|  | ||||
|     public static void openAPP(Context context, String packageName) { | ||||
|         // 这里假设要打开微信,微信的包名是com.tencent.mm | ||||
|         //String packageName = "com.tencent.mm";  | ||||
|         PackageManager packageManager = context.getPackageManager(); | ||||
|         Intent intent = packageManager.getLaunchIntentForPackage(packageName); | ||||
|         if (intent != null) { | ||||
|             ResolveInfo resolveInfo = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); | ||||
|             if (resolveInfo != null) { | ||||
|                 context.startActivity(intent); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ZhanGSKen
					ZhanGSKen