Search code examples
androidpythonandroid-intentsl4a

Sl4A Broadcasting an Intent to Minimalistic text widget


I have been attempting to send variable data directly from SL4A to Minimalistic Text Widget using sendBroadcastIntent much like how I can send variables to Tasker (Using code I found on the SL4A google groups)

Unfortunately my understanding of intents is a little lax and I have found locating tutorials specifically in relation to SL4A almost impossible.

The SL4A makeintent API Reference

The minimalistic Test Intent example

The code I have attempted to use:

import Android
droid = Android()

activity = "com.twofortyfouram.locale.intent.action.FIRE_SETTING"
extras = {'de.devmil.minimaltext.locale.extras.VAR_NAME': "Test"; "de.devmil.minimaltext.locale.extras.VAR_TEXT" : "Passed"}
packagename = 'de.devmil.minimaltext'
classname = 'de.devmil.minimaltext.locale.LocaleFireReceiver'
intent = droid.makeIntent(activity, None, None, extras, None, packagename, classname).result
droid.sendBroadcastIntent(intent)

Solution

  • The reason your original code did not work is because you are using ; instead of , to split the name/value pairs when you create the dictionary called extras.

    Wrong Way:

    extras = {'de.devmil.minimaltext.locale.extras.VAR_NAME':"Test" ; "de.devmil.minimaltext.locale.extras.VAR_TEXT" : "Passed"}
    

    Correct Way:

    extras = {'de.devmil.minimaltext.locale.extras.VAR_NAME':"Test" , 'de.devmil.minimaltext.locale.extras.VAR_TEXT' : "Passed"}
    

    You can learn more about using dictionaries here: http://www.tutorialspoint.com/python/python_dictionary.htm