yttrium Active Member Licensed User Longtime User Apr 12, 2013 #1 I've looked up how to receive content from an app when it wants to share something. This usually involves "Intent Filters". For my app, I want it to be able to accept pictures, and then launch the app and save the picture to memory when it's launched (via the share). How do I go about doing this? Explanations I've seen involve adding something resembling the following to my Manifest file: Code: Copy AddApplicationText( <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter>) My app doesn't show up in the stock Gallery's share function with this. How can I make it work, and how can I reference what to do when the app is launched this way? There's nice documentation on this for Android, but not for Basic4Android.
I've looked up how to receive content from an app when it wants to share something. This usually involves "Intent Filters". For my app, I want it to be able to accept pictures, and then launch the app and save the picture to memory when it's launched (via the share). How do I go about doing this? Explanations I've seen involve adding something resembling the following to my Manifest file: Code: Copy AddApplicationText( <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter>) My app doesn't show up in the stock Gallery's share function with this. How can I make it work, and how can I reference what to do when the app is launched this way? There's nice documentation on this for Android, but not for Basic4Android.
yttrium Active Member Licensed User Longtime User Apr 15, 2013 #21 thedesolatesoul said: As I said before you need to post what is returned by: Code: Copy Log(In.ExtrasToString) You cannot pass that directly to GetPathFromContentResult. Click to expand... Sorry, I figured that since the content chooser worked that the intent would as well. I'll get a printout for you in a little bit. Upvote 0
thedesolatesoul said: As I said before you need to post what is returned by: Code: Copy Log(In.ExtrasToString) You cannot pass that directly to GetPathFromContentResult. Click to expand... Sorry, I figured that since the content chooser worked that the intent would as well. I'll get a printout for you in a little bit.
yttrium Active Member Licensed User Longtime User Apr 15, 2013 #22 The printout of Msgbox(Log(In.ExtrasToString)) is: Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7859}] Obtained by using the share function on a screenshot in the AOSP4.1 Gallery app. Upvote 0
The printout of Msgbox(Log(In.ExtrasToString)) is: Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7859}] Obtained by using the share function on a screenshot in the AOSP4.1 Gallery app.
thedesolatesoul Expert Licensed User Longtime User Apr 15, 2013 #23 Okay, so now you get the value of Uri using: Code: Copy Dim UriString as String UriString = In.GetExtra("android.intent.extra.STREAM") ' Now UriString should contain a value similar to content://media/external/images/media/7859 'And now you can call the function to get the filepath Preview.SetBackgroundImage(LoadBitmap("", GetPathFromContentResult(UriString))) Upvote 0
Okay, so now you get the value of Uri using: Code: Copy Dim UriString as String UriString = In.GetExtra("android.intent.extra.STREAM") ' Now UriString should contain a value similar to content://media/external/images/media/7859 'And now you can call the function to get the filepath Preview.SetBackgroundImage(LoadBitmap("", GetPathFromContentResult(UriString)))
yttrium Active Member Licensed User Longtime User Apr 15, 2013 #24 I'm still getting these exceptions. Code: Copy Error occurred: An error has occured in sub: main_getpathfromcontentresult (java line: 415) java.lang.RuntimeException: Object should first be initialized (Cursor). Continue? Only difference is from line 408 to 415. Upvote 0
I'm still getting these exceptions. Code: Copy Error occurred: An error has occured in sub: main_getpathfromcontentresult (java line: 415) java.lang.RuntimeException: Object should first be initialized (Cursor). Continue? Only difference is from line 408 to 415.
Erel B4X founder Staff member Licensed User Longtime User Apr 15, 2013 #25 Try to open the Uri directly. Add a RingtoneManager object from the Phone library and call: Code: Copy LoadBitmap(Ringtone.GetContentDir, UriString) Upvote 0
Try to open the Uri directly. Add a RingtoneManager object from the Phone library and call: Code: Copy LoadBitmap(Ringtone.GetContentDir, UriString)
thedesolatesoul Expert Licensed User Longtime User Apr 15, 2013 #26 For some reason I cannot understand this code always returns null. Code: Copy Dim UriString as String UriString = In.GetExtra("android.intent.extra.STREAM") I worked around it, not very elegant, but it would work. Code: Copy Log(In.ExtrasToString) Dim MyUriString As String MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) Log(MyUriString) Activity.SetBackgroundImage (LoadBitmap("", GetPathFromContentResultString(MyUriString ))) Upvote 0
For some reason I cannot understand this code always returns null. Code: Copy Dim UriString as String UriString = In.GetExtra("android.intent.extra.STREAM") I worked around it, not very elegant, but it would work. Code: Copy Log(In.ExtrasToString) Dim MyUriString As String MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) Log(MyUriString) Activity.SetBackgroundImage (LoadBitmap("", GetPathFromContentResultString(MyUriString )))
yttrium Active Member Licensed User Longtime User Apr 15, 2013 #27 thedesolatesoul said: Try to do: To figure out what is sent back in return and which extra is which. Click to expand... thedesolatesoul said: For some reason I cannot understand this code always returns null. Code: Copy Dim UriString as String UriString = In.GetExtra("android.intent.extra.STREAM") I worked around it, not very elegant, but it would work. Code: Copy Log(In.ExtrasToString) Dim MyUriString As String MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) Log(MyUriString) Activity.SetBackgroundImage (LoadBitmap("", GetPathFromContentResultString(MyUriString ))) Click to expand... GetPathFromContentResultString isn't valid, do you mean GetPathFromContentResult? Upvote 0
thedesolatesoul said: Try to do: To figure out what is sent back in return and which extra is which. Click to expand... thedesolatesoul said: For some reason I cannot understand this code always returns null. Code: Copy Dim UriString as String UriString = In.GetExtra("android.intent.extra.STREAM") I worked around it, not very elegant, but it would work. Code: Copy Log(In.ExtrasToString) Dim MyUriString As String MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) Log(MyUriString) Activity.SetBackgroundImage (LoadBitmap("", GetPathFromContentResultString(MyUriString ))) Click to expand... GetPathFromContentResultString isn't valid, do you mean GetPathFromContentResult?
thedesolatesoul Expert Licensed User Longtime User Apr 15, 2013 #28 yttrium said: GetPathFromContentResultString isn't valid, do you mean GetPathFromContentResult? Click to expand... Yes. Upvote 0
yttrium said: GetPathFromContentResultString isn't valid, do you mean GetPathFromContentResult? Click to expand... Yes.
yttrium Active Member Licensed User Longtime User Apr 16, 2013 #29 thedesolatesoul said: Yes. Click to expand... Your new snippet of code gives the following error: Code: Copy Error Occurred An error has occurred in sub: main_activity_resume (java line: 337) java.lang.StringIndexOutOfBoundsException: length=80; regionStart=36; regionLength=-37 Continue? Upvote 0
thedesolatesoul said: Yes. Click to expand... Your new snippet of code gives the following error: Code: Copy Error Occurred An error has occurred in sub: main_activity_resume (java line: 337) java.lang.StringIndexOutOfBoundsException: length=80; regionStart=36; regionLength=-37 Continue?
thedesolatesoul Expert Licensed User Longtime User Apr 16, 2013 #30 yttrium said: Your new snippet of code gives the following error: Code: Copy Error Occurred An error has occurred in sub: main_activity_resume (java line: 337) java.lang.StringIndexOutOfBoundsException: length=80; regionStart=36; regionLength=-37 Continue? Click to expand... It works fine for me. Maybe your intent is delivered differently. You will have to figure out that yourself. Upvote 0
yttrium said: Your new snippet of code gives the following error: Code: Copy Error Occurred An error has occurred in sub: main_activity_resume (java line: 337) java.lang.StringIndexOutOfBoundsException: length=80; regionStart=36; regionLength=-37 Continue? Click to expand... It works fine for me. Maybe your intent is delivered differently. You will have to figure out that yourself.
yttrium Active Member Licensed User Longtime User Apr 16, 2013 #31 thedesolatesoul said: It works fine for me. Maybe your intent is delivered differently. You will have to figure out that yourself. Click to expand... It was a really simple error with this line: Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) I don't know where you thought a comma existed in Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7859}] but changing the line of code to Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf("}")) fixed it immediately. Thanks! Upvote 0
thedesolatesoul said: It works fine for me. Maybe your intent is delivered differently. You will have to figure out that yourself. Click to expand... It was a really simple error with this line: Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) I don't know where you thought a comma existed in Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7859}] but changing the line of code to Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf("}")) fixed it immediately. Thanks!
thedesolatesoul Expert Licensed User Longtime User Apr 16, 2013 #32 yttrium said: It was a really simple error with this line: Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) I don't know where you thought a comma existed in Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7859}] but changing the line of code to Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf("}")) fixed it immediately. Thanks! Click to expand... The intent returned on my device, had another extra after this one, so it had a comma. So you have to careful otherwise your code will not run on all devices (my code was only a demonstration not meant to be used in production-grade code). Either way, the correct way is to use In.GetExtra which is not working for some reason. Upvote 0
yttrium said: It was a really simple error with this line: Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf(",")) I don't know where you thought a comma existed in Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7859}] but changing the line of code to Code: Copy MyUriString = MyUriString.SubString2(MyUriString.IndexOf("=")+1,MyUriString.IndexOf("}")) fixed it immediately. Thanks! Click to expand... The intent returned on my device, had another extra after this one, so it had a comma. So you have to careful otherwise your code will not run on all devices (my code was only a demonstration not meant to be used in production-grade code). Either way, the correct way is to use In.GetExtra which is not working for some reason.
yttrium Active Member Licensed User Longtime User Apr 16, 2013 #33 thedesolatesoul said: The intent returned on my device, had another extra after this one, so it had a comma. So you have to careful otherwise your code will not run on all devices (my code was only a demonstration not meant to be used in production-grade code). Either way, the correct way is to use In.GetExtra which is not working for some reason. Click to expand... Can you show me the syntax of your Log(In.ExtrasToString) on your device? Upvote 0
thedesolatesoul said: The intent returned on my device, had another extra after this one, so it had a comma. So you have to careful otherwise your code will not run on all devices (my code was only a demonstration not meant to be used in production-grade code). Either way, the correct way is to use In.GetExtra which is not working for some reason. Click to expand... Can you show me the syntax of your Log(In.ExtrasToString) on your device?
thedesolatesoul Expert Licensed User Longtime User Apr 16, 2013 #34 yttrium said: Can you show me the syntax of your Log(In.ExtrasToString) on your device? Click to expand... Here: Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7935, exit_on_sent=true}] Upvote 0
yttrium said: Can you show me the syntax of your Log(In.ExtrasToString) on your device? Click to expand... Here: Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7935, exit_on_sent=true}]
yttrium Active Member Licensed User Longtime User Apr 16, 2013 #35 thedesolatesoul said: Here: Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7935, exit_on_sent=true}] Click to expand... So then perhaps this? Code: Copy MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("STREAM=")+1,MyUriString.IndexOf("}")) If MyUriString.Contains(",") Then MyUriString = MyUriString.SubString2(0,MyUriString.IndexOf(",")) Upvote 0
thedesolatesoul said: Here: Code: Copy Bundle[{android.intent.extra.STREAM=content://media/external/images/media/7935, exit_on_sent=true}] Click to expand... So then perhaps this? Code: Copy MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("STREAM=")+1,MyUriString.IndexOf("}")) If MyUriString.Contains(",") Then MyUriString = MyUriString.SubString2(0,MyUriString.IndexOf(","))
thedesolatesoul Expert Licensed User Longtime User Apr 16, 2013 #36 Yes, that seems reasonably safe. Upvote 0
yttrium Active Member Licensed User Longtime User Apr 16, 2013 #37 Awesome. I'll probably put the comma line in a loop until there are no commas left. And ugh, for some reason (I didn't change any code there!) I'm now getting the following error yet again: http://www.b4x.com/forum/basic4andr...67-intent-filters-receiving-2.html#post164404 Upvote 0
Awesome. I'll probably put the comma line in a loop until there are no commas left. And ugh, for some reason (I didn't change any code there!) I'm now getting the following error yet again: http://www.b4x.com/forum/basic4andr...67-intent-filters-receiving-2.html#post164404
yttrium Active Member Licensed User Longtime User Apr 16, 2013 #38 thedesolatesoul said: Yes, that seems reasonably safe. Click to expand... Turns out it's not. I am incredibly stupid: Code: Copy MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("STREAM=")+1,MyUriString.IndexOf("}")) If MyUriString.Contains(",") Then MyUriString = MyUriString.SubString2(0,MyUriString.IndexOf(",")) STREAM= is not 1 character. Code: Copy MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("STREAM=")+7,MyUriString.IndexOf("}")) If MyUriString.Contains(",") Then MyUriString = MyUriString.SubString2(0,MyUriString.IndexOf(",")) Error fixed and works perfectly, though I'm experimenting with Erel's answer as well (which replaces the whole GetPathFromContentResult function). Last edited: Apr 16, 2013 Upvote 0
thedesolatesoul said: Yes, that seems reasonably safe. Click to expand... Turns out it's not. I am incredibly stupid: Code: Copy MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("STREAM=")+1,MyUriString.IndexOf("}")) If MyUriString.Contains(",") Then MyUriString = MyUriString.SubString2(0,MyUriString.IndexOf(",")) STREAM= is not 1 character. Code: Copy MyUriString = In.ExtrasToString MyUriString = MyUriString.SubString2(MyUriString.IndexOf("STREAM=")+7,MyUriString.IndexOf("}")) If MyUriString.Contains(",") Then MyUriString = MyUriString.SubString2(0,MyUriString.IndexOf(",")) Error fixed and works perfectly, though I'm experimenting with Erel's answer as well (which replaces the whole GetPathFromContentResult function).