该应用程序正常运行。将文件附加到imageview,然后将其发送到服务器。
现在,在选择图片(文件)后,应用程序会在imageview中显示它,所有方法都能正确运行到最后。
但应用程序会将我抛给上一个片段而日志中没有任何错误。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == Activity.RESULT_OK && requestCode == 100){
if(getPath(data.getData()) != null){
Uri fileUri = data.getData();
file = new File(getPath(fileUri));
String mimetype = getActivity().getContentResolver().getType(fileUri);
Log.d("mylog","name " + file.getName() + " type " + mimetype);
imageV.setVisibility(View.VISIBLE);
imageV.setImageResource(R.drawable.icons8highpriority96);
if(mimetype.equals("image/jpeg")){ imageV.setImageURI(fileUri);}
if(mimetype.equals("image/png")){ imageV.setImageURI(fileUri);}
if(mimetype.equals("application/pdf")){ imageV.setImageResource(R.drawable.icons8pdf80);}
if(mimetype.equals("text/html")){ imageV.setImageResource(R.drawable.icons8doc80);}
textFileName.setText(file.getName());
textFileName.setVisibility(View.VISIBLE);
}else {
imageV.setVisibility(View.VISIBLE);
textFileName.setVisibility(View.VISIBLE);
textFileName.setText("Выберите файл из определенного раздела! ");}
}
}
我附上了一些令我困惑的日志 -
447-705/system_process I/ActivityManager: START u0
{act=android.intent.action.GET_CONTENT typ=*/*
cmp=com.android.gallery/com.android.camera.ImageGallery} from pid
1382
201-304/? W/genymotion_audio: out_write() limiting sleep time 34149
to 23219
201-304/? W/genymotion_audio: out_write() limiting sleep time 45759
to 23219
201-304/? W/genymotion_audio: out_write() limiting sleep time 37369
to 23219
447-705/system_process D/dalvikvm: GC_FOR_ALLOC freed 616K, 27% free
6910K/9424K, paused 5ms, total 5ms
447-705/system_process D/dalvikvm: GC_FOR_ALLOC freed 755K, 31% free
6526K/9424K, paused 8ms, total 8ms
447-544/system_process D/MobileDataStateTracker: default:
setPolicyDataEnable(enabled=true)
201-304/? W/genymotion_audio: out_write() limiting sleep time 28979
to 23219
447-540/system_process I/qtaguid: Failed write_ctrl(s 1 10016)
res=-1
errno=1
447-540/system_process W/NetworkManagementSocketTagger:
setKernelCountSet(10016, 1) failed with errno -1
1448-1448/com.android.gallery D/dalvikvm: GC_FOR_ALLOC freed 662K,
27% free
3596K/4900K, paused 2ms, total 2ms
1448-1448/com.android.gallery D/dalvikvm: GC_FOR_ALLOC freed 527K,
28% free
3547K/4900K, paused 1ms, total 1ms
201-304/? W/genymotion_audio: out_write() limiting sleep time 31767
to 23219
1448-1448/com.android.gallery D/dalvikvm: GC_FOR_ALLOC freed 220K,
27% free
3613K/4900K, paused 1ms, total 1ms
447-544/system_process D/MobileDataStateTracker: default:
setPolicyDataEnable(enabled=true)
447-464/system_process I/ActivityManager: Displayed
com.android.gallery/com.android.camera.ImageGallery: +124ms
1448-1448/com.android.gallery D/dalvikvm: GC_FOR_ALLOC freed 103K,
21% free
3915K/4900K, paused 2ms, total 2ms
1448-1448/com.android.gallery D/dalvikvm: GC_FOR_ALLOC freed 265K,
16% free
4121K/4900K, paused 18ms, total 18ms
1448-1448/com.android.gallery D/dalvikvm: GC_FOR_ALLOC freed 586K,
24% free
3748K/4900K, paused 3ms, total 3ms
447-544/system_process D/MobileDataStateTracker: default:
setPolicyDataEnable(enabled=true)
447-544/system_process D/MobileDataStateTracker: default:
setPolicyDataEnable(enabled=true)
447-540/system_process I/qtaguid: Failed write_ctrl(s 0 10053)
res=-1
errno=1
447-540/system_process W/NetworkManagementSocketTagger:
setKernelCountSet(10053, 0) failed with errno -1
447-544/system_process D/MobileDataStateTracker: default:
447-539/system_process D/dalvikvm: GC_FOR_ALLOC freed 999K, 31% free
6545K/9424K, paused 4ms, total 5ms
447-544/system_process D/MobileDataStateTracker: default:
setPolicyDataEnable(enabled=true)
447-544/system_process D/MobileDataStateTracker: default:
setPolicyDataEnable(enabled=true)
201-304/? W/genymotion_audio: out_write() limiting sleep time 44149
to 23219
201-304/? W/genymotion_audio: out_write() limiting sleep time 55759
to 23219
447-447/system_process D/dalvikvm: GC_FOR_ALLOC freed 444K, 27% free
6903K/9424K, paused 6ms, total 6ms
447-447/system_process D/dalvikvm: GC_FOR_ALLOC freed 749K, 31% free
6525K/9424K, paused 5ms, total 5ms
447-544/system_process D/MobileDataStateTracker: default:
setPolicyDataEnable(enabled=true)
447-540/system_process I/qtaguid: Failed write_ctrl(s 1 10053)
res=-1
errno=1
447-540/system_process W/NetworkManagementSocketTagger:
setKernelCountSet(10053, 1) failed with errno -1
1382-1382/com.example.usersad.myapplication D/mylog: name
IMG_20180327_045230.jpg type image/jpeg
我将我的代码复制到一个新项目中并且它有效! 来自activi和fragment。 但在与画廊互动后的主要项目中,片段已关闭。
答案 0 :(得分:0)
使用{ email: 'somevalidemail@gmail.com',
password:
'$2b$10$oQN7i5AKYDyPLp.DefeRjuyh9Z7JLayPjTO4I3B6NvytM0vq2YnVG',
firstName: 'Cool',
lastName: 'Cat' }
和model PipeTest
Pipe_base3 pipe_base3_1(redeclare package Medium = Modelica.Media.Water.WaterIF97_R1pT)
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Modelica.Fluid.Sources.FixedBoundary boundary(
nPorts=1,
p=100000,
redeclare package Medium = Modelica.Media.Water.WaterIF97_R1pT)
annotation (Placement(transformation(extent={{-60,-40},{-40,-20}})));
Modelica.Fluid.Sources.FixedBoundary boundary1(
nPorts=1,
p=100000,
redeclare package Medium = Modelica.Media.Water.WaterIF97_R1pT)
annotation (Placement(transformation(extent={{60,-40},{40,-20}})));
Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedHeatFlow[2](Q_flow={0,0})
annotation (Placement(transformation(extent={{-40,20},{-20,40}})));
equation
connect(boundary.ports[1], pipe_base3_1.fluidin) annotation (Line(points={{-40,-30},{-8,-30},{-8,-9}}, color={0,127,255}));
connect(boundary1.ports[1], pipe_base3_1.fluidout) annotation (Line(points={{40,-30},{8,-30},{8,-9}}, color={0,127,255}));
connect(fixedHeatFlow.port, pipe_base3_1.heatport) annotation (Line(points={{-20,30},{0,30},{0,7}}, color={191,0,0}));
annotation (
Icon(coordinateSystem(preserveAspectRatio=false)),
Diagram(coordinateSystem(preserveAspectRatio=false)),
uses(Modelica(version="3.2.2")));
end PipeTest;
将代码写入onActivityResult
内并打印异常
答案 1 :(得分:0)
我建议你逐行调试你的代码,我觉得有些东西是空的。在不同的sdk中,获取Path(文件Uri)是不同的
答案 2 :(得分:0)
你可以遵循这个结构。用你的变量和方法替换变量和方法。希望它会对你有所帮助。请评论任何查询。
if (requestCode == SELECT_GALLERY && resultCode == RESULT_OK && null != data) {
try {
galleryopen = false;
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
Consts.img_Bitmap = null;
Consts.img_Bitmap = BitmapFactory.decodeFile(picturePath);
Intent intent = new Intent(MainActivity.this, CropActivity.class);
} catch (Exception e) {
e.printStackTrace();
}
} else if (requestCode == SELECT_CAMERA) {
try {
galleryopen = false;
Uri selectedImageUri = getImageUri();
String uri = selectedImageUri.toString();
Consts.img_Bitmap = null;
Consts.img_Bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
ExifInterface ei = new ExifInterface(selectedImageUri.getPath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
Consts.img_Bitmap = rotateImage(Consts.img_Bitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Consts.img_Bitmap = rotateImage(Consts.img_Bitmap, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
Consts.img_Bitmap = rotateImage(Consts.img_Bitmap, 270);
break;
default:
break;
}
Intent intent = new Intent(MainActivity.this, CropActivity.class);
startActivity(intent);
} catch (Exception e) {
galleryopen = false;
e.printStackTrace();
}
} else {
galleryopen = false;
Toast.makeText(MainActivity.this, "you have not selected any Image", Toast.LENGTH_SHORT).show();
}
答案 3 :(得分:0)
尝试编辑AndroidManifest.xml
如下所述
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tscolari.photo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".PhotoFilterActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
答案 4 :(得分:0)
我发现了我的错误。 该应用程序已关闭,因为我在主要活动的onStart方法中调用了另一个片段。