HTTP Post a picture using share button.

arr0ba

Member
Licensed User
Longtime User
I'm trying to use the share button after taking a picture with camera to upload a picture to a web server that is hosting an asp page. The problem is that I cant seem to get the file name to the image created by the camera after the picture is taken. I am not using the Advanced Camera Library, I want to do this using the native camera app.

In java I was doing this like this
PHP:
 Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
                         String ImageFile = getRealPathFromURI(uri);
I am stuck here...
 

arr0ba

Member
Licensed User
Longtime User
Its the sharing intent fired when you hit the share button after you take the picture with the camera.

android.content.Intent.ACTION_SEND
 
Upvote 0

arr0ba

Member
Licensed User
Longtime User
The following code returns null every time...
B4X:
Sub Activity_Resume
ShareIntent = Activity.GetStartingIntent
ToastMessageShow(ShareIntent.Action,False)
   If ShareIntent.Action = "android.intent.action.SEND" Then
      Dim ShareString As String
      ShareString = ShareIntent.GetExtra("android.intent.extra.STREAM")
      ToastMessageShow("Share : " & ShareString, False)
   Else
      ToastMessageShow("No Share action!", False)
      Activity.Finish
   End If

End Sub
 
Last edited by a moderator:
Upvote 0

arr0ba

Member
Licensed User
Longtime User
ShareString = ShareIntent.GetExtra("android.intent.extra.STREAM")
ToastMessageShow("Share : " & ShareString, False)
 
Upvote 0

arr0ba

Member
Licensed User
Longtime User
I did that and Intent.HasExtra returns True, I also tried to Intent.ExtrasToString this returns a bundle with the value aswell. The problem that I'm having is getting Intent.GetExtra("android.intent.extra.STREAM" ) to return the value of the URI, Instead it always returns null I believe this might be a bug. Can I use reflector Library to get the value and if so how do I do this?
 
Upvote 0

arr0ba

Member
Licensed User
Longtime User
Starting: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) } from pid 353


Displayed android/com.android.internal.app.ChooserActivity: +595ms (total +13s218ms)


Starting: Intent { act=android.intent.action.SEND typ=image/jpeg flg=0x3000000 cmp=com.wrds.sendpodv1/.main (has extras) } from pid 353


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


** Activity (main) Resume **


GC_EXTERNAL_ALLOC freed 129K, 52% free 2668K/5447K, external 2135K/2137K, paused 40ms


Displayed com.wrds.sendpodv1/.main: +1s234ms


Key android.intent.extra.STREAM expected Serializable but value was a android.net.Uri$HierarchicalUri. The default value <null> was returned.


Attempt to cast generated internal exception:


java.lang.ClassCastException: android.net.Uri$HierarchicalUri
at android.os.Bundle.getSerializable(Bundle.java:1195)
at android.content.Intent.getSerializableExtra(Intent.java:3462)
at anywheresoftware.b4a.objects.IntentWrapper.GetExtra(IntentWrapper.java:104)
at com.wrds.sendpodv1.main._activity_resume(main.java:266)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at com.wrds.sendpodv1.main.afterFirstLayout(main.java:90)
at com.wrds.sendpodv1.main.access$100(main.java:16)
at com.wrds.sendpodv1.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406e4680


Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4077cc90
 
Upvote 0

arr0ba

Member
Licensed User
Longtime User
Thank you... the following code works...



Sub Activity_Resume

ShareIntent = Activity.GetStartingIntent
ToastMessageShow(ShareIntent.Action,False)
If ShareIntent.Action = "android.intent.action.SEND" Then
If ShareIntent.HasExtra("android.intent.extra.STREAM") = True Then
'Using reflector library since this does not work without it...
Dim r As Reflector
r.Target = ShareIntent 'the intent object

Dim ShareString As String
ShareString = r.RunMethod2("getParcelableExtra", "android.intent.extra.STREAM", "java.lang.String")

ToastMessageShow(GetPathFromContentResult(ShareString),True)
End If
Else
ToastMessageShow("No Share action!", False)
Activity.Finish
End If
End Sub
 
Upvote 0
Top