Эй, в настоящее время я работаю над живыми обоями, и я разрешаю пользователю выбирать изображение, которое пойдет за мои эффекты.
В настоящее время у меня есть:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.putExtra("crop", "true");
startActivityForResult(i, 1);
И немного под этим:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1)
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
Log.d("IMAGE SEL", "" + selectedImage);
// TODO Do something with the select image URI
SharedPreferences customSharedPreference = getSharedPreferences("imagePref", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference.edit();
Log.d("HO", "" + selectedImage);
editor.putString("imagePref", getRealPathFromURI(selectedImage));
Log.d("IMAGE SEL", getRealPathFromURI(selectedImage));
editor.commit();
}
}
Когда мой код запущен, Logcat сообщает мне, что selectedImage имеет значение null. Если я прокомментирую
i.putExtra("crop", "true"):
Logcat не дает мне исключение null-указателя, и я могу делать то, что хочу с изображением. Итак, в чем проблема? Кто-нибудь знает, как я могу это исправить? Спасибо, за ваше время.