Writing an Intent object to File

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can create a type that mimics the intent structure. Fill the type fields and save it with RandomAccessFile.WriteObject. Do you want to be able to save any intent? Or a known intent? If you need to save any possible intent then you will need to use ExtrasToString to get a string with all the extras. You will need to implement the parsing code that parses this string and recreates the extras.

Some intents may include more complicated objects in the extras fields.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Initially I wanted to save any kind of intent. This was meant for a callback i.e. some other app could send me an intent wrapped in an intent, so I could call it back later.
I'm guessing this is not possible. So I will have to store the component and the extras to call them back.
However today I had quite a difficult time getting an intent to work with setComponent(packagename/.activity) , it didnt work. I had to use a different kind of intent filter (with a custom action) to get the intent to work.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Is it possible to implement the getExtras() method so that I can get the complete list of extras into a Map, instead of parsing a string? I tried with JavaObjects but couldn't understand the "Bundle" return type.

Basically I need to save an intent to file, read from the file later and call StartActivity() on it.
 
Last edited:
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Did anyone solve Inman's issue?

I use:

B4X:
Sub ParseExtras(ExtrasString As String) As Map 
	Dim tempMap As Map ,tempstr() As String , temp As Int , Key As String, Value As String 
	tempMap.Initialize 
	ExtrasString = API.Mid(ExtrasString, 8, ExtrasString.Length-10) & ", "
	tempstr= Regex.Split(", ", ExtrasString)
	For temp = 0 To tempstr.Length-1 
		Key=API.getside(tempstr(temp), "=", True, False).Trim 
		Value= API.Right(tempstr(temp), tempstr(temp).Length- Key.Length -1).Trim 
		tempMap.Put( Key, Value)
	Next
	Return tempMap
End Sub

but it's not perfect.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
ie:

'Extras: Bundle[{android.intent.extra.shortcut.INTENT=Intent { act=android.intent.action.VIEW dat=http://warnersretrocorner.com/wp-co...t-Poster-Nes-Conan-barbarian-190876195313.jpg pkg=com.android.chrome (has extras) }, android.intent.extra.shortcut.ICON=android.graphics.Bitmap@2b7afcf3, android.intent.extra.shortcut.NAME=A3-80s-Replica-Reproduction-Video-Game-PRINT-Box-Art-Poster-Nes-Conan-barbarian-190876195313.jpg (290×400)}]
 
Upvote 0
Top