Getting image from Gallery

Tiwiz

Member
Licensed User
Longtime User
Hello everyone,
I was trying to start the Gallary to pick up a picture, can you help me understand what's wrong in my code?

B4X:
Dim in As Intent
   
   in.Initialize2(in.ACTION_PICK,0)
   in.SetType("image/*")
   in.WrapAsIntentChooser("Pick up a draft")
   StartActivity(in)

Thanks in advance.

Tiwiz
 

Tiwiz

Member
Licensed User
Longtime User
Tried but looks like nothing returns.

B4X:
Sub draft_click()
   Dim cc As ContentChooser
   
   'mostro la galleria
   cc.Initialize("CC")
   cc.Show("image/*","Pick a draft")
   
End Sub

Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
   Dim draft As String
   Dim mail As Email
   
   ToastMessageShow("Success: " & Success, False)
   If Success == True Then
      draft = File.Combine(Dir,FileName)
      mail.To.Add(address)
      mail.Subject = "Draft ICS"
      StartActivity(mail.GetIntent)
   End If   
End Sub

If I choose "Gallery" from the popup windows, even the Toast doesn't get to be shown... I need an image to attach to an email... but why I don't get anything in that routine?

Tiwiz
 
Upvote 0

Tiwiz

Member
Licensed User
Longtime User
It looks like it never reaches the edge...

B4X:
Sub draft_click()
   Dim cc As ContentChooser
   
   'mostro la galleria
   cc.Initialize("CC")
   cc.Show("image/*","Pick a draft")
   
End Sub

Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
   Dim draft As String
   Dim mail As Email
   
   Log("Success: " & Success)
   
   
End Sub

but never shows the LogCat message... :confused:

Tiwiz
 
Upvote 0

Tiwiz

Member
Licensed User
Longtime User
Yes, but if you try to pick up an image it doesn't return anything... it should return true, shouldn't it?

Tiwiz
 
Upvote 0

Tiwiz

Member
Licensed User
Longtime User
Many thanks, it worked, but now I have another problem :(

B4X:
Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
   Dim draft As String
   Dim mail As Email
   
   If File.Exists(Dir,FileName) Then
      ToastMessageShow("FOUND",True)
   Else
      ToastMessageShow("CAN'T FIND IT", False)
   End If
   
   
End Sub

Always shows "CAN'T FIND IT", could you help me manage that file? File.Copy crashes as well if I pass it Dir and FileName as source...

Tiwiz
 
Upvote 0

Tiwiz

Member
Licensed User
Longtime User
Here's the error:
B4X:
LogCat connected to: 0280414642bf21d7
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


running waiting messages (1)


main_cc_result (B4A line: 69)


File.Copy(Dir,FileName,File.DirInternal,FileName)



java.io.FileNotFoundException: /data/data/tiwiz.locale.test/files/content:/media/external/images/media/31 (No such file or directory)
   at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
   at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
   at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
   at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:344)
   at anywheresoftware.b4a.objects.streams.File.Copy(File.java:320)
   at tiwiz.locale.test.main._cc_result(main.java:314)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:89)
   at anywheresoftware.b4a.phone.Phone$ContentChooser$1.ResultArrived(Phone.java:829)
   at anywheresoftware.b4a.BA$2.run(BA.java:313)
   at anywheresoftware.b4a.BA.setActivityPaused(BA.java:263)
   at tiwiz.locale.test.main$ResumeMessage.run(main.java:190)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:130)
   at android.app.ActivityThread.main(ActivityThread.java:3835)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
   at dalvik.system.NativeStart.main(Native Method)
java.io.FileNotFoundException: /data/data/tiwiz.locale.test/files/content:/media/external/images/media/31 (No such file or directory)

Tiwiz
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Tested code on following devices :
Motorola defy android 2.36
LG optimus L5 android 4.0
Alview Viva i7 android 4.4

just a remark ..pay attention to the extention format .png ...do not change that while copy to dir.rootexternal
 
Upvote 0
Top