0

i am trying to take a picture and send the picture to the server, but at the moment i don't enter the onActivityResult and fon't figure out what is going on

here is the code:

public void capturar(View view){
        Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(intent,REQUEST_IMAGE_CAPTURE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            String encodedImage = encodeImage(imageBitmap);
            Log.d("encoded",encodedImage);
            sendImage(encodedImage);
        }
    }

i can take preview the camera but the click on the android photo doesn't hit the Log.d on the activiyt result, any tip»?

LogCat:

05-16 23:50:36.304 9940-9940/com.example.afcosta.inesctec.pt.android E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                       Process: com.example.afcosta.inesctec.pt.android, PID: 9940
                                                                                       java.lang.IllegalStateException: Could not execute method for android:onClick
                                                                                           at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                                           at android.view.View.performClick(View.java:5637)
                                                                                           at android.view.View$PerformClick.run(View.java:22429)
                                                                                           at android.os.Handler.handleCallback(Handler.java:751)
                                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                                        Caused by: java.lang.reflect.InvocationTargetException
                                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                                           at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                                                                                           at android.view.View.performClick(View.java:5637) 
                                                                                           at android.view.View$PerformClick.run(View.java:22429) 
                                                                                           at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                           at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                           at android.os.Looper.loop(Looper.java:154) 
                                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
                                                                                        Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.android.camera/.Camera } from ProcessRecord{631d205 9940:com.example.afcosta.inesctec.pt.android/u0a74} (pid=9940, uid=10074) with revoked permission android.permission.CAMERA
                                                                                           at android.os.Parcel.readException(Parcel.java:1684)
                                                                                           at android.os.Parcel.readException(Parcel.java:1637)
                                                                                           at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3101)
                                                                                           at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
                                                                                           at android.app.Activity.startActivityForResult(Activity.java:4225)
                                                                                           at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
                                                                                           at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
                                                                                           at android.app.Activity.startActivityForResult(Activity.java:4183)
                                                                                           at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
                                                                                           at com.example.afcosta.inesctec.pt.android.MainMenu.capturar(MainMenu.java:55)
                                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                                           at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
                                                                                           at android.view.View.performClick(View.java:5637) 
                                                                                           at android.view.View$PerformClick.run(View.java:22429) 
                                                                                           at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                           at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                           at android.os.Looper.loop(Looper.java:154) 
                                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119) 

1 Answers1

0

You're missing permissions in your manifest in order to access the camera hardware. Add:

<uses-feature android:name="android.hardware.camera" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.hardware.camera.autofocus" />
Luca Nicoletti
  • 2,265
  • 2
  • 18
  • 32
  • not working, i think i need to check my permissions on runtime see –  May 17 '17 at 15:25
  • http://stackoverflow.com/questions/32789027/android-m-camera-intent-permission-bug –  May 17 '17 at 15:25
  • Sure if you're targetting android M+. You did not specified which version, and by the way, you always need to put these in manifest, even if you're checking them at runtime – Luca Nicoletti May 17 '17 at 15:27