pyjnius icon indicating copy to clipboard operation
pyjnius copied to clipboard

Android 5.1 PythonActivity.mActivity Stuck

Open 331319341 opened this issue 8 years ago • 4 comments

74765882-7fe9-44be-855b-b2163729b3c8


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

331319341 avatar Jun 15 '17 09:06 331319341

@331319341 so, we have the log, that's good, but it's not complete (the log should end with Python for android ended or something like that). What we don't have is what's wrong with it or at least some code that could reproduce it. Buildozer/P4A files used for creating the APK would be nice too. Please include the requested stuff :)

KeyWeeUsr avatar Jun 15 '17 21:06 KeyWeeUsr

from jnius import cast from jnius import autoclass

import the needed Java class

PythonActivity = autoclass('org.renpy.android.PythonActivity') Intent = autoclass('android.content.Intent') Uri = autoclass('android.net.Uri')

create the intent

intent = Intent() intent.setAction(Intent.ACTION_VIEW) intent.setData(Uri.parse('http://kivy.org'))

PythonActivity.mActivity is the instance of the current Activity

BUT, startActivity is a method from the Activity class, not from our

PythonActivity.

We need to cast our class into an activity and use it

currentActivity = cast('android.app.Activity', PythonActivity.mActivity) currentActivity.startActivity(intent)

The website will open.

331319341 avatar Jun 16 '17 07:06 331319341

image

331319341 avatar Jun 16 '17 07:06 331319341

8ac34446-5f8e-473b-80bf-0193be4e9f33

331319341 avatar Jun 16 '17 07:06 331319341