Camera Intent returning error

Asked

Viewed 21 times

1

Old phone : Samsung S4 ANDROID - 4.2.2 -- New phone : MOTO G4 - 6.0.1

My application was working until yesterday, I switched to a new phone today ,I do not know if you have something to see ,is returning an Internet camera error when taking a photo ...

       @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case Utility.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                if (userChoosenTask.equals("Tirar Foto"))
                    cameraIntent();
                else if (userChoosenTask.equals("Escolha uma foto da galeria"))
                    galleryIntent();
            } else {
                //code for deny
            }
            break;
    }
}

private void selectImage() {
    final CharSequence[] items = {"Tirar Foto", "Escolha uma foto da galeria",
            "Cancelar"};

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle("Adicione uma foto ");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            boolean result = Utility.checkPermission(MainActivity.this);

            if (items[item].equals("Tirar Foto")) {
                userChoosenTask = "Tirar Foto";
                if (result)
                    cameraIntent();

            } else if (items[item].equals("Escolha uma foto da galeria")) {
                userChoosenTask = "Escolha uma foto da galeria";
                if (result)
                    galleryIntent();

            } else if (items[item].equals("Cancelar")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}


private void galleryIntent() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);//
    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);



}

private void cameraIntent() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, REQUEST_CAMERA);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == SELECT_FILE)
            onSelectFromGalleryResult(data);
        else if (requestCode == REQUEST_CAMERA)
            onCaptureImageResult(data);
    }
}

public void onCaptureImageResult(Intent data) {
    Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.PNG, 1, bytes);
    byte[] b = bytes.toByteArray();
    String encodedfile = Base64.encodeToString(b, Base64.DEFAULT);


    base64p = encodedfile;


    System.out.println(base64p);


    File destination = new File(Environment.getExternalStorageDirectory(),
            System.currentTimeMillis() + ".jpg");

    FileOutputStream fo;
    try {
        destination.createNewFile();
        fo = new FileOutputStream(destination);
        fo.write(bytes.toByteArray());
        fo.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    ivImage.setImageBitmap(thumbnail);
}


@SuppressWarnings("deprecation")
private void onSelectFromGalleryResult(Intent data) {

    Bitmap bm = null;
    if (data != null) {
        try {
            bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());





        } catch (IOException e) {


            e.printStackTrace();
        }
    }

    ivImage.setImageBitmap(bm);
}
}

LOGCAT returns these errors :

Exception dispatching input event.
exception in MessageQueue callback: handleReceiveCallback
va.lang.SecurityException: Permission Denial: starting Intent {   
act=android.media.action.IMAGE_CAPTURE cmp=
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at  
android.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2731)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1574)
at android.app.Activity.startActivityForResult(Activity.java:3934 
at FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3894)
at Activity_addinf.cameraIntent(Activity_addinf.java:567)
at.myapplication.Activity_addinf.access$3500(Activity_addinf.java:68)
at.com.Activity_addinf$4.onClick(Activity_addinf.java:555)
at.AlertController$AlertParams$3.onItemClick(AlertController.java:1108)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)

Manifest :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thiago.myapplication">

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="25" />


<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
  • Edit the question and put the Android versions of each Smartphone. This makes the problem better, and enables a more concrete answer.

  • Editing done ..

  • Almost sure is permissions problem. Put the full error log.

  • 1

    @ramaral so I asked to give details of the version. I also imagined that it would be this. = D

  • I put the logcat and the manifest

  • Thank you for your attention :)

  • 1

    It is confirmed that it is lack of permission see the answer indicated in the closing.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.