3
I’m developing an android app I have an event on the Button to open the camera:
On Androimanifest.xml
<!-- Permissão para acessar a área de memória externa -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Permissão para acessar a câmera diretamente -->
<uses-permission android:name="android.permission.CAMERA"/>
On Mainactivit I have an Imageview and an Imagebutton
<ImageView
android:id="@+id/imgv_imagem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@mipmap/ic_launcher" />
<ImageButton
android:id="@+id/ibtn_tirarfoto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:onClick="takePicture"
app:srcCompat="@android:drawable/ic_menu_camera" />
In Activity.java I have the method that triggered the Button onclick event
public void takePicture(View v) {
// Cria uma intent que será usada para abrir a aplicação nativa de câmera
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Indica na intent o local onde a foto tirada deve ser armazenada
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
// Abre a aplicação de câmera
startActivityForResult(i, REQUEST_PICTURE);
}
The startActivityForResult method call is opening an Illegalstateexception and gives the following message "Could not execute method for android:onClick"
The app is powered up after this. I apply the same code in another application and it works. Does anyone know what it can be?
Error log:
11-18 16:41:02.205 30551-30551/br.com.multiwaycursos.multiwayapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.multiwaycursos.multiwayapp, PID: 30551
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:5716)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22596)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
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:5716)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22596)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.sec.android.app.camera/.Camera } from ProcessRecord{c668b6b 30551:br.com.multiwaycursos.multiwayapp/u0a138} (pid=30551, uid=10138) with revoked permission android.permission.CAMERA
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3181)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1541)
at android.app.Activity.startActivityForResult(Activity.java:4298)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:4245)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:708)
at br.com.multiwaycursos.multiwayapp.actAutoCadastroCamera.TirarFoto(actAutoCadastroCamera.java:52)
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:5716)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22596)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
I am using a Navigation Drawer in this actvity, tried in another application that uses the Navigation Drawer and gave the same error. The Navigation Drawer Mainactivity class inherits from the Appcompatactivity class, unlike the others that inherit from the Activity class
– Rafael Christófano
What is the
targetSdkVersion
and the Android version of the device you’re testing?– ramaral
Hello ramaral, I use targetSdkVersion 26 on API 21. The project is at https://github.com/faelchristofano/MultiWayApp
– Rafael Christófano
This could be the problem of runtime permissions or because of changes to permissions that impact file sharing. Put the full bug log.
– ramaral
I put the error log
– Rafael Christófano