展会信息港展会大全

检测 Android 中的某个 Intent 是否有效
来源:互联网   发布日期:2016-01-14 09:17:15   浏览:2916次  

导读:[代码]java代码01/**02* Indicates whether the specified action can be used as an intent. This03* method queries the package manager for installed packages that can04* respond......

[代码] java代码

01

/**

02

* Indicates whether the specified action can be used as an intent. This

03

* method queries the package manager for installed packages that can

04

* respond to an intent with the specified action. If no suitable package is

05

* found, this method returns false.

06

*

07

* @param context The application's environment.

08

* @param action The Intent action to check for availability.

09

*

10

* @return True if an Intent with the specified action can be sent and

11

*responded to, false otherwise.

12

*/

13

public static boolean isIntentAvailable(Context context, String action) {

14

final PackageManager packageManager = context.getPackageManager();

15

final Intent intent = new Intent(action);

16

List<ResolveInfo> list =

17

packageManager.queryIntentActivities(intent,

18

PackageManager.MATCH_DEFAULT_ONLY);

19

return list.size() > 0;

20

}

赞助本站

人工智能实验室

相关热词: Intent 是否有效

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港