Commit c03ed23b by sikang

优化GP跳转逻辑

parent abaae597
...@@ -20,6 +20,7 @@ import com.tbruyelle.rxpermissions2.Permission; ...@@ -20,6 +20,7 @@ import com.tbruyelle.rxpermissions2.Permission;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Map;
import tech.starwin.LibConfig; import tech.starwin.LibConfig;
import tech.starwin.R; import tech.starwin.R;
...@@ -34,6 +35,7 @@ import tech.starwin.utils.ui_utils.DialogManager; ...@@ -34,6 +35,7 @@ import tech.starwin.utils.ui_utils.DialogManager;
*/ */
public class ActivityJumper { public class ActivityJumper {
private static String GP_APP_DETAIL_URL = "https://play.google.com/store/apps/details?id="; private static String GP_APP_DETAIL_URL = "https://play.google.com/store/apps/details?id=";
private static String GP_PACKAGE_NAME = "com.android.vending";
private Intent intent; private Intent intent;
private static int REQUEST_PERMISSION_CODE = 0x000AF00; private static int REQUEST_PERMISSION_CODE = 0x000AF00;
/** /**
...@@ -164,23 +166,45 @@ public class ActivityJumper { ...@@ -164,23 +166,45 @@ public class ActivityJumper {
} }
// public static void startGooglePlay(Context context, String packageName) {
// try {
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(GP_APP_DETAIL_URL + packageName));
// List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0);
// if (resolveInfos != null && resolveInfos.size() > 0) {
// for (ResolveInfo resolveInfo : resolveInfos) {
// if (resolveInfo.activityInfo.packageName.toLowerCase().contains("com.android.vending")
// || resolveInfo.activityInfo.name.toLowerCase().contains("com.android.vending")
// || resolveInfo.activityInfo.processName.toLowerCase().contains("com.android.vending")) {
// intent.setPackage(resolveInfo.activityInfo.packageName);
// break;
// }
// }
// }
// context.startActivity(intent);
// } catch (Exception e) {
// DialogFactory.showMessageDialog(context, context.getString(R.string.show_download_on_google_player));
// }
// }
/**
* 打开Google Play下载页
*/
public static void startGooglePlay(Context context, String packageName) { public static void startGooglePlay(Context context, String packageName) {
try { //已安装GooglePlay直接打开,否则用浏览器访问App下载页
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(GP_APP_DETAIL_URL + packageName)); Uri uri = Uri.parse(GP_APP_DETAIL_URL + packageName);
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0); if (AppInfoUtils.isPackageExist(context, GP_PACKAGE_NAME)) {
if (resolveInfos != null && resolveInfos.size() > 0) { Intent intent = new Intent();
for (ResolveInfo resolveInfo : resolveInfos) { intent.setAction(Intent.ACTION_VIEW)
if (resolveInfo.activityInfo.packageName.toLowerCase().contains("com.android.vending") .setData(uri)
|| resolveInfo.activityInfo.name.toLowerCase().contains("com.android.vending") .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|| resolveInfo.activityInfo.processName.toLowerCase().contains("com.android.vending")) {
intent.setPackage(resolveInfo.activityInfo.packageName); if (AppInfoUtils.isPackageExist(context, GP_PACKAGE_NAME)) {
break; intent.setPackage(GP_PACKAGE_NAME);
}
}
} }
context.startActivity(intent); context.startActivity(intent);
} catch (Exception e) { } else {
DialogFactory.showMessageDialog(context, context.getString(R.string.show_download_on_google_player)); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(intent);
} }
} }
......
...@@ -56,6 +56,7 @@ public class AppInfoUtils { ...@@ -56,6 +56,7 @@ public class AppInfoUtils {
return false; return false;
} }
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
public static String getPhoneNumber(Context context) { public static String getPhoneNumber(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
...@@ -67,4 +68,6 @@ public class AppInfoUtils { ...@@ -67,4 +68,6 @@ public class AppInfoUtils {
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment