모바일 사진 라이브러리에 액세스하고 선택 후 사진을 업로드하는 응용 프로그램을 개발 중입니다. 응용 프로그램은 카메라로 찍은 사진을 제외한 모든 사진을 완벽하게로드합니다. 누군가 나를 도와 주려고합니까?사진 라이브러리에 액세스 - 안드로이드 응용 프로그램
MainActivity.java
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.ImageView;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class MainActivity extends ActionBarActivity {
ImageView img;
private Bitmap bitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView) findViewById(R.id.imageView);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
abrirFoto();
}
});
}
public void abrirFoto() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
InputStream stream = null;
if (requestCode == 1 && resultCode == RESULT_OK) {
try {
if (bitmap != null) {
bitmap.recycle();
}
stream = getContentResolver().openInputStream(data.getData());
bitmap = BitmapFactory.decodeStream(stream);
img.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (stream != null)
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#0B9AE2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/fotos1"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_weight = "1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Clique para acessar as fotos do celular"
android:id="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_weight = "1"/>
</RelativeLayout>
내 코드는 메모리에있는 이미지의 모바일 라이브러리에 액세스합니다. 내 질문은 내 휴대 전화에서 사진 라이브러리에 액세스 할 때 내가 선택한 모든 사진은 카메라로 찍은 사진을 제외하고 ImageView를 업데이트한다는 것입니다. 내 코드를 실행하면 완벽하게 이해할 수 있습니다. 고맙습니다. @Prem –