原文:https://blog.csdn.net/u010207898/article/details/73888311
// 做跳转到谷歌play做好评的业务逻辑
//这里开始执行一个应用市场跳转逻辑,默认this为Context上下文对象
var intent: Intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("market://details?id=" + 你的应用包名) //跳转到应用市场,非Google Play市场一般情况也实现了这个接口
//存在手机里没安装应用市场的情况,跳转会包异常,做一个接收判断
if (intent.resolveActivity(applicationContext!!.packageManager) != null) { //可以接收
startActivity(intent)
} else { //没有应用市场,我们通过浏览器跳转到Google Play
intent.data = Uri.parse("https://play.google.com/store/apps/details?id=" + 你的应用包名)
//这里存在一个极端情况就是有些用户浏览器也没有,再判断一次
if (intent.resolveActivity(applicationContext!!.packageManager) != null) { //有浏览器
startActivity(intent);
} else {
ToaskmmutUtils.toastShort("Fail")
}
}
//上面的有bug ,在没有谷歌市场时会跳转到自带的应用市场,下面这个准确些
/**
* 跳转google play
*/
public static void openGooglePlay(Context context) {
String playPackage = "com.android.vending";
try {
String currentPackageName = context.getPackageName();
if (currentPackageName != null) {
Uri currentPackageUri = Uri.parse("market://details?id="+context.getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, currentPackageUri);
intent.setPackage(playPackage);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
Uri currentPackageUri = Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, currentPackageUri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
本文详细介绍了如何从Android应用内部跳转至Google Play进行应用评价的实现方法,包括使用Intent进行市场跳转的代码示例及异常处理,确保用户无论是否安装Google Play都能顺利进行评价。

6005

被折叠的 条评论
为什么被折叠?



