1

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!

4

1 回答 1

1

我刚刚重新阅读了您的问题,有一些全屏 webview 的示例,但是据我所知,webview 是一种全有或全无的交易。如果您想使用 XML 查看Fullscreenwrapper2,因为它允许您使用与本机 Java 应用程序类似的 xml 布局,从那里您可以查找 xml 布局的示例并进行修改以适应。

你想要一个小部件还是一个对话框?如果你只想要一个对话框,你可以使用一个 dialogCreateAlert

import android

droid = android.Android()

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

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

但是,如果您想在小部件上使用它,我发现最简单的解决方案是使用简约的文本小部件,您可以通过 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")

直接通过本地意图(您在 MT 中使用本地变量字段选择此选项):

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)
于 2013-10-11T05:33:57.810 回答