python-for-android icon indicating copy to clipboard operation
python-for-android copied to clipboard

Broadcast parameter sent via not taking effect

Open tsiens opened this issue 11 months ago • 3 comments

Success in PC

adb shell am broadcast -a android.intent.action.shbl.shut_down --ei  time 6666

Faild in Phone

from jnius import autoclass

mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
Intent = autoclass('android.content.Intent')
intent = Intent("android.intent.action.shbl.shut_down")
intent.putExtra("time", 6666)
mActivity.sendBroadcast(intent)

Can receive broadcast, but did not receive parameter “time“

tsiens avatar Mar 05 '25 15:03 tsiens

I suspect this is about Android behavior rather than p4a or pyjnius behavior.

There are plenty of examples of putExtra using pyjnius. For example https://github.com/Android-for-Python/androidstorage4kivy/blob/main/src/androidstorage4kivy/chooser.py#L28. The functionality of the Java is transparent to pyjnius.

This might be a permissions issue, adb has root permission, the app has app permission.

This might be an api issue. I suggest you check the Android documentation for "android.intent.action.shbl.shut_down" (I can't find any!) for a documented "time" extra. For example https://developer.android.com/reference/android/content/Intent#ACTION_SHUTDOWN does not have a "time" extra.

RobertFlatt avatar Mar 07 '25 06:03 RobertFlatt

I suspect this is about Android behavior rather than p4a or pyjnius behavior.

There are plenty of examples of putExtra using pyjnius. For example https://github.com/Android-for-Python/androidstorage4kivy/blob/main/src/androidstorage4kivy/chooser.py#L28. The functionality of the Java is transparent to pyjnius.

This might be a permissions issue, adb has root permission, the app has app permission.

This might be an api issue. I suggest you check the Android documentation for "android.intent.action.shbl.shut_down" (I can't find any!) for a documented "time" extra. For example https://developer.android.com/reference/android/content/Intent#ACTION_SHUTDOWN does not have a "time" extra.

I tried to make the system print out the received broadcast, but found that putExtra can only emit a string equivalent to es, but the broadcast requires ei numbers, and all receivers cannot recognize the parameters

tsiens avatar Mar 07 '25 06:03 tsiens

I'm sorry I don't know what es and ei number are.

Its not clear to me that this is a p4a issue.

RobertFlatt avatar Mar 07 '25 16:03 RobertFlatt