0
Manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera.any" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
Activity
public void TirarFoto(View view)
{
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent,1);
}
public void PegarImagem(View view)
{
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(intent, "Selecione uma imagem"), 12);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if(requestCode == 1) { //funciona
if (intent != null) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Bitmap bitmap = (Bitmap) bundle.get("data");
ImageView img = (ImageView) findViewById(R.id.imgFoto);
img.setImageBitmap(bitmap);
}
}
}
if(requestCode == 12)
{
if(resultCode == RESULT_OK)
{
Uri uri = intent.getData();
Cursor cursor = getContentResolver().query(uri, new String[]{MediaStore.Images.Media.DATA}, null, null, null);
cursor.moveToFirst();
int indexColuna = cursor.getColumnIndex(MediaStore.Images.Media.DATA); // aqui sempre vem 0
String path = cursor.getString(indexColuna);
cursor.close();
Bitmap bitmap = BitmapFactory.decodeFile(path);
ImageView img = (ImageView) findViewById(R.id.imgFoto);
img.setImageBitmap(bitmap);
}
}
}
The first time I did it would have worked but I don’t know what’s different about it that it doesn’t work now. Select image but not arrow in Imagemview.
I tried to set direct from Uri but gave file error not found.