ギャラリーから写真を撮りたい、私はこのコードを使用しています。
ギャラリーから写真を撮る
コードはsumsung s4
デバイスの一部の写真で動作しますが、sumsung a7
では機能しません。
すべてのデバイスで動作するコードを作成します。
public class SignUpPersonalUserStep5 extends Fragment {
public SignUpPersonalUserStep5(PersonalProfil profil) {
this.profil = profil;
}
PersonalProfil profil;
public static final int RESULT_LOAD_PHOTO = 3;
ImageView signUpPhoto;
String ImageDecodableString;
FloatingActionButton button;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.step5_sign_up, container, false);
signUpPhoto = (ImageView) view.findViewById(R.id.signUpPhoto);
signUpPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_PHOTO);
}
});
button = (FloatingActionButton) view.findViewById(R.id.step5Button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager manager = getActivity().getSupportFragmentManager();
SignUpPersonalUserStep4 signUpStep4 = new SignUpPersonalUserStep4(profil);
FragmentTransaction transaction = manager.beginTransaction();
transaction.addToBackStack("");
transaction.setCustomAnimations(R.anim.toastox_sheet_show, R.anim.toastox_sheet_hide);
transaction.replace(R.id.signUpForFragment, signUpStep4);
transaction.commit();
}
});
return view;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_PHOTO && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// Get the cursor
Cursor cursor = getActivity().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
ImageDecodableString = cursor.getString(columnIndex);
cursor.close();
Log.d("nizar",ImageDecodableString);
signUpPhoto.setImageBitmap(BitmapFactory
.decodeFile(ImageDecodableString));
// ImageDecodableString = Base64.encodeToString(ImageDecodableString.getBytes(), Base64.DEFAULT);
profil.setImage(ImageDecodableString);
}
} catch (Exception e) {
Toast.makeText(getActivity(), "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}}
データは空ではありません。
あなたの考えを教えてください
ありがとうございました!
Android OSのバージョン:ユーザーはまた、彼らがインストールされている可能性のあるギャラリーのアプリを使用できるようにするには? – Aryan
Androidバージョン6.0.1 –
下記の内容を確認してください。 – Aryan