如何获取相机应用程序的包名称

RAA*_*AAM 3 android

感谢以前的回复,

是否可以获取设备上安装的摄像头应用程序的包名?如果自定义操作系统,则设备制造商会更改默认包名称.如何通过编码获取包名?我不确定这是可能的.

小智 10

你试过这个吗?

    PackageManager packman = getPackageManager();
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    String pack = intent.resolveActivity(packman).getPackageName();
Run Code Online (Sandbox Code Playgroud)


use*_*305 7

我不确定,但我认为您可以使用指定的意图获取应用程序的包名称.

查看此代码以获取处理特定意图的可用应用程序信息,

/**
 * Indicates whether the specified action can be used as an intent. This
 * method queries the package manager for installed packages that can
 * respond to an intent with the specified action. If no suitable package is
 * found, this method returns false.
 *
 * @param context The application's environment.
 * @param action The Intent action to check for availability.
 *
 * @return True if an Intent with the specified action can be sent and
 *         responded to, false otherwise.
 */
public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List list =
            packageManager.queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}
Run Code Online (Sandbox Code Playgroud)

现在使用Camera intent,您可以获取处理IMAGE_CAPTURE意图的应用程序信息,并使用该信息轻松获取包名称.

更新:

在您的情况下,具体意图是

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Run Code Online (Sandbox Code Playgroud)

编辑:

List<ResolveInfo> listCam = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo res : listCam) {
    Log.e("Camera Application Package Name and Activity Name",res.activityInfo.packageName + " " + res.activityInfo.name));
}
Run Code Online (Sandbox Code Playgroud)

试试这个让我知道发生了什么......