我已将手机更新至安卓nougat版本,但是剪裁功能突然不起作用了。在Marshmallow版本中,该功能运行得非常完美。
这是我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "multas.com.usj.multaszgz"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':tess-two-release')
compile files('libs/androidjhlabs.jar')
//Pestañas
compile files('libs/commons-codec-1.7.jar')
compile project(path: ':openCVLibrary310')
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
compile 'com.android.support:design:24.2.0'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.itextpdf:itextg:5.5.9'
compile 'org.codepond:wizardroid:1.3.1'
compile 'com.google.android.gms:play-services:9.4.0'
testCompile 'junit:junit:4.12'
}
以下是裁剪的代码:
private void crop(){
try {
Log.v("OCRActivity", "HA LLEGADO AL CROP: "+takeStoragePermissionGranted());
File file = new File(path);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(outputFileUri, "image/*");
intent.putExtra("crop", true);
//intent.putExtra("outputX",bm.getWidth());
//intent.putExtra("outputY", bm.getHeight());
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
Log.v("OCRActivity", "HA LLEGADO ");
startActivityForResult(intent, PIC_CROP);
}
catch(ActivityNotFoundException anfe){
//display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}catch(Exception e){
Log.e("OCRActivity", "crop():"+e.getMessage());
}
}
我在控制台中没有检测到任何错误,但在onActivityOnResult中返回的结果代码为0,而应该是1...
我不知道nougat发生了什么事情,使用marshmallow时相同的代码可以正常工作...
请问有什么解决方法吗?
CROP
Intent
。有许多可用于Android的图像裁剪库,请使用其中之一。 - CommonsWare