I have this code to select a photo from gallery, copy the photo to dirdefaultexternal and shows the photo in imageview.
It works in some devices:
- tablet Samsung TabS (Android 6.0.1)
- Galaxy S2 Mini (Android 4.2.2)
but don't works in this devices:
- Moto G4 (Android 6.0.1)
- Galaxy S4 Mini (Android 7.1 CyanogenMod)
What am I missing?
Thanks in advance for any tips.
It works in some devices:
- tablet Samsung TabS (Android 6.0.1)
- Galaxy S2 Mini (Android 4.2.2)
but don't works in this devices:
- Moto G4 (Android 6.0.1)
- Galaxy S4 Mini (Android 7.1 CyanogenMod)
What am I missing?
Thanks in advance for any tips.
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
Private ImageView1 As ImageView
Dim bmp1 As Bitmap
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
'empty the imageview with a default image
Dim TargetDir As String
If File.ExternalWritable Then TargetDir = File.DirDefaultExternal Else TargetDir = File.DirInternal
File.Copy(File.DirAssets, "empty.jpg", TargetDir, "new.jpg")
End Sub
Sub Activity_Resume
'read the image copy from gallery after close the intent or use the default image
bmp1.Initialize(File.DirDefaultExternal, "new.jpg")
ImageView1.Bitmap = bmp1
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ParseUri(FileName As String) As Object
Dim r As Reflector
Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(FileName), Array As String("java.lang.String"))
End Sub
Sub GetGallery(Directory As String, PictureName As String)
Dim i As Intent
i.Initialize(i.ACTION_PICK, "")
i.SetType("image/*")
i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName)))
i.PutExtra("crop", "true")
i.PutExtra("aspectX", 0)
i.PutExtra("aspectY", 0)
i.PutExtra("outputX", 400)
i.PutExtra("outputY", 400)
StartActivity(i)
End Sub
Sub Button1_Click
GetGallery(File.DirDefaultExternal, "new.jpg") 'select and copy image
End Sub