收索手机里面的packageName,与某个特定的包名+

时间:2021-10-26 17:40:48
/**
 * 手机里面应用程序信息的提供类
 * 
 * @author lijian-pc
 * @date 2016-6-17 上午11:29:09
 */
public class AppInfoProvider {
   public static final String LOTTERY_PACKAGENAME_PREFIX = "com.zykj.ksy";
   public static final String LOTTERY_PACKAGENAME_SUFFIX = "ppl";

   /**
    * 获取手机里面购彩app包名
    * 
    * @param context
    *            上下文
    * @return
    */
   public static String getLotteryAppPackageName(Context context) {
      PackageManager pm = context.getPackageManager();
      // 获取手机里面所有的apk包的信息,PackageInfo代表的就是每个应用程序的manifest.xml文件
      List<PackageInfo> packInfos = pm.getInstalledPackages(0);
      String lotteryPackageName = null;
      for (PackageInfo packInfo : packInfos) {
         String packName = packInfo.packageName;
         if (packName.startsWith(LOTTERY_PACKAGENAME_PREFIX)
               && packName.endsWith(LOTTERY_PACKAGENAME_SUFFIX)) {
            lotteryPackageName = packName;
            break;
         }
      }
      return lotteryPackageName;
   }
}