在android中设置默认的图像裁剪程序



在我的应用程序中,用户选择一个图像。启动CROP_IMAGE意图时,它会显示对话框,以选择设备上安装的可用图像裁剪器之一。我想解决的是,其中一个已安装的程序启动默认值,用户不必一直选择要使用的程序。

是否可以跳过这个选择器对话框并自动启动一个图像裁剪器?

我找到了答案:

Intent cropApps = new Intent("com.android.camera.action.CROP");
cropApps.setType("image/*");
List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(cropApps, 0);
int size = list.size();
if (size == 0) 
{           
    Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();    
} 
else 
{
    ResolveInfo res = list.get(0);
    Intent cropIntent = new Intent();
    cropIntent.setClassName(res.activityInfo.packageName, res.activityInfo.name);
    cropIntent.setDataAndType(picUri, "image/*");
    cropIntent.putExtra("outputX", 800);
    cropIntent.putExtra("outputY", 800);
    cropIntent.putExtra("aspectX", 1);
    cropIntent.putExtra("aspectY", 1);
    cropIntent.putExtra("scale", true);
    cropIntent.putExtra("return-data", true);
    startActivityForResult(cropIntent, PIC_CROP);
}

最新更新