从Intent Chooser中排除应用

时间:2015-05-25 14:54:37

标签: android

我正在使用意图选择器让用户决定使用哪个应用来从相机或图库中选择图像。问题是我的代码还显示了文件浏览器应用程序,如ES文件管理器或库存文件管理器。

演示截图: http://image.noelshack.com/fichiers/2015/22/1432565769-xmeedd.png

另外,我不知道我的代码的哪一部分列出了这两个文件浏览器。

那么有没有办法只保留#34;相机"这是库存相机应用程序," 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);
}

0 个答案:

没有答案