Question

I'd like to know how can I show simple and short data (eg: temperature data from a running script) in Android desktop using SL4A. My script gets temperature data from a web, and I tried showing it via notify, via toast and via dialogs, but I´d like it to remain accesible on the screen. I undestand that webview is an option but I can´t write the xml code for a simple text box, as I undestand I should. Is this right? Where could I get a (very) simple code example in xml to show text on screen (not full screen)? Thanks!

Was it helpful?

Solution

I just re-read your question there are a few examples of full screen webviews however as far as I understand it webview is kind of an all or nothing deal. If you want to us Xml look into the Fullscreenwrapper2 as it allows you to use similar xml layouts to native java apps, from there you can look for examples of xml layouts and modify to fit.

Do you want a widget or just a dialog box? if you just want a dialog box you can just use a dialogCreateAlert

import android

droid = android.Android()

title=("Your Tittle")
content=("Your content")

droid.dialogCreateAlert(title, content)
droid.dialogShow()

However if you want it on a widget the simplest soloution I have found is to use a minimalistic text widget you can pass the data either through tasker or directly using a local intent.

Through Tasker:

import android, time

droid = android.Android()
class Task():
    SET_VARIABLE = 547
    def new_task(self):
        self.action_cnt = 0
        self.extras = {'version_number': '1.0', 'task_name': 'task' + str(time.time()), 'task_priority': 9 }
    def set_var(self, varname, value):
        self.action_cnt += 1
        self.extras['action' + str(self.action_cnt)] = {'action': self.SET_VARIABLE, 'arg:1': varname, 'arg:2': value, 'arg:3': False, 'arg:4': False, 'arg:5': False}
    def run_task(self):
        taskIntent = droid.makeIntent('net.dinglisch.android.tasker.ACTION_TASK', None, None, self.extras).result
        droid.sendBroadcastIntent(taskIntent)
    def set_var_now(self, varname, value):
        self.new_task()
        self.set_var(varname, value)
        self.run_task()

t = Task()
t.set_var_now("%Var", "Your variable value")

Directly via a Local intent (You select this in MT by using a Local variable field):

import android

droid = android.Android()

activity = 'com.twofortyfouram.locale.intent.action.FIRE_SETTING'
extras = {}
extras['de.devmil.minimaltext.locale.extras.VAR_NAME'] = 'Your Variable name'
extras['de.devmil.minimaltext.locale.extras.VAR_TEXT'] = 'Your Variable content'

packagename =  'de.devmil.minimaltext'
classname = 'de.devmil.minimaltext.locale.LocaleFireReceiver'

intent = droid.makeIntent(activity, None, None, extras, None, packagename, classname).result

droid.sendBroadcastIntent(intent)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top