首页 > 移动平台 > 详细

Android - 判断intent-filter的特定的action

时间:2015-01-13 10:39:04      阅读:242      评论:0      收藏:0      [点我收藏+]

判断intent-filter的特定的action


本文地址:http://blog.csdn.net/caroline_wendy


如果使用startIntent()启动Activity时,如果intent-filter中未包含此action,则会异常崩溃;
在使用时,可以先进行检查:
    // 判断是否安装【健康工具】
    private boolean isInstallChunyuTools() {

        Intent cardioFaceIntent = new Intent(EtonConstants.CHUNYU_CARDIO_FACE_ACTION);
        Intent pedometerIntent = new Intent(EtonConstants.CHUNYU_PEDOMETER_ACTION);

        PackageManager pm = getPackageManager();

        List<ResolveInfo> cardioFaceInfos =
                pm.queryIntentActivities(cardioFaceIntent, PackageManager.GET_RESOLVED_FILTER);
        List<ResolveInfo> pedometerInfos =
                pm.queryIntentActivities(pedometerIntent, PackageManager.GET_RESOLVED_FILTER);

        return cardioFaceInfos.isEmpty() || pedometerInfos.isEmpty();
    }



heck out queryIntentActivities()
So you create an intent with the correct filter matching discriminators on it.
Intent intent = new Intent("my_awesome.package.hasa.custom.ACTION!");
intent.addCategory("typingisfunfunfun");
intent.setData(Uri.parse("data://foo/bar"));
PackageManager pm = getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
if(resolveInfo.isEmpty()) {
  Log.i("NoneResolved", "No Activities");
} else {
  Log.i("Resolved!", "There are activities" + resolveInfos);
}





Android - 判断intent-filter的特定的action

原文:http://blog.csdn.net/caroline_wendy/article/details/42671939

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!