Package: kvdroid
KvDroidA re-implementation of android java API in python with easy access to some Android functionality like Notification,
Reading of Contacts, accessing Webview Cookies, etc...The aim is to provide full access to Android API which can be used together with Python frameworks like:kivy,kivymd, etc... Or as a standalone, in which
Android native UI is created with only python codes.Compiling into APKTo compile, kivyp4aor kivybuildozeris
required, and bootstrap must be set tosdl2DependenciesAndroidmin-api21Installationpip install kvdroid

or

pip install https://github.com/kvdroid/Kvdroid/archive/refs/heads/master.zip # master version
# Note: this works on android only, but you can install it on your desktop for code completion assistanceBuildozer Requirementrequirement = kvdroid

or

requirement = https://github.com/kvdroid/Kvdroid/archive/refs/heads/master.zipUsageTo use system-provided fonts:warning:That function is so experimental. It should work for Android 7 and above but not been tested on much devices. It is actually for multilingual purposes to use system-provided fonts for no Latin languages. system_font() will always return the supported font from /system/fonts for the current device language.  Also, you could use any language-supported font from the system just by calling the system_font function with the target language's iso639-1 or iso639-2 abbreviation such as font_name = system_font('zh') or system_font('zho').fromkivy.uix.labelimportLabelfromkvdroid.tools.fontimportsystem_font# that will return the default font for the device's current language.Label(text="example",font_name=system_font())# for the specific language fontLabel(text="你好世界",font_name=system_font('zho'))# Language definition must be iso639-1 or iso639-2 abbreviation.  https://en.wikipedia.org/wiki/List_of_ISO_639-1_codesTo send notificationfromkvdroid.jclass.android.graphicsimportColorfromkvdroid.tools.notificationimportcreate_notificationfromkvdroid.toolsimportget_resourcecreate_notification(small_icon=get_resource("drawable").ico_nocenstore,# app iconchannel_id="1",title="You have a message",text="hi, just wanted to check on you",ids=1,channel_name=f"ch1",large_icon="assets/image.png",expandable=True,small_icon_color=Color().rgb(0x00,0xC8,0x53),# 0x00 0xC8 0x53 is same as 00C853big_picture="assets/image.png")To read Contactsfromkvdroid.tools.contactimportget_contact_detailsget_contact_details("phone_book")# gets a dictionary of all contact both contact name and phone mumbersget_contact_details("names")# gets a list of all contact namesget_contact_details("mobile_no")# gets a list of all contact phone numbersTo get a list of all installed packages (Applications)fromkvdroid.tools.packageimportall_packagesprint(all_packages())"""['com.google.android.carriersetup','com.android.cts.priv.ctsshim','com.google.android.ext.services','com.android.providers.telephony','com.android.providers.calendar'...]"""To get all main activitiesfromkvdroid.tools.packageimportall_main_activitiesprint(all_main_activities())"""[{'com.android.settings': 'com.android.settings.Settings'},{'com.android.vending': 'com.android.vending.AssetBrowserActivity'},{'com.google.android.contacts': 'com.android.contacts.activities.PeopleActivity'},{'com.google.android.deskclock': 'com.android.deskclock.DeskClock'}...]"""To check if the package is a system applicationfromkvdroid.tools.packageimportis_system_packageprint(is_system_package("com.android.settings"))To check if the package is enabledfromkvdroid.tools.packageimportis_package_enabledprint(is_package_enabled("com.android.settings"))To get a specific app detailsfromkvdroid.tools.packageimportpackage_infoprint(package_info("com.android.settings"))"""{'activities': ['org.chromium.settings.SettingsBlackHoleActivity','com.android.settings.Settings$NetworkDashboardActivity','com.android.settings.network.NetworkSettings','com.android.settings.Settings$AdvancedAppsActivity','com.android.settings.app.AdvancedAppsSettings'...],'dataDir': '/data/user_de/0/com.android.settings','loadIcon': <android.graphics.drawable.Drawable at 0x7e8e15bac8b0 jclass=android/graphics/drawable/Drawable jself=<LocalRef obj=0x6196 at 0x7e8e15f63e30>>,'loadLabel': 'Settings','packageName': 'com.android.settings','permissions': ['org.chromium.settings.ENABLE_INPUT_METHOD','android.permission.REQUEST_NETWORK_SCORES','android.permission.WRITE_MEDIA_STORAGE','android.permission.WRITE_EXTERNAL_STORAGE'...],'processName': 'com.android.settings','publicSourceDir': '/system/priv-app/ArcSettings/ArcSettings.apk','sharedLibraryFiles': None,'sourceDir': '/system/priv-app/ArcSettings/ArcSettings.apk'}"""To get an activity infofromkvdroid.tools.packageimportactivity_infoprint(activity_info("com.android.settings","com.android.settings.network.NetworkSettings"))"""{'loadIcon': <android.graphics.drawable.Drawable at 0x7e8e15c46db0 jclass=android/graphics/drawable/Drawable jself=<LocalRef obj=0x6156 at 0x7e8e15c8c8b0>>,'loadLabel': 'Network and Internet'}"""To save a drawable object to given path as pngfromkvdroid.tools.packageimportpackage_infofromkvdroid.tools.graphicsimportsave_drawableapp=package_info("com.android.settings")app_icon=app["loadIcon"]# <android.graphics.drawable.Drawable at 0x7e8e15c46db0 jclass=android/graphics/drawable/Drawable jself=<LocalRef obj=0x6156 at 0x7e8e15c8c8b0>>save_drawable(app_icon,"< path >","< file_name >")# That will save the app icon to given path and return the path + filename# can be used likefromkivy.uix.imageimportImageImage(source=save_drawable(app_icon,"< path >","< file_name >"))To check if the given app is installed from PlayStorefromkvdroid.tools.packageimportpackage_sourceprint(package_source("< package_name >"))To get Android WebView Cookiesfromkvdroid.tools.webkitimportget_cookiesget_cookies("https://google.login")To detect keyboard heightfromkvdroid.toolsimportkeyboard_heightprint(keyboard_height())To detect if app is installed from Play Store or notfromkvdroid.tools.appsourceimportapp_sourceprint(app_source())To get absolute screen size in dp-pixel and detect current orientationfromkvdroid.tools.metricsimportMetricsscreen=Metrics()print(screen.orientation())print(screen.width_dp())print(screen.height_px())print(screen.resolution())To check if device has a data connection.fromkvdroid.tools.networkimportnetwork_status,wifi_status,mobile_statusprint(network_status())# for both wifi and mobileprint(wifi_status())# only for wifiprint(mobile_status())# only for mobileTo check if device is  in dark mode or notfromkvdroid.tools.darkmodeimportdark_modeprint(dark_mode)To get device informations.
Available options are;'model','brand','manufacturer','version','sdk','product','base','rom','security','hardware','tags','sdk_int','total_mem','used_mem','avail_ram','total_ram','used_ram','bat_level','bat_capacity','bat_temperature','bat_voltage','bat_technology'fromkvdroid.tools.deviceinfoimportdevice_infoprint(device_info("model"))print(device_info("avail_ram",convert=True))To enable immersive modefromkvdroid.toolsimportimmersive_modeimmersive_mode()To launch an applicationfromkvdroid.toolsimportlaunch_applaunch_app("< app_package >")To launch a specific application activityfromkvdroid.toolsimportlaunch_app_activitylaunch_app_activity("< app_package >","< app_activity >")To open target app's details pagefromkvdroid.toolsimportapp_detailsapp_details("< app_package >")To detect current device's languagefromkvdroid.tools.langimportdevice_langprint(device_lang())# enprint(device_lang("DisplayLanguage"))# Englishprint(device_lang(option="DisplayLanguage",display_lang="fr"))# Anglais"""Available options are ;Language           ---> enISO3Language       ---> engCountry            ---> USISO3Country        ---> USADisplayCountry     ---> United StatesDisplayName        ---> English (United States)String             ---> en_USDisplayLanguage    ---> EnglishLanguageTag        ---> en-US"""To get a list of supported languages on the devicefromkvdroid.tools.langimportsupported_languagesprint(supported_languages())"""['af', 'agq', 'ak', 'am', 'ar', 'as', 'asa', 'ast'...]"""To set statusbar colorfromkvdroid.toolsimportchange_statusbar_colorchange_statusbar_color("#FFFFFF","black")To set navigationbar colorfromkvdroid.toolsimportnavbar_colornavbar_color("#FFFFFF")To display a toast messagefromkvdroid.toolsimporttoasttoast("hello world")To get absolute sdcard pathfromkvdroid.tools.pathimportsdcardprint(sdcard)To get absolute external_sdcardfromkvdroid.tools.pathimportexternal_sdcardprint(external_sdcard)To get file mime Typefromkvdroid.toolsimportmime_typemime_type=mime_type("path/to/file")print(mime_type)To change default wallpaperfromkvdroid.toolsimportset_wallpaperset_wallpaper("/sdcard/test.jpg")To use text-to-speechfromkvdroid.toolsimportspeechspeech("hello world","en")To use default Download Managerfromkvdroid.toolsimportdownload_managerdownload_manager("< title >","< description >","< URL >","< path >","< file >")To restart the appfromkvdroid.toolsimportrestart_apprestart_app()To share text via Android Share menufromkvdroid.toolsimportshare_textshare_text("hello world",title="Share",chooser=False,app_package=None,call_playstore=False,error_msg="application unavailable")To share any file via Android Share menufromkvdroid.toolsimportshare_fileshare_file("< path - to - file >","< title >","< chooser >","< app - package: open -with-default - app >","< call_playstore >","< error_msg >")share_file("/sdcard/test.pdf",title='Share',chooser=False,app_package=None,call_playstore=False,error_msg="application unavailable")To play supported music format or radio stream through Android Media Playerplayer.mPLayer = Android Media PLayerfromkvdroid.tools.audioimportPlayerplayer=Player()player.play("< path - to - music - file >")player.stream("https://bit.ly/3mHQdzZ")# radioplayer.pause()player.resume()player.seek(2)# secondsplayer.do_loop(True)# default is Falseplayer.is_playing()player.get_duration()player.current_position()To cast Java Objectfromkvdroid.castimportcast_objectfromkvdroid.jclass.androidimportUriuri=Uri().fromFile("/home/java/my_document.pdf")parcelable=cast_object("parcelable",uri)# Above code  is same as below code::fromkvdroid.jclass.androidimportUrifromjniusimportcasturi=Uri().fromFile("/home/java/my_document.pdf")parcelable=cast("android.os.Parcelabel",uri)'''the difference is, you dont have to remember the package name, just only the name andyou are good to go. This will also be helpful for python devs who do have zero knowledge on javaNote::not all castable java object are included you can open an issue to include all missingcastables'''To access WebView cookies(i.e if you compiled your app with webview bootstrap or have Webview in your app)fromkvdroid.tools.webkitimportget_cookiesprint(get_cookies("https://google.com"))To access android package resource folders like:drawblelayoutmenuvaluesmipmapetc....fromkvdroid.toolsimportget_resourcedrawable=get_resource("drawable")To get Wi-Fi IP Addressfromkvdroid.tools.networkimportget_wifi_ip_addressprint(get_wifi_ip_address())To send emailfromkvdroid.tools.emailimportsend_emailsend_email(recipient=["test@gmail.com"],subject="Hello there",body="This is kvdroid")To send an email with an attachment (androidx is required).Also note before you can share files on Android version greaterthan 10, you must specify a provider in the AndroidManifest.xmlinside the <application> tag e.g<providerandroid:name="androidx.core.content.FileProvider"android:authorities="${applicationId}.fileprovider"android:grantUriPermissions="true"android:exported="false"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/filepath"/></provider>and also specify file path in the res/xml/filepath.xml of the android project folder e.g<paths><files-pathname="document"path="app"/></paths>refer toandroid developer FileProvder Documentationto know morefromkvdroid.tools.emailimportsend_emailfromosimportgetenvfromos.pathimportjoinsend_email(recipient=["test@gmail.com"],subject="Hello there",body="This is kvdroid",file_path=join(getenv("PYTHONHOME"),"test.txt"))To read all SMSfromkvdroid.tools.smsimportget_all_smsfromandroid.permissionsimportPermission,request_permissions# NOQA# remember to add READ_SMS to your buildozer `android.permissions`request_permissions([Permission.READ_SMS])print(get_all_sms())# returns a tuple of message count and messagesTo read all Call Logfromkvdroid.tools.callimportget_call_logfromandroid.permissionsimportPermission,request_permissions# NOQA# remember to add READ_CALL_LOG to your buildozer `android.permissions`request_permissions([Permission.READ_CALL_LOG])print(get_call_log())# returns a tuple of call log count and call_logSince the release of Android 11 (API 30), the way file are stored became differentLicenseMIT