首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获取android设备使用的裁剪包名称

如何获取android设备使用的裁剪包名称
EN

Stack Overflow用户
提问于 2013-11-23 13:27:35
回答 1查看 498关注 0票数 0

Intent cropIntent = new Intent("com.android.camera.action.CROP", null);包:"com.android.camera.action“并不是在所有的安卓设备(如Nexus7)中都可用。.Is没有任何代码来获取该安卓设备使用的”裁剪包“的名称。

EN

回答 1

Stack Overflow用户

发布于 2013-11-23 13:58:58

您检查过此Android 4.3 crop gallery resultCode Cancel

您有没有考虑过只使用这样的库:

https://github.com/biokys/cropimage

我发现com.android.camera.action.CROP有时会在不同的手机上表现不同,而且并不总是可用的,所以如果你想要发布它,它可能会给你带来一些问题。

更新:

我已经在Android4.3上测试了上面的库,没有任何问题。您只需将该库添加到您的项目中。

然后,您可以用非常类似的方式编写您的方法:

代码语言:javascript
复制
private void performCrop(Uri picUri) {
//you have to convert picUri to string and remove the "file://" to work as a path for this library
String path = picUri.toString().replaceAll("file://", "");

try {
    int aspectX = 750;
    int aspectY = 1011;

    Intent intent = new Intent(this, CropImage.class);
    //send the path to CropImage intent to get the photo you have just taken or selected from gallery
    intent.putExtra(CropImage.IMAGE_PATH, path);

    intent.putExtra(CropImage.SCALE, true);

    intent.putExtra("aspectX", aspectX);
    intent.putExtra("aspectY", aspectY);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCurrentPhotoPath)));

    startActivityForResult(intent, CROP);
}
catch (ActivityNotFoundException anfe) {
    String errorMessage = "Your device doesn't support the crop action!";
    Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
    toast.show();
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20158929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档