Android Question under targetSdkVersion="26" camera-mode will not work...

VJNiega

Member
Licensed User
Hi,
we used the following setting in Manifest in the past:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>

After changing to <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
on Android Version 7.0 and higher the camera-mode function did not work...
"Audio Recording", we get running by granting rights to the microphone... But camera, we have no idea..!?

Error : "Camera is not available"... (see below)
The Code where the error is triggered:

B4X:
    Sub TakePicture
    Dim i As Intent
    i.Initialize("android.media.action.IMAGE_CAPTURE", "")
    Dim uri As Uri
    File.Delete(imageFolder, tempImageFile)
    uri.Parse("file://" & File.Combine(imageFolder, tempImageFile))
    i.PutExtra("output", uri) 'the image will be saved to this path
    Try
    StartActivityForResult(i)
    Catch
    ToastMessageShow("Camera is not available.", True)
    Log(LastException) '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    End Try
    End Sub

In earlier android versions same Code work fine (example android 4.2.2) with the new targetSdkVersion="26" setting...

In the moment we have to change to the old setting "19" and Camera work fine...
Question, any idea to get camera working or should we let setting "19" for the next future???
regards
Rainer
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

VJNiega

Member
Licensed User
Error when debugging...

B4X:
Sub StartActivityForResult(i As Intent)
   Dim jo As JavaObject = GetBA
   ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
   jo.RunMethod("startActivityForResult", Array As Object(ion, i))   '!!!!  Error with this command  !!!!!!!!!!!!!
End Sub

java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.MPTMobile_eG.main._takepicture(main.java:2289)
at b4a.MPTMobile_eG.main._button1_click(main.java:2281)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5675)
at android.view.View$PerformClick.run(View.java:22641)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/b4a.MPTMobile_eG/files/tempimage.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1814)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8914)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8899)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
at android.app.Activity.startActivityForResult(Activity.java:4226)
at android.app.Activity.startActivityForResult(Activity.java:4185)
at anywheresoftware.b4a.BA.startActivityForResult(BA.java:542)
... 30 more


@Erel, thanks, I will have a look at your link...
but be aware of the fact, that it works fine without the manifest android:targetSdkVersion="26"

:))))
 
Upvote 0

VJNiega

Member
Licensed User
Hi Erel,
thank's, I get camera running using your codes...
For those who have the same problem, I had Problems with the use of the ImageFolder changing it to "Starter.provider.SharedFolder" solved my problems...

But now a new Problem made me desperate... Can you perhapps help???

When installing our app first time (android:targetSdkVersion="26"), we have to get rights for "microphone" and "storage"!!!
Using older android versions it is possible to get the rights, when installing the app...

When using android:targetSdkVersion="26" on android 7.0, I don't get the rights for "microphone" and "storage"...
After installing app, I need to open systemsettings/apps/myapp and have to grant explicit rights under app-permissions..
After that, updates will keep the permissions and every thing work fine...

How can I get rid of this behavior on installation? Is it an manifest-problem?
What can we do? ... to say the system, that we need to get the necessary rights on first time installation?
Isn't it easier to use targetSdkVersion="19" and forget "26"? ;)o_O
 
Upvote 0

VJNiega

Member
Licensed User
"The nice thing about runtime permissions is.... " What is the nice thing??? :(

I have in the moment no plan, what I can do to get the Microphone-Permission enabled...

I get Error:
audiorecord_btnstartrecording_click (java line: 144)
java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
at android.media.AudioRecord.startRecording(AudioRecord.java:982)
when code "streamer.StartRecording" is starting...

I use "Private streamer As AudioStreamer"

I understand reading Your docs, that I should use RuntimePermissions instead of Manifest-Permissions?
In Manifest I tried to use "AddPermission(android.permission.RECORD_AUDIO)" but it's no effect...
And I don't know at all, if "android.permission.RECORD_AUDIO" is my problem... The only thing I know is, that when I set manually after first time installation the App-Permission for Microphone under setting/apps/Myapp/Permissions to true, the Recording works fine..

Dave had in the past the same problem and wrote "Once I added the runtime permissions (a couple lines of code), everything worked fine in my app." But what couple of lines he used, he did not wrote (as an example)??
https://www.b4x.com/android/forum/threads/solved-audiostreamer-and-not-initialized-exceptions.98191/

I think, it could be a little problem, but guys excuse me, I'm confused, I have no idea anymore....:confused:
 
Upvote 0
Top