我是android应用程序开发的新手。我和我的团队正在创建一个应用程序,它使用图片库文件夹来上传照片。该应用程序可以拍摄照片,并立即上传照片。但特别是在三星设备上,当我试图从相机文件夹上传照片时,应用程序要么崩溃,要么上传一个白色页面。当我尝试从图库中选择一个不同的文件夹,而不是相机文件夹时,效果也很好。只有在相机文件夹中才会出现此错误。我在不同的nexus设备上测试了我的应用程序,它工作得非常完美。我在任何地方和任何地方都在寻找这个。我在Android Studio上写了所有的代码,还有Java和XML。有没有人有同样的问题并且能够解决?我真的需要一个指导。感谢您的时间和关注。
下面是我的Java onGalleryClick方法:
public void onGalleryClick(View v) {
isCameraReleased = true;
//TODO
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}发布于 2015-05-23 04:02:04
我想我已经通过实现毕加索图书馆解决了这个问题。最后,我可以访问相机文件夹(一些设备,它是DCIM),当我进入画廊选项。我相信三星设备的虚拟内存非常低,而且不知何故,它不允许你在自己创建的安卓应用程序上看到imageView。基本上,我在android studio上创建了一个非常简单的按钮,叫做activity_main.xml。这就是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ImageView>
<Button
android:id="@+id/buttonLoadPicture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0"
android:onClick="loadImagefromGallery"
android:text="Load Picture" >
</Button>
</LinearLayout>之后,我创建了提供所有功能的MainActivity.java。这就是:
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity {
private static int RESULT_LOAD_IMG = 1;
String imgDecodableString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void loadImagefromGallery(View view) {
// Create intent to Open Image applications like Gallery, Google Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
ImageView imgView = (ImageView) findViewById(R.id.imgView);
// Set the Image in ImageView after decoding the String
imgView.setImageBitmap(BitmapFactory
.decodeFile(imgDecodableString));
} else {
Toast.makeText(this, "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
}这是您必须在AndroidManifest文件中添加的代码行:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>这是所有事情中最棘手的部分。在你的build.gradle(模块:应用)中,你将在依赖部分添加编译'com.squareup.picasso:picasso:2.3.3‘。
在你需要添加
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Picasso.with(this)
.load("https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg")
.into(imageView);这就对了!请看http://code.tutsplus.com/tutorials/android-sdk-working-with-picasso--cms-22149
https://stackoverflow.com/questions/30382836
复制相似问题