Android 应用商店评分+APP分享
转载自:Android Market链接的生成 调用Market 搜索软件 Android 调用已安装市场,进行软件评分的功能实现
参考:Android跳转到应用商店的APP详情页面,以及 Google GMS 各个apk的包
注:ionic-native还有这样的一个插件:Market 描述:Opens an app's page in the market place (Google Play, App Store) (我没去试过,估计也差不多的功能呱)
开发中,有时需要在应用中添加这样的功能:指引用户跳转到应用市场去评价应用,或者更新版本,或者下载作者开发或推荐的其他应用等Market链接功能。代码如下:
- Uri uri = Uri.parse("market://details?id=" + getPackageName());
- Intent intent = new Intent(Intent.ACTION_VIEW,uri);
- startActivity(intent);
从中可以看到,利用Uri对象和Intent实现即可!使用示例:
《一》通过packageName定位至Market对应App详情介绍页:
http://market.Android.com/details?id= your packageName
或者
market://details?id= your packageName
《二》通过packageName搜索App,获取得到的App列表:
http://market.android.com/search?q=pname:<Java包名>
或者
market://search?q=pname:<java包名>
《三》通过developer名称搜索App,获取得到的App列表:
http://market.android.com/search?q=pub:<开发者名称>
或者
market://search?q=pub:<开发者名称>
《四》通过关键词搜索App,获取得到的App列表:
http://market.android.com/search?q=<关键词>
或者
market://search?q=<关键词>
不过,这种方法将显示搜索到的标题(及内容?)中包含此关键词的所有App列表,需注意的是:这个是语言相关的,如果App中有对应于你机器的语言,那么你就要以这个语言搜才容易找到,搜索其他语言版本的名称应该是找不到该软件的,所以这种方法不推荐使用。
《五》综合搜索:
上述搜索相关的内容可以简单组合起来做更精确的筛选,不过通常情况下很少会用到。
例如:market://search?q=lucky wheel pub:xianfeng
http://developer.android.com/guide/publishing/publishing.html
- /**
- * market://search?q=pname:<package>
- */
- private void startSearchPNAMEIntent(){
- String pkgname;
- if(mEditText != null){
- pkgname = mEditText.getText().toString();
- }else{
- return;
- }
- Uri uri = Uri.parse("market://search?q=pname:"+pkgname);
- Intent it = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(it);
- }
- /**
- * market://search?q=pnames:<package>
- */
- private void startSearchPNAMESIntent(){
- String pkgnames;
- if(mEditText != null){
- pkgnames = mEditText.getText().toString();
- }else{
- return;
- }
- Uri uri = Uri.parse("market://search?q=pnames:"+pkgnames);
- Intent it = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(it);
- }
- /**
- * market://search?q=pub:Your Publisher Name
- */
- private void startSearchPUBIntent(){
- String pub;
- if(mEditText != null){
- pub = mEditText.getText().toString();
- }else{
- return;
- }
- Uri uri = Uri.parse("market://search?q=pub:"+pub);
- Intent it = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(it);
- }
- /**
- * market://details?id=<package_name>
- */
- private void startSearchIDIntent(){
- String id;
- if(mEditText != null){
- id = mEditText.getText().toString();
- }else{
- return;
- }
- Uri uri = Uri.parse("market://search?id="+id);
- Intent it = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(it);
- }
项目中要有一个给软件评分的功能,一个很常见,很简单的功能,却费了我不小功夫。需要实现的效果如下:
本来以为一般的软件都会有“去评分”、“亲,给个好评”这样的功能,但是在网上搜了搜竟没有搜到,问了三个群外加5个童鞋,分析log,反编译看源码,终于找到了这个uri,获取他真不容易啊。
- Uri uri = Uri.parse("market://details?id="+getPackageName());
- Intent intent = new Intent(Intent.ACTION_VIEW,uri);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
通过以上代码就能够列出您手机上所安装的所有应用市场(如:google player、豌豆荚、360手机助手等),让您选择。
加点福利吧,把调用分享的代码也贴出来,免得以后到处找:
- Intent sendIntent = new Intent();
- sendIntent.setAction(Intent.ACTION_SEND);
- sendIntent.setType("text/*");
- sendIntent.putExtra(Intent.EXTRA_TEXT, contentEditText.getText().toString());
- startActivity(sendIntent);
Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, 分享的内容); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(Intent.createChooser(intent, "分享"));