luanhailiang

less is more

  • 首页
  • 微语
  • 留言
    • Android软件中实现跳转到应用商店进行评分

      package cn.gamesdk.unity3d;
      
      
      import java.util.ArrayList;
      import java.util.List;
      
      import android.content.Context;
      import android.content.Intent;
      import android.content.pm.ActivityInfo;
      import android.content.pm.PackageInfo;
      import android.content.pm.PackageManager;
      import android.content.pm.ResolveInfo;
      import android.net.Uri;
      import android.text.TextUtils;
      
      import com.ucube.chyogame.rbs.MainActivity;
      
      /**
       * Caige
       * 2015-11-1
       * 应用商店评分工具类
       */
      public class MarketUtils {
          /**
           * 获取已安装应用商店的包名列表
           *
           * @param context
           * @return
           */
          public static ArrayList<String> queryInstalledMarketPkgs(Context context) {
              ArrayList<String> pkgs = new ArrayList<String>();
              if (context == null)
                  return pkgs;
              Intent intent = new Intent();
              intent.setAction("android.intent.action.MAIN");
              intent.addCategory("android.intent.category.APP_MARKET");
              PackageManager pm = context.getPackageManager();
              List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
              if (infos == null || infos.size() == 0)
                  return pkgs;
              int size = infos.size();
              for (int i = 0; i < size; i++) {
                  String pkgName = "";
                  try {
                      ActivityInfo activityInfo = infos.get(i).activityInfo;
                      pkgName = activityInfo.packageName;
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  if (!TextUtils.isEmpty(pkgName))
                      pkgs.add(pkgName);
      
              }
              return pkgs;
          }
      
          /**
           * 过滤出已经安装的包名集合
           *
           * @param context
           * @param pkgs
           *            待过滤包名集合
           * @return 已安装的包名集合
           */
          public static ArrayList<String> filterInstalledPkgs(Context context,
                                                              ArrayList<String> pkgs) {
              ArrayList<String> empty = new ArrayList<String>();
              if (context == null || pkgs == null || pkgs.size() == 0)
                  return empty;
              PackageManager pm = context.getPackageManager();
              List<PackageInfo> installedPkgs = pm.getInstalledPackages(0);
              int li = installedPkgs.size();
              int lj = pkgs.size();
              for (int j = 0; j < lj; j++) {
                  for (int i = 0; i < li; i++) {
                      String installPkg = "";
                      String checkPkg = pkgs.get(j);
                      try {
                          installPkg = installedPkgs.get(i).applicationInfo.packageName;
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                      if (TextUtils.isEmpty(installPkg))
                          continue;
                      if (installPkg.equals(checkPkg)) {
                          empty.add(installPkg);
                          break;
                      }
      
                  }
              }
              return empty;
          }
      
          /**
           * 启动到app详情界面
           *
           * @param appPkg
           *            App的包名
           * @param marketPkg
           *            应用商店包名 ,如果为""则由系统弹出应用商店列表供用户选择,否则调转到目标市场的应用详情界面,某些应用商店可能会失败
           */
          public static void launchAppDetail(String appPkg, String marketPkg) {
              try {
                  if (TextUtils.isEmpty(appPkg))
                      return;
                  Uri uri = Uri.parse("market://details?id=" + appPkg);
                  Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                  if (!TextUtils.isEmpty(marketPkg))
                      intent.setPackage(marketPkg);
                  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  MainActivity.context.startActivity(intent);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      « spring boot data jpa 多数据源配置 | openssl生成公私钥对»

      日期:30 Nov 2015

      luanhailiang 0 843

      发表评论 取消回复

      你的邮件地址不会被公布;带*栏目为必填

    • 最新微语

      • 幸福就是找一个温暖的人过一辈子

        2014-05-21 00:02

      • 更多»

    • 日历

    • 存档

      • 2017年10月(1)
      • 2017年9月(1)
      • 2017年1月(1)
      • 2016年4月(4)
      • 2016年3月(1)
      • 2016年2月(1)
      • 2015年11月(2)
      • 2015年8月(1)
      • 2015年6月(5)
      • 2015年3月(1)
      • 2015年2月(1)
      • 2015年1月(2)
      • 2014年11月(1)
      • 2014年7月(7)
      • 2014年5月(1)
      • 2014年4月(7)
      • 2014年3月(1)
      • 2014年2月(1)
      • 2013年12月(3)
      • 2013年8月(4)
      • 2013年7月(19)
    • 分类

      • 笔记(36) 订阅该分类
      • 关注(5) 订阅该分类
    • 标签

        c python shell mysql lua perl go php ruby cpp rails java javascript css html linux mongodb jni nginx android google-play ios object-c redis activemq
    • 链接

      • github-luanhailiang
      • Stack Overflow
    • 最新评论

      • Kerry Beck
        I came across your C...
      • Kerry Beck
        I discovered your C/...
      • arham
        这篇文章中的最好的东西是作者的写作技巧,...
      • haoessays
        我读过这篇文章,并指出你必须遵循信息量。...
      • arham
        不错的文章
      • Ramona Jordan
        I came across your C...
      • Ramona Jordan
        I came across your C...
      • Rebecca Sutton
        I came to your C/C  ...
      • Rebecca Sutton
        This is a comment to...
      • Website Traffic
        This is a comment to...
Powered by emlog / Theme by SiyoChen / Made by Kuma 京ICP备13015133号-1 sitemap