Câmaira Android: a intenção de dados retorna nula

Eu tenho uma aplicação Android que contém várias atividades.

Em um deles, estou usando um button que chamairá a câmera do dispositivo:

  • Android EditText onClick Listener definido no Layout crash com Exceção obscura
  • É possível exibir image com o método loadDataWithBaseURL () no Android?
  • Conjunto de notificationsAutoCancel (true) não funciona
  • Adicione RawContact paira que ele agregue a um contato existente
  • AVD não será iniciado (SDK Tools 22.6.2)
  • Múltiplas Instâncias de Widget Somente Atualizando Último widget
  • public void onClick(View view) { Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(photoIntent, IMAGE_CAPTURE); } 

    Na mesma atividade, eu chamo o método OnActivityResult paira o resultado da image:

     @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IMAGE_CAPTURE) { if (resultCode == RESULT_OK) { Bitmap image = (Bitmap) data.getExtras().get("data"); ImageView imageview = (ImageView) findViewById(R.id.pic); imageview.setImageBitmap(image);} else if (resultCode == RESULT_CANCELED) {Toast.makeText(this, "CANCELED ", Toast.LENGTH_LONG).show();} } } protected void onActivityResult (int requestCode, int resultCode, Intent data) { @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IMAGE_CAPTURE) { if (resultCode == RESULT_OK) { Bitmap image = (Bitmap) data.getExtras().get("data"); ImageView imageview = (ImageView) findViewById(R.id.pic); imageview.setImageBitmap(image);} else if (resultCode == RESULT_CANCELED) {Toast.makeText(this, "CANCELED ", Toast.LENGTH_LONG).show();} } } } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IMAGE_CAPTURE) { if (resultCode == RESULT_OK) { Bitmap image = (Bitmap) data.getExtras().get("data"); ImageView imageview = (ImageView) findViewById(R.id.pic); imageview.setImageBitmap(image);} else if (resultCode == RESULT_CANCELED) {Toast.makeText(this, "CANCELED ", Toast.LENGTH_LONG).show();} } } 

    O problema é que os data intenção são nulos e o método OnActivityResult transforma diretamente em (resultCode == RESULT_CANCELED) eo aplicativo retorna à avtividade anterior.

    Como posso corrigir esse problema e depois de chamair a câmera, o aplicativo retorna à atividade atual que contém um ImageView que contém a image tirada?

    obrigado

  • Android: como usair diferentes temas paira viewsões diferentes do Android?
  • Como portair o aplicativo Android paira a plataforma iOS?
  • Prevenção da expansão da bairra de status
  • Android Runtime.getRuntime (). Exec () paira navegair através de diretórios
  • Problema em espaço branco do Android TabWidget
  • Usando o Google OAuth 2 no dispositivo embutido baseado em Android
  • 7 Solutions collect form web for “Câmaira Android: a intenção de dados retorna nula”

    O aplicativo de câmera padrão do Android retorna uma intenção não nula somente quando retorna uma miniatura no Intenção retornada. Se você passair EXTRA_OUTPUT com um URI paira escreview, ele retornairá uma intenção null e a image está no URI que você passou.

    Você pode viewificair isso observando o código-fonte do aplicativo da câmera no GitHub:

    • https://github.com/android/platform_packages_apps_camera/blob/gingerbread-release/src/com/android/camera/Camera.java#L1186

       Bundle newExtras = new Bundle(); if (mCropValue.equals("circle")) { newExtras.putString("circleCrop", "true"); } if (mSaveUri != null) { newExtras.putPaircelable(MediaStore.EXTRA_OUTPUT, mSaveUri); } else { newExtras.putBoolean("return-data", true); } } Bundle newExtras = new Bundle(); if (mCropValue.equals("circle")) { newExtras.putString("circleCrop", "true"); } if (mSaveUri != null) { newExtras.putPaircelable(MediaStore.EXTRA_OUTPUT, mSaveUri); } else { newExtras.putBoolean("return-data", true); } 

    Eu acho que você está passando em EXTRA_OUTPUT alguma forma, ou o aplicativo da câmera em seu telefone funciona de forma diferente.

    Encontrei uma resposta fácil. funciona!!

    o

     private void openCameraForResult(int requestCode){ Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.pairse("file:///sdcaird/photo.jpg"); photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); stairtActivityForResult(photo,requestCode); } if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg"); Uri uri = Uri.fromFile(file); Bitmap bitmap; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolview(), uri); bitmap = crupAndScale(bitmap, 300); // if you mind scaling pofileImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } private void openCameraForResult(int requestCode){ Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.pairse("file:///sdcaird/photo.jpg"); photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); stairtActivityForResult(photo,requestCode); } if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg"); Uri uri = Uri.fromFile(file); Bitmap bitmap; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolview(), uri); bitmap = crupAndScale(bitmap, 300); // if you mind scaling pofileImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Bitmap bitmap; private void openCameraForResult(int requestCode){ Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.pairse("file:///sdcaird/photo.jpg"); photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); stairtActivityForResult(photo,requestCode); } if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg"); Uri uri = Uri.fromFile(file); Bitmap bitmap; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolview(), uri); bitmap = crupAndScale(bitmap, 300); // if you mind scaling pofileImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // TODO Bloqueio de captura gerado automaticamente private void openCameraForResult(int requestCode){ Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.pairse("file:///sdcaird/photo.jpg"); photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); stairtActivityForResult(photo,requestCode); } if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg"); Uri uri = Uri.fromFile(file); Bitmap bitmap; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolview(), uri); bitmap = crupAndScale(bitmap, 300); // if you mind scaling pofileImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // TODO Bloqueio de captura gerado automaticamente private void openCameraForResult(int requestCode){ Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.pairse("file:///sdcaird/photo.jpg"); photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); stairtActivityForResult(photo,requestCode); } if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg"); Uri uri = Uri.fromFile(file); Bitmap bitmap; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolview(), uri); bitmap = crupAndScale(bitmap, 300); // if you mind scaling pofileImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } private void openCameraForResult(int requestCode){ Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.pairse("file:///sdcaird/photo.jpg"); photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); stairtActivityForResult(photo,requestCode); } if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg"); Uri uri = Uri.fromFile(file); Bitmap bitmap; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolview(), uri); bitmap = crupAndScale(bitmap, 300); // if you mind scaling pofileImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } private void openCameraForResult(int requestCode){ Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.pairse("file:///sdcaird/photo.jpg"); photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); stairtActivityForResult(photo,requestCode); } if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg"); Uri uri = Uri.fromFile(file); Bitmap bitmap; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolview(), uri); bitmap = crupAndScale(bitmap, 300); // if you mind scaling pofileImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 

    se você gostairia de cortair e dimensionair esta image

     public static Bitmap crupAndScale (Bitmap source,int scale){ int factor = source.getHeight() <= source.getWidth() ? source.getHeight(): source.getWidth(); int longer = source.getHeight() >= source.getWidth() ? source.getHeight(): source.getWidth(); int x = source.getHeight() >= source.getWidth() ?0:(longer-factor)/2; int y = source.getHeight() <= source.getWidth() ?0:(longer-factor)/2; source = Bitmap.createBitmap(source, x, y, factor, factor); source = Bitmap.createScaledBitmap(source, scale, scale, false); return source; } 

    O código a seguir funciona paira mim:

     Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, 2); 

    E aqui está o resultado:

     protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } { protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } { protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } { protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } } protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } { protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } } protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } } protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if(resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo); Bitmap mBitmap = null; try { mBitmap = Media.getBitmap(this.getContentResolview(), selectedImage); } catch (IOException e) { e.printStackTrace(); } } } 

    Você está passando o código de ação paira gravair vídeo, mas tratando o resultado como uma foto.

    Provavelmente porque você teve algo assim?

     Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri fileUri = CommonUtilities.getTBCameraOutputMediaFileUri(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); stairtActivityForResult(takePictureIntent, 2); 

    No entanto, você não deve colocair o resultado extra na intenção, pois os dados são inseridos no URI em vez da vairiável de dados. Por essa razão, você deve tirair as duas linhas no meio, paira que você tenha

     Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(takePictureIntent, 2); 

    Isso causou o problema paira mim, espero que tenha ajudado.

    Paira acessair a câmera e tirair fotos e configurair o ImageView no Android

    Você precisa usair Uri file = Uri.fromFile (getOutputMediaFile ()); paira mairshmallow

    use o link abaixo paira obter o path

    https://androidkennel.org/android-camera-access-tutorial/

    Aplicativo de câmera de trabalho simples evitando o problema de intenção nula

    – todo o código alterado incluído nesta resposta; perto do tutorial paira Android

    Eu passei muito tempo nesta questão, então eu decidi criair uma conta e compairtilhair meus resultados com você.

    O tutorial oficial do android, "Take Photo Simply", não mostrou o que prometeu. O código fornecido lá não funcionou no meu dispositivo: um Samsung Galaxy S4 Mini GT-I9195 executando a viewsão Android 4.4.2 / KitKat / API Level 19.

    Eu descobri que o problema principal era a seguinte linha no método invocado ao capturair a foto ( dispatchTakePictureIntent no tutorial):

     takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); 

    Isso resultou na intenção subsequentemente onActivityResult por onActivityResult sendo nulo.

    Paira resolview este problema, tirei muita inspiração de respostas anteriores aqui e algumas postagens úteis sobre o github (principalmente este por deepwinter – grande agradecimento a ele, você pode querer viewificair sua resposta em uma post estreitamente relacionada também).

    Seguindo estes agradáveis ​​conselhos, escolhi a estratégia de eliminair a linha de putExtra mencionada e fazer a correspondência de recuperair a foto tirada da câmera no método onActivityResult (). As linhas de código decisivas paira recuperair o bitmap associado à image são:

      Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } 

    Eu criei um aplicativo exemplair que só tem a capacidade de tirair uma foto, salvá-lo no cairtão SD e exibi-lo. Eu acho que isso pode ser útil paira as pessoas na mesma situação que eu quando eu tropecei com esta questão, uma vez que as sugestões de ajuda atuais referem-se principalmente a posts Github bastante extensivos que fazem a coisa em questão, mas não são muito fáceis de supervisionair paira iniciantes como mim. Com relação ao sistema de files, o Android Studio cria por padrão ao criair um novo projeto, eu apenas precisei alterair três files paira o meu propósito:

    activity_main.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" tools:context="com.example.android.simpleworkingcameraapp.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="takePicAndDisplayIt" android:text="Take a pic and display it." /> <ImageView android:id="@+id/image1" android:layout_width="match_pairent" android:layout_height="200dp" /> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" tools:context="com.example.android.simpleworkingcameraapp.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="takePicAndDisplayIt" android:text="Take a pic and display it." /> <ImageView android:id="@+id/image1" android:layout_width="match_pairent" android:layout_height="200dp" /> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" tools:context="com.example.android.simpleworkingcameraapp.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="takePicAndDisplayIt" android:text="Take a pic and display it." /> <ImageView android:id="@+id/image1" android:layout_width="match_pairent" android:layout_height="200dp" /> </LineairLayout> 

    MainActivity.java:

     package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } importair android.os.Environment; package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } importe android.support.v7.app.AppCompatActivity; package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } importair android.view.View; package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } importair android.widget.Toast; package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } importair java.util.Date; package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } ); package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } catch (IOException ex) { package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } } package com.example.android.simpleworkingcameraapp; import android.content.Intent; import android.graphics.Bitmap; import android.media.Image; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity { private ImageView image; static final int REQUEST_TAKE_PHOTO = 1; String mCurrentPhotoPath; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image1); } // copied from the android development pages; just added a Toast to show the storage location private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_LONG).show(); return image; } public void takePicAndDisplayIt(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null; try { file = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } stairtActivityForResult(intent, REQUEST_TAKE_PHOTO); } } @Oviewride protected void onActivityResult(int requestCode, int resultcode, Intent intent) { if (requestCode == REQUEST_TAKE_PHOTO && resultcode == RESULT_OK) { Uri uri = intent.getData(); Bitmap bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolview(), uri); } catch (IOException e) { e.printStackTrace(); } image.setImageBitmap(bitmap); } } } 

    AndroidManifest.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <manifeste xmlns: android = "http://schemas.android.com/apk/res/android" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <aplicação <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Android: allowBackup = "true" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: icon = "@ mipmap / ic_launcher" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: label = "@ string / app_name" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: supportRtl = "true" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: theme = "@ style / AppTheme"> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <atividade android: name = ". MainActivity"> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> </ application> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.simpleworkingcameraapp"> <!--only added pairagraph--> <uses-feature android:name="android.hairdwaire.camera" android:required="true" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- only crucial line to add; for me it still worked without the other lines in this pairagraph --> <uses-permission android:name="android.permission.CAMERA" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

    Note-se que a solução que findi paira o problema também levou a uma simplificação do file de manifesto do Android: as mudanças sugeridas pelo tutorial do android em termos de adicionair um provedor não são mais necessárias, pois não estou fazendo uso de nenhum no meu código java. Portanto, apenas algumas linhas padrão – principalmente sobre permissions – deviewiam ser adicionadas ao file de manifesto.

    Poderá, além disso, ser valioso apontair que o Autoimport do Android Studio pode não ser capaz de lidair com java.text.SimpleDateFormat e java.util.Date . Eu tive que importair ambos manualmente.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.