Commit c03ed23b by sikang

优化GP跳转逻辑

parent abaae597
......@@ -20,6 +20,7 @@ import com.tbruyelle.rxpermissions2.Permission;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import tech.starwin.LibConfig;
import tech.starwin.R;
......@@ -34,6 +35,7 @@ import tech.starwin.utils.ui_utils.DialogManager;
*/
public class ActivityJumper {
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 static int REQUEST_PERMISSION_CODE = 0x000AF00;
/**
......@@ -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) {
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;
}
}
//已安装GooglePlay直接打开,否则用浏览器访问App下载页
Uri uri = Uri.parse(GP_APP_DETAIL_URL + packageName);
if (AppInfoUtils.isPackageExist(context, GP_PACKAGE_NAME)) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW)
.setData(uri)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (AppInfoUtils.isPackageExist(context, GP_PACKAGE_NAME)) {
intent.setPackage(GP_PACKAGE_NAME);
}
context.startActivity(intent);
} catch (Exception e) {
DialogFactory.showMessageDialog(context, context.getString(R.string.show_download_on_google_player));
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(intent);
}
}
......
......@@ -56,6 +56,7 @@ public class AppInfoUtils {
return false;
}
@SuppressLint("MissingPermission")
public static String getPhoneNumber(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
......@@ -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