Android凌空上传图片 [英] Android volley to upload image
问题描述
我遵循了本教程将图像上传到我的服务器.但是,一旦我单击图库中的其中一张图片,它就会关闭我的应用程序.我有两个按钮,一个在用户选择后浏览,另一个在上载. 要浏览,我这样做:
I followed this tutorial to upload image to my server. But it closes my app once I click on one of the pictures in my gallery. I have two buttons one to browse and the other to upload once the user made their selection. To browse I do:
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
要获得结果,我将其覆盖:
And to get the results I override:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri filePath = data.getData();
try {
//Getting the Bitmap from Gallery
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
//Setting the Bitmap to ImageView
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
LogCat错误
01-06 17:32:02.937 24999-24999/? D/dalvikvm: Late-enabling CheckJNI
01-06 17:32:03.148 24999-24999/com.mypackage I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018_msm8226_LNX.LA.3.5.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.24.00.08
Build Date: 03/07/14 Fri
Local Branch:
Remote Branch: quic/LNX.LA.3.5.1_RB1.1
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018 + f2fd134 + NOTHING
01-06 17:32:03.176 24999-24999/com.mypackage D/OpenGLRenderer: Enabling debug mode 0
01-06 17:32:21.603 24999-24999/com.mypackage W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
推荐答案
我解决了.我有
android:noHistory="true"
在进行登录工作时的同一活动中,后来又改变了主意,想彻底改变我的体系结构,却忘记删除该行或将其设置为假.因此,当我从图库中获得结果时,活动便从堆栈中消失了.现在,我删除了所有内容,就像应该的一样.
on the same activity when I was doing login stuff and later on I changed my mind and wanted to change my architecture completely and forgot to delete that line or make it false; hence when I had the result from the gallery the activity was gone from the stack. Now I deleted it everything is like it's supposed to.
这篇关于Android凌空上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!