Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从意向选择器中排除应用程序_Android - Fatal编程技术网

Android 从意向选择器中排除应用程序

Android 从意向选择器中排除应用程序,android,Android,我正在使用一个意向选择器,让用户决定使用什么应用程序,以便从相机或画廊中选择图像。问题是,我下面的代码还显示了文件浏览器应用程序,如ES文件管理器或股票文件管理器 演示截图: 另外,我不知道我的代码中列出了这两个文件探索器的哪一部分 那么,有没有一种方法可以只保留股票相机应用程序Camera和股票画廊应用程序Galerie 对不起,英语不好 private void openImageIntent() { // Determine Uri of camera image to

我正在使用一个意向选择器,让用户决定使用什么应用程序,以便从相机或画廊中选择图像。问题是,我下面的代码还显示了文件浏览器应用程序,如ES文件管理器或股票文件管理器

演示截图:

另外,我不知道我的代码中列出了这两个文件探索器的哪一部分

那么,有没有一种方法可以只保留股票相机应用程序Camera和股票画廊应用程序Galerie

对不起,英语不好

 private void openImageIntent() {

      // Determine Uri of camera image to save.
    final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "TempDirectory" + File.separator);
    root.mkdirs();
    final String fname = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date())+".jpg";
    final File sdImageMainDirectory = new File(root, fname);
    outputFileUri = Uri.fromFile(sdImageMainDirectory);

    // Camera.
    // Is it this part that list the two unwanted file explorers ?
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for(ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }

    // Filesystem.
    // Is it this part that list the two unwanted file explorers ?
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
    galleryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));

    startActivityForResult(chooserIntent, CAMERA_PIC_REQUEST);
}

问题是,我下面的代码也显示了文件浏览器应用程序,如ES文件管理器或股票文件管理器-所以?也许用户想要使用这些应用程序或其他应用程序。那么,有没有一种方法可以只保留股票相机应用程序Camera和股票画廊应用程序Galerie没有单一库存照相机应用程序,也没有单一库存画廊应用程序。大约有15亿台安卓设备,跨越数千种型号,每种型号都可以有自己的股票应用程序。另外,用户可能希望使用第三方相机、多媒体资料或其他应用程序。@Commonware是的,我知道这不是一个用户友好的解决方案,但我希望确保所选文件是图像。使用第三方文件选择器(如ES)是不可能做到的,ES允许选择任何类型的文件。在这种情况下,我必须验证onActivityResult方法中的文件类型,这是实现它的好方法吗?但我想确保选择的文件是图像-不要求任何应用程序(包括stock camera应用程序和stock gallery应用程序)始终返回图像。这些应用程序是由程序员编写的,欢迎他们做任何他们想做的事情。在这种情况下,我必须验证onActivityResult方法中的文件类型,这是实现它的好方法吗是的,例如,使用BitmapFactory、BitmapFactory.Options和inJustDecodeBounds来查看结果是否解码为位图,或者调用ContentResolver上的getType来检查MIME类型,如果这不够充分。@Commonware感谢您的帮助、建议和您的书,我非常感谢。