Sl4A Broadcasting an Intent to Minimalistic text widget

≡放荡痞女 提交于 2020-01-03 02:12:41

问题


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)

回答1:


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




回答2:


I got it working finally! From this Stackoverflow answer

import android

droid = android.Android()

activity = 'com.twofortyfouram.locale.intent.action.FIRE_SETTING'
extras = {}
extras['de.devmil.minimaltext.locale.extras.VAR_NAME'] = 'test'
extras['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)

That said I am unsure as to where I have gone wrong in my initial code. If anyone would care to chime in and point out where the hell I have gone wrong



来源:https://stackoverflow.com/questions/18710318/sl4a-broadcasting-an-intent-to-minimalistic-text-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!