Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to android jvm on termux #732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomaszduda23
Copy link

@tomaszduda23 tomaszduda23 commented Sep 22, 2024

It is possible to access android classes from termux by adding new app termux-pyjnius which load python and pyjnius. pyjnius for termux is build with jnius_jvm_dlopen.pxi. It adds possibility to provide any jnienv in android. It was discussed some time ago in #247. It allows to use bellow example in termux.

from jnius import autoclass

DisplayMetrics = autoclass('android.util.DisplayMetrics')

metrics = DisplayMetrics()

WindowManager = autoclass('android.view.WindowManager')
Context = autoclass('android.content.Context')
MainActivity = autoclass('com.termux.pyjnius.MainActivity')

activity = MainActivity.mActivity
window_manager = activity.getSystemService(Context.WINDOW_SERVICE)
default_display = window_manager.getDefaultDisplay()

default_display.getMetrics(metrics)

density = metrics.density
density_dpi = metrics.densityDpi
width_pixels = metrics.widthPixels
height_pixels = metrics.heightPixels

print(f"Screen density: {density}")
print(f"Screen density DPI: {density_dpi}")
print(f"Screen width in pixels: {width_pixels}")
print(f"Screen height in pixels: {height_pixels}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant