标签: ucrop

java.io.FileNotFoundException 打开失败:ENOENT(没有这样的文件或目录)

我有一个临时文件,用于从裁剪库创建图像,我可以在设备文件资源管理器中看到该文件,但当我尝试打开该文件时,出现此错误:

java.io.FileNotFoundException:文件:/data/user/0/com.example.demo/cache/.tmp/cropped1651879842159823361.png:打开失败:ENOENT(没有这样的文件或目录)

该文件的创建方式如下:

val croppedImageFile = File.createTempFile("cropped", ".png", viewModel.tempPath)
val destinationUri = Uri.fromFile(croppedImageFile)
Run Code Online (Sandbox Code Playgroud)

viewModel.tempPath 如下:

viewModel.tempPath = "${this.cacheDir}/.tmp"
Run Code Online (Sandbox Code Playgroud)

我可以看到该文件已创建并且有效,但是当我尝试访问它时,它声称它不存在。我只是通过执行以下操作打开文件File(uri.toString())。在视图模型中

我不确定出了什么问题以及为什么找不到该文件。如果这很重要,我使用的是带有 google play 的模拟器,并且是 Android 11。

android kotlin android-fileprovider ucrop

8
推荐指数
1
解决办法
2万
查看次数

来自片段的 UCrop 没有发送 requestCode

我正在尝试从片段中使用 Ucrop。我面临的问题是 onActivityresult 没有收到,requestCode == UCrop.REQUEST_CROP因此没有执行我需要对图像执行的操作。我四处寻找教程,但我没有找到任何教程。

以下是使用 UCrop 的片段代码:

public class FragmentSettingsTabImage extends Fragment {
private String TAG = "----->";
Tools t;
private String currentPhotoPath;
private final int REQUEST_TAKE_PHOTO = 1;
private final int CAMERA_PERMISSIONS = 2;
private ImageView imgTabImageDriver;
private Button btnSettingsSaveImage;

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == CAMERA_PERMISSIONS) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // All good so launch take picture from here …
Run Code Online (Sandbox Code Playgroud)

android ucrop

5
推荐指数
1
解决办法
972
查看次数

添加新库时出现错误"程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior"

当我尝试向项目添加新库然后运行我的应用程序时,我收到此错误:

程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior

以下是我想添加的库

  1. implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
  2. implementation 'com.github.yalantis:ucrop:2.2.2'

这是我的应用级gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.techxee.adarsh.chatbeta"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    //For firebase UI
    implementation 'com.firebaseui:firebase-ui-database:3.1.3'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    //For bottom …
Run Code Online (Sandbox Code Playgroud)

android gradle ucrop

3
推荐指数
1
解决办法
1万
查看次数

Ucrop onActivityMethod 不起作用

我使用了 ucrop 库中的以下代码,并且显示了裁剪窗口。

 Uri destinationUri = Uri.fromFile(new File(myContext.getCacheDir(), "IMG_" + System.currentTimeMillis()));
            UCrop.of(sourceUri, destinationUri)
                     .withMaxResultSize(maxWidth, maxHeight)
                    .start(myContext);
Run Code Online (Sandbox Code Playgroud)

但是,控制不会进入 onActivityResult 方法。如果/否则都不起作用。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
        final Uri resultUri = UCrop.getOutput(data);
    } else if (resultCode == UCrop.RESULT_ERROR) {
        final Throwable cropError = UCrop.getError(data);
    }
}
Run Code Online (Sandbox Code Playgroud)

知道出了什么问题,我错过了什么吗?

android onactivityresult ucrop

1
推荐指数
1
解决办法
1338
查看次数