0

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.

Any suggestions?

  • If your app is running, but you are not viewing the app, it should put an SL4A icon in the notifications area. If you open your notifications blade, you should be able to click the SL4A Running Scripts notification, which brings up a list of all running SL4A scripts. Then you choose the script you want and should be returned to the script's GUI or terminal. I'm not sure what it'd do if you had a background app with no GUI ~ is that what you have? – Carl Smith Feb 07 '13 at 02:10

3 Answers3

0

Notifications created by SL4A do nothing; they have no callback and can only alert users. Unfortunately there isn't really any way around this: BeanShell, JRuby and Rhino can make Java API calls (eg., to add the 'open my app when clicked' part) but can't use Contexts (which notifications require), and you could make your own version of the API facade, but then users would be required to install your specific version of x (eg., Python) for Android.

Otherwise all I could think of would be to get tricky with Intents or something and include an activity in the /src of your app to show the notification, though that would likely require learning Java / Android programming meaning you may as well follow through and write the entire app natively.

Sorry, but there really isn't an easy way to do this

Grace B
  • 1,386
  • 11
  • 30
0

You stated you wanted to publish it so I am assuming you were implying that in the long run you will be compiling it into a standalone apk?

If so, which package are/will you be using? py4a's method, python27, kivy? From my experiences when you compile to an apk with python27, there is no notification window at the top at all but if you were to compile it using py4a's method it should create a workable notification item for you. Please see the following link for further information: http://code.google.com/p/android-scripting/wiki/SharingScripts

Otherwise ProfSmiles answer is correct but it appears to be a much more complex solution then using the py4a method.

You can also see the python27 project if you would like a more embedded approach, although as mentioned previously it does not have a notification setup by default like py4a.

Kivy's implementation also looks promising but I am unfamiliar with it, it might also be worth looking at further: https://github.com/kivy/python-for-android

AWainb
  • 868
  • 2
  • 13
  • 27
0

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

This is more like a hack.

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

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.

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

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.

For example in bash and using adb:

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

You'll get something like this:

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.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

Let's play with this!

Running:

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

Or:

# 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 

Or:

# 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

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.

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.

DarkXDroid
  • 311
  • 2
  • 11