Jul 21, 2016 Replies: 48 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 CameraIntent.zip 9.5 KB · Views: 3,621 Last edited: Sep 19, 2021 Click to expand...
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.
Phayao Active Member Licensed User Longtime User Jul 21, 2016 #2 Hello, this is great, so no need to use a camera lib. Unfortunately i go the error : Error parsing program. Error description: Unknown type: runtimepermissions Are you missing a library reference? Occurred on line: 9 (Starter) Public rp As RuntimePermissions I did the changes in the manifest editor. Can it be that we need B4A v.6 (i have v.5.80) ? Thank you, Chris
Hello, this is great, so no need to use a camera lib. Unfortunately i go the error : Error parsing program. Error description: Unknown type: runtimepermissions Are you missing a library reference? Occurred on line: 9 (Starter) Public rp As RuntimePermissions I did the changes in the manifest editor. Can it be that we need B4A v.6 (i have v.5.80) ? Thank you, Chris
DonManfred Expert Licensed User Longtime User Jul 21, 2016 #4 Phayao said: Can it be that we need B4A v.6 (i have v.5.80) ? Click to expand... yes you need v6
Douglas Farias Expert Licensed User Longtime User Jul 21, 2016 #5 @Erel this code B4X: Expand Collapse Copy String mCurrentPhotoPath; private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = "file:" + image.getAbsolutePath(); return image; } its not important on this lib? like ezcamra lib and intent camera codes posted on forum, sometimes the camera ignore the extra output and save the image with another name, in the case of your example. B4X: Expand Collapse Copy Private const tempImageFile As String = "tempimage.jpg" will be ignored like posted here https://www.b4x.com/android/forum/t...ack-from-camera-app-intent.11378/#post-132956 and will be saved with random name file /mnt/sdcard/DCIM/Camera/2012-11-02 13.58.38.jpg (random file name!) using the code like google show "mCurrentPhotoPath" will fix this bug on some devices? here is a similar problem http://stackoverflow.com/questions/...them-with-a-custom-name-to-a-custom-destinati Converting the google code to b4a will result in this right? B4X: Expand Collapse Copy Private Sub GetFileName As String DateTime.TimeFormat = "yyyyMMdd_HHmmss" Private timestamps As String = DateTime.Time(DateTime.Now) Private imageFileName As String = "JPEG_" & timestamps & "_" &".jpg" Return imageFileName End Sub ps: I do not mean that the camera will not work, it will work ok, but in some cases it will save the image file with another name and not the name used in extra output thx Last edited: Jul 21, 2016
@Erel this code B4X: Expand Collapse Copy String mCurrentPhotoPath; private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = "file:" + image.getAbsolutePath(); return image; } its not important on this lib? like ezcamra lib and intent camera codes posted on forum, sometimes the camera ignore the extra output and save the image with another name, in the case of your example. B4X: Expand Collapse Copy Private const tempImageFile As String = "tempimage.jpg" will be ignored like posted here https://www.b4x.com/android/forum/t...ack-from-camera-app-intent.11378/#post-132956 and will be saved with random name file /mnt/sdcard/DCIM/Camera/2012-11-02 13.58.38.jpg (random file name!) using the code like google show "mCurrentPhotoPath" will fix this bug on some devices? here is a similar problem http://stackoverflow.com/questions/...them-with-a-custom-name-to-a-custom-destinati Converting the google code to b4a will result in this right? B4X: Expand Collapse Copy Private Sub GetFileName As String DateTime.TimeFormat = "yyyyMMdd_HHmmss" Private timestamps As String = DateTime.Time(DateTime.Now) Private imageFileName As String = "JPEG_" & timestamps & "_" &".jpg" Return imageFileName End Sub ps: I do not mean that the camera will not work, it will work ok, but in some cases it will save the image file with another name and not the name used in extra output thx
Erel B4X founder Staff member Licensed User Longtime User Jul 22, 2016 #6 The file name is not important and will not help with the issue of the camera app ignoring the "output" value.
The file name is not important and will not help with the issue of the camera app ignoring the "output" value.
cxdzbl Active Member Licensed User Aug 8, 2016 #7 Maven artifact not found: com.android.support/support-v4 Erel said: 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: Expand Collapse Copy AddManifestText( <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" /> ) Click to expand... The same question, how can I do, to explain the specific operation of the procedure? B4A version: 6.00 Parsing code. (0.00s) Compiling code. (0.08s) Compiling layouts code. (0.04s) Organizing libraries. Error Maven artifact not found: com.android.support/support-v4
Maven artifact not found: com.android.support/support-v4 Erel said: 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: Expand Collapse Copy AddManifestText( <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" /> ) Click to expand... The same question, how can I do, to explain the specific operation of the procedure? B4A version: 6.00 Parsing code. (0.00s) Compiling code. (0.08s) Compiling layouts code. (0.04s) Organizing libraries. Error Maven artifact not found: com.android.support/support-v4
Douglas Farias Expert Licensed User Longtime User Aug 8, 2016 #8 cxdzbl said: Maven artifact not found: com.android.support/support-v4 The same question, how can I do, to explain the specific operation of the procedure? B4A version: 6.00 Parsing code. (0.00s) Compiling code. (0.08s) Compiling layouts code. (0.04s) Organizing libraries. Error Maven artifact not found: com.android.support/support-v4 Click to expand... try put this jar on b4a libraries folder http://iddesenvolvimento.com.br/downloads/android-support-v4.jar and add this to your code B4X: Expand Collapse Copy #AdditionalJar: android-support-v4
cxdzbl said: Maven artifact not found: com.android.support/support-v4 The same question, how can I do, to explain the specific operation of the procedure? B4A version: 6.00 Parsing code. (0.00s) Compiling code. (0.08s) Compiling layouts code. (0.04s) Organizing libraries. Error Maven artifact not found: com.android.support/support-v4 Click to expand... try put this jar on b4a libraries folder http://iddesenvolvimento.com.br/downloads/android-support-v4.jar and add this to your code B4X: Expand Collapse Copy #AdditionalJar: android-support-v4
cxdzbl Active Member Licensed User Aug 8, 2016 #9 Douglas Farias said: try put this jar on b4a libraries folder http://iddesenvolvimento.com.br/downloads/android-support-v4.jar and add this to your code B4X: Expand Collapse Copy #AdditionalJar: android-support-v4 Click to expand... Still not, very strange?
Douglas Farias said: try put this jar on b4a libraries folder http://iddesenvolvimento.com.br/downloads/android-support-v4.jar and add this to your code B4X: Expand Collapse Copy #AdditionalJar: android-support-v4 Click to expand... Still not, very strange?
Douglas Farias Expert Licensed User Longtime User Aug 8, 2016 #10 cxdzbl said: Still not, very strange? View attachment 46801 View attachment 46802 View attachment 46803 View attachment 46804 Click to expand... https://www.b4x.com/android/forum/t...-android-gms-play-services-map.69551/#content
cxdzbl said: Still not, very strange? View attachment 46801 View attachment 46802 View attachment 46803 View attachment 46804 Click to expand... https://www.b4x.com/android/forum/t...-android-gms-play-services-map.69551/#content
cxdzbl Active Member Licensed User Aug 8, 2016 #11 Douglas Farias said: https://www.b4x.com/android/forum/t...-android-gms-play-services-map.69551/#content Click to expand... Thanks for your help. The problem is solved.
Douglas Farias said: https://www.b4x.com/android/forum/t...-android-gms-play-services-map.69551/#content Click to expand... Thanks for your help. The problem is solved.
freedom2000 Well-Known Member Licensed User Longtime User Sep 16, 2016 #12 HI, The example works fine (thank you) But is there a way to have the picture automatically taken, without having to click on the "button" ? Thanks
HI, The example works fine (thank you) But is there a way to have the picture automatically taken, without having to click on the "button" ? Thanks
Erel B4X founder Staff member Licensed User Longtime User Sep 18, 2016 #13 No. Use CameraEx for this.
freedom2000 Well-Known Member Licensed User Longtime User Sep 18, 2016 #14 Erel said: No. Use CameraEx for this. Click to expand... Ok thank you .
T TheArkhangel Member Licensed User Longtime User Sep 26, 2016 #15 Just say that I have tried the example directly into my B4A version 5.80 and it works perfectly, activates the camera and records the image. Erel take this opportunity to congratulate the great work that is being done with this tool that we use both. Greetings to all.
Just say that I have tried the example directly into my B4A version 5.80 and it works perfectly, activates the camera and records the image. Erel take this opportunity to congratulate the great work that is being done with this tool that we use both. Greetings to all.
T TheArkhangel Member Licensed User Longtime User Sep 27, 2016 #16 One question about it, I try to use the example to mixed with ftp send file...... the path of photo and the name who variable used to include at the ftp command ? FTP.UploadFile(File.DirRootExternal, file, False, "/remotepath/", file) B4X: Expand Collapse Copy 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 Thanks
One question about it, I try to use the example to mixed with ftp send file...... the path of photo and the name who variable used to include at the ftp command ? FTP.UploadFile(File.DirRootExternal, file, False, "/remotepath/", file) B4X: Expand Collapse Copy 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 Thanks
Erel B4X founder Staff member Licensed User Longtime User Sep 27, 2016 #17 The image is only available inside ion_Event. The safest way is to save lastPicture to a temporary file and then upload it. https://www.b4x.com/android/help/drawing.html#bitmap_writetostream
The image is only available inside ion_Event. The safest way is to save lastPicture to a temporary file and then upload it. https://www.b4x.com/android/help/drawing.html#bitmap_writetostream
T TheArkhangel Member Licensed User Longtime User Oct 9, 2016 #18 Whats the best metod to delete de image take for camera device, the image available inside the ion_Event..... ? Last edited: Oct 9, 2016
Whats the best metod to delete de image take for camera device, the image available inside the ion_Event..... ?
Erel B4X founder Staff member Licensed User Longtime User Oct 9, 2016 #19 B4X: Expand Collapse Copy Sub ion_Event (MethodName As String, Args() As Object) As Object If Args(0) = -1 Then Try Dim in As Intent = Args(1) If File.Exists(imageFolder, tempImageFile) Then lastPicture = LoadBitmapSample(imageFolder, tempImageFile, ImageView1.Width, ImageView1.Height) ImageView1.Bitmap = lastPicture File.Delete(imageFolder, tempImageFile) '<----------------------- Else If in.HasExtra("data") Then 'try to get thumbnail instead Dim jo As JavaObject = in lastPicture = jo.RunMethodJO("getExtras", Null).RunMethod("get", Array("data")) End If Catch Log(LastException) End Try End If If lastPicture.IsInitialized Then ImageView1.Bitmap = lastPicture Return Null End Sub
B4X: Expand Collapse Copy Sub ion_Event (MethodName As String, Args() As Object) As Object If Args(0) = -1 Then Try Dim in As Intent = Args(1) If File.Exists(imageFolder, tempImageFile) Then lastPicture = LoadBitmapSample(imageFolder, tempImageFile, ImageView1.Width, ImageView1.Height) ImageView1.Bitmap = lastPicture File.Delete(imageFolder, tempImageFile) '<----------------------- Else If in.HasExtra("data") Then 'try to get thumbnail instead Dim jo As JavaObject = in lastPicture = jo.RunMethodJO("getExtras", Null).RunMethod("get", Array("data")) End If Catch Log(LastException) End Try End If If lastPicture.IsInitialized Then ImageView1.Bitmap = lastPicture Return Null End Sub
A Antonio Eduardo New Member Licensed User Oct 14, 2016 #20 Douglas Farias said: try put this jar on b4a libraries folder http://iddesenvolvimento.com.br/downloads/android-support-v4.jar and add this to your code B4X: Expand Collapse Copy #AdditionalJar: android-support-v4 Click to expand... Estou Tentando instalar a câmera, conforme o seu post porém está dando o mesmo erro do versão 4
Douglas Farias said: try put this jar on b4a libraries folder http://iddesenvolvimento.com.br/downloads/android-support-v4.jar and add this to your code B4X: Expand Collapse Copy #AdditionalJar: android-support-v4 Click to expand... Estou Tentando instalar a câmera, conforme o seu post porém está dando o mesmo erro do versão 4