Android Tutorial Intent Based Camera

Newer example: [B4X] [B4XPages] Intent based camera

This example uses an intent to take a picture with the default camera app.

It is based on this tutorial: https://developer.android.com/training/camera/photobasics.html

It is simple to use and doesn't require any permission (*).

It does rely on the default camera app to work properly and save the image file in the path passed in the intent.
As a fallback, if the image was not saved it tries to get the thumbnail from the intent returned.

Don't miss the manifest editor code that is required for sharing file uris.
 

Attachments

  • CameraIntent.zip
    9.5 KB · Views: 1,686
Last edited:

uniplan

Active Member
Licensed User
Is possibile add an editbox into the form where are "OK" and "Cancel" buttons ?
 

iCAB

Well-Known Member
Licensed User
Hi Guys

This code triggers an exception when used from within a class module

B4X:
Sub GetBA As Object
   Dim jo As JavaObject
   Dim cls As String = Me
   cls = cls.SubString("class ".Length)
   jo.InitializeStatic(cls)
   Return jo.GetField("processBA")
End Sub

The same code works fine if moved to parent activity.

Is there a workaround?

Thanks in advance
 

yiankos1

Active Member
Licensed User
Good morning,
When i take photo and returns to main app, app starts at landscape and immediately changes to portrait. I want to use this at my app, but this behavior is not professional.
Thank you for your time.

p.s. tried on Galaxy S4
 

Pooya1

Active Member
Licensed User
Can i use this code in all android version without problem? (i would like make without any library for take picture from camera)
Problems like "cannot connect to camera","cannot save output" or any problem that it is dangerous
 

Marcos Alves

Well-Known Member
Licensed User
This example uses an intent to take a picture with the default camera app.

It is based on this tutorial: https://developer.android.com/training/camera/photobasics.html

It is simple to use and doesn't require any permission (*).

It does rely on the default camera app to work properly and save the image file in the path passed in the intent.
As a fallback, if the image was not saved it tries to get the thumbnail from the intent returned.

* - It uses RuntimePermissions.GetSafeDirDefaultExternal which means that you need to add the external storage permission to older versions of Android with this manifest code:
B4X:
AddManifestText(
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
)

Is there any way to receive video from camera also?
 

Filippo

Expert
Licensed User
Hi,

I have changed the example of Erel so that the photos can now be saved under the default order "../DCIM/Camera".
 

Attachments

  • CameraIntent.zip
    9.1 KB · Views: 327

winiha

Member
Licensed User
Hi,

I have changed the example of Erel so that the photos can now be saved under the default order "../DCIM/Camera".
it dose not work for me. (android 7.0)

how can change Erel's code such that taken picture directly save in File.DirRootExternal (for example, or in specific directory).
in the other word manifest be only write external storage and camera permission not default path.
 
Last edited:

Filippo

Expert
Licensed User
it dose not work for me. (android 7.0)

how can change Erel's code such that taken picture directly save in File.DirRootExternal.
in the other word manifest is only write external storage permission not default path.
You just have to change the "/DCIM/Camera" folder to your folder.
 
Top