Last active
August 29, 2015 14:01
-
-
Save maluta/e29dc4c2f57d1f9099e9 to your computer and use it in GitHub Desktop.
Kivy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Kivy contact and support: | |
# http://kivy.org/docs/contact.html | |
# Kivy on irc.freenode.net | |
# | |
## Kivy android build doc: | |
# http://kivy.org/docs/guide/packaging-android.html | |
# | |
## Python-for-android: | |
# https://github.com/kivy/python-for-android | |
# http://python-for-android.readthedocs.org/en/latest/ | |
# http://kivy.org/docs/guide/packaging-android.html | |
# | |
## Buildozer: | |
# $ sudo pip install buildozer | |
# https://github.com/kivy/buildozer | |
from kivy.app import App | |
from kivy.uix.image import Image | |
from jnius import autoclass, cast | |
from android import activity | |
import time | |
class Stress(App): | |
def build(self): | |
# import the needed Java class | |
self.PythonActivity = autoclass('org.renpy.android.PythonActivity') | |
self.Intent = autoclass('android.content.Intent') | |
self.currentActivity = cast('android.app.Activity', self.PythonActivity.mActivity) | |
## examples ## | |
self.calculator() | |
time.sleep(10); | |
self.browser() | |
time.sleep(10); | |
self.play_audio() | |
time.sleep(10); | |
self.image() | |
## ## | |
def calculator(self): | |
intent_calculator = self.Intent() | |
intent_calculator.setAction(self.Intent.ACTION_MAIN) | |
intent_calculator.setClassName("com.android.calculator2","com.android.calculator2.Calculator"); | |
self.currentActivity.startActivity(intent_calculator) | |
def browser(self): | |
intent_browser = self.Intent() | |
intent_browser.setAction(self.Intent.ACTION_VIEW) | |
Uri = autoclass('android.net.Uri') | |
intent_browser.setData(Uri.parse('http://www.google.com')) | |
self.currentActivity.startActivity(intent_browser) | |
def play_audio(self): | |
MediaPlayer = autoclass('android.media.MediaPlayer') | |
mPlayer = MediaPlayer() | |
mPlayer.setDataSource('/sdcard/F1_New_MMS.ogg') | |
mPlayer.prepare() | |
mPlayer.start() | |
time.sleep(5) | |
mPlayer.release() | |
def image(self): | |
intent_image = self.Intent() | |
intent_image.setAction(self.Intent.ACTION_VIEW) | |
Uri = autoclass('android.net.Uri') | |
intent_image.setData(Uri.parse("file:///sdcard/ok.png")) | |
intent_image.setClassName("com.cooliris.media","com.cooliris.media.Gallery"); | |
self.currentActivity.startActivity(intent_image) | |
if __name__ == "__main__": | |
Stress().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./build.py --dir /home/maluta/git/experimental/kivy/ --package io.github.maluta --name "3st kivy" --version 1.0 debug installd