SL4A选择运行从通知窗口申请 [英] Sl4A Selecting running application from notification window

查看:206
本文介绍了SL4A选择运行从通知窗口申请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我写了一个程序SL4A。我有一个问题,我已经准备好发布之前。

I have a SL4A program I have written. I have one issue before i'm ready to publish it.

有关,当应用程序正在运行,如果我回家筛选出的应用程序,我看到它在通知区域中运行,但是当我选择它什么也不会发生某些原因。但是,如果我点击来自应用领域我的图标,它会带来应用程序备份。

For some reason when the app is running, if I home screen out of the app, I see it running in the notification area, but when I select it nothing happens. However if I click my icon from apps area it will bring the app back up.

有什么建议?

推荐答案

嘛看来你可以看到SL4Acomo.google code.android_scripting包用下面的命令启动了通知:

Well It seems that you can see the notifications started by SL4A "como.googlecode.android_scripting" package with the following command:

这更像是一个黑客。

dumpsys statusbar | grep "pkg=com.googlecode.android_scripting"

由SL4A发起的每个通知将有身份证。例如,ID = 1是在服务器运行时SL4A开始通知。一个你点击停止服务器。

Every notification initiated by SL4A will have an "id". For example the "id=1" is the notification started by SL4A when the server is running. The one you click to stop the server.

考虑到这一点,你可以其实可以列出每一个通知你的包和块开始,直到你通知的ID消失。

With this in mind you can can actually list every notification started by your package and block until the id of your notification disappear.

如果这样的话你的下一个通知,都应有一个ID 2个或以上。请注意,如果SL4A停止或崩溃这可以改变的。下一次你可能会获得ID = 2为(RPC)服务器的通知,然后在ID = 3,并在你的应用程序通知,直到你重新启动设备等RPC服务器通知可以追溯到ID = 1 。知道这意味着你需要不断的新通知searchig一个循环中。

If so then your next notifications should have an id with 2 or above. Note that this can change if SL4A is stopped or crash. The next time you may get the "id=2" for the (RPC) server notification and then "id=3" and over for your app notifications until you restart your device and so the RPC server notification goes back to "id=1". Knowing this means that you need to keep searchig for new notifications within a loop.

例如在bash和使用亚行:

For example in bash and using adb:

while read Info; do echo "$Info" | grep 'pkg=com.googlecode.android_scripting'; done < <(adb shell dumpsys statusbar)

您会得到这样的:

1:StatusBarNotification(PKG = com.google code.android_scripting ID = 2标签= NULL分数= 0 notn =通知(PRI = 0 =内容查看com.google code.android_scripting / 0x109008f振动= NULL听起来= NULL默认值=为0x0标志= 0X62 =样[空])用户= UserHandle {0})#SL4A RPC通知

1: StatusBarNotification(pkg=com.googlecode.android_scripting id=2 tag=null score=0 notn=Notification(pri=0 contentView=com.googlecode.android_scripting/0x109008f vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null]) user=UserHandle{0}) # SL4A RPC Notification

7:StatusBarNotification(PKG = com.google code.android_scripting ID = 3 =标签的空分= 0 notn =通知(PRI = 0 =内容查看com.google code.android_scripting / 0x109008f振动= NULL听起来= NULL默认值=为0x0标志= 0×10 =样[空])用户= UserHandle {0})#我的通知

7: StatusBarNotification(pkg=com.googlecode.android_scripting id=3 tag=null score=0 notn=Notification(pri=0 contentView=com.googlecode.android_scripting/0x109008f vibrate=null sound=null defaults=0x0 flags=0x10 kind=[null]) user=UserHandle{0}) # My Notification

让我们玩这个!

运行:

while read Info; do echo "$Info" | grep "pkg=com.googlecode.android_scripting" | awk '{print $3}' | cut -s -d '=' -f2 ; done < <(adb shell dumpsys statusbar)

会得到你,例如:

Will get you for example:

# Without Using Cut
id=2 # SL4A Notificaion
id=3 # My Notification

或者

# Using Cut
2 # SL4A Notification
3 # My Notification

让我们开始行动! (一个丑陋的解决方案)

Let's get to the action! (An ugly solution)

# Start ADB USB Serial Connection
adb devices

# Activate Wireless ADB (Needs Root) - Not Needed
# adb shell setprop service.adb.tcp.port 5555
# stop adbd
# start adbd 

或者

# Start ADB Wireless
adb connect 192.168.1.3

NotifyCount=0 
NotifyList=()

while read Notify; do

   DumpNotify=`echo "$Notify" | grep "pkg=com.googlecode.android_scripting" | awk '{print $3}' | cut -s -d '=' -f2`

   if [ ! -z "$DumpNotify" ] ; then 
      NotifyList[$NotifyCount]="$DumpNotify"
      ((NotifyCount++))  
   fi 

done < <(adb shell dumpsys statusbar)

SL4ARPCNotification="2"
MyScriptNotification="3"

if [[ ${NotifyList[*]} != *"$MyScriptNotification"* ]] ; then 
   adb shell am start -a android.intent.action.MUSIC_PLAYER
fi

这应该是2的功能与MyNotification和SL4ARPCNotification变量参数更好。这样,你可以从任何地方在code核实和划分工作:FunctionX上市的通知和函数y比较的结果。

This should be better in 2 functions with arguments for MyNotification and SL4ARPCNotification variables. That way you can verify from anywhere in the code and divide the job: FunctionX for listing the notifications and FunctionY for comparing the results.

这可以很容易地在Pyhon或其他跨preters来完成。你需要记住,总会有来自SL4A本身的通知。通过使用Python中线程可以为新的或旧的通知不断搜索,而不需要阻止你的程序等待一个变化,所以你可以继续正常runninig你的脚本。

This can easily be done in Pyhon or other interpreters. You need to remember that there's always a notification from SL4A itself. By using Threading in python you can continuously search for new or old notifications without the need to block your program waiting for a change and thus you can continue runninig your script normally.

这篇关于SL4A选择运行从通知窗口申请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆