Skip to content

Commit 6878ded

Browse files
Nik KleverNik Klever
Nik Klever
authored and
Nik Klever
committed
Changed the structure to include the action module (not tested) and to source
older things out into a separate paragraph
1 parent 0c6d37a commit 6878ded

File tree

1 file changed

+123
-41
lines changed

1 file changed

+123
-41
lines changed

docs/source/android.rst

Lines changed: 123 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,15 @@ screen:
184184
(Source of the Compass Windrose: `Wikipedia <http://en.wikipedia.org/wiki/Compass_rose>`__)
185185

186186

187-
API
188-
---
187+
Android API
188+
-----------
189189

190-
android
191-
~~~~~~~
190+
Hardware
191+
~~~~~~~~
192192

193-
.. module:: android
193+
This module is built for accessing hardware devices of an Android device
194+
195+
.. module:: Hardware
194196

195197

196198
.. function:: vibrate(s)
@@ -264,6 +266,122 @@ used to enable/disable the sensor and to read the sensor
264266

265267
(SSID, BSSID, SignalLevel)
266268

269+
Action
270+
~~~~~~
271+
272+
This module is built to deliver data to someone else.
273+
274+
.. module:: Action
275+
276+
.. function:: send(mimetype, filename, subject, text, chooser_title)
277+
278+
Deliver data to someone else. This method is a wrapper around `ACTION_SEND
279+
<http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND>`_
280+
281+
:Parameters:
282+
`mimetype`: str
283+
Must be a valid mimetype, that represent the content to sent.
284+
`filename`: str, default to None
285+
(optional) Name of the file to attach. Must be a absolute path.
286+
`subject`: str, default to None
287+
(optional) Default subject
288+
`text`: str, default to None
289+
(optional) Content to send.
290+
`chooser_title`: str, default to None
291+
(optional) Title of the android chooser window, default to 'Send email...'
292+
293+
Sending a simple hello world text::
294+
295+
android.action_send('text/plain', text='Hello world',
296+
subject='Test from python')
297+
298+
Sharing an image file::
299+
300+
# let's say you've make an image in /sdcard/image.png
301+
android.action_send('image/png', filename='/sdcard/image.png')
302+
303+
Sharing an image with a default text too::
304+
305+
android.action_send('image/png', filename='/sdcard/image.png',
306+
text='Hi,\n\tThis is my awesome image, what do you think about it ?')
307+
308+
Further Modules
309+
~~~~~~~~~~~~~~~
310+
311+
Some further modules are currently available but not yet documented.
312+
Please have a look into the code and you are very welcome to contribute to
313+
this documentation.
314+
315+
316+
How it's working without PyJNIus
317+
--------------------------------
318+
319+
The whole Android API is accessible in Java. Their is no native or extensible
320+
way to access it from Python. The schema for accessing to their API is::
321+
322+
[1] Cython -> [2] C JNI -> [3] Java
323+
324+
#. ``android.pyx`` is written in `Cython <http://cython.org/>`_: a language
325+
with typed informations, very close to Python, that generate Python
326+
extension. It's easier to write in Cython than CPython, and it's linked
327+
directly to the part 2.
328+
#. ``android_jni.c`` is defining simple c methods that access to Java
329+
interfaces using JNI layer.
330+
#. The last part contain the Java code that will be called from the JNI stuff.
331+
332+
All the source code is available at:
333+
334+
https://github.com/kivy/python-for-android/tree/master/recipes/android/src
335+
336+
337+
Example without PyJNIus
338+
-----------------------
339+
340+
::
341+
342+
import android
343+
344+
# activate the vibrator
345+
android.vibrate(1)
346+
347+
# read screen dpi
348+
print android.get_dpi()
349+
350+
351+
352+
Old Version
353+
-----------
354+
355+
.. note::
356+
357+
The following is from an older version and the documentation for this
358+
part is currently not updated. Nevertheless it is included here for history
359+
and further development aspects.
360+
361+
362+
android
363+
~~~~~~~
364+
365+
.. module:: android
366+
367+
.. function:: check_pause()
368+
369+
This should be called on a regular basis to check to see if Android
370+
expects the game to pause. If it return true, the game should call
371+
:func:`android.wait_for_resume()`, after persisting its state as necessary.
372+
373+
.. function:: wait_for_resume()
374+
375+
This function should be called after :func:`android.check_pause()` returns
376+
true. It does not return until Android has resumed from the pause. While in
377+
this function, Android may kill a game without further notice.
378+
379+
.. function:: map_key(keycode, keysym)
380+
381+
This maps between an android keycode and a python keysym. The android
382+
keycodes are available as constants in the android module.
383+
384+
267385

268386
android_mixer
269387
~~~~~~~~~~~~~
@@ -316,39 +434,3 @@ It has several differences from the pygame mixer:
316434
The android_mixer module hasn't been tested much, and so bugs may be
317435
present.
318436

319-
320-
How it's working without PyJNIus
321-
--------------------------------
322-
323-
The whole Android API is accessible in Java. Their is no native or extensible
324-
way to access it from Python. The schema for accessing to their API is::
325-
326-
[1] Cython -> [2] C JNI -> [3] Java
327-
328-
#. ``android.pyx`` is written in `Cython <http://cython.org/>`_: a language
329-
with typed informations, very close to Python, that generate Python
330-
extension. It's easier to write in Cython than CPython, and it's linked
331-
directly to the part 2.
332-
#. ``android_jni.c`` is defining simple c methods that access to Java
333-
interfaces using JNI layer.
334-
#. The last part contain the Java code that will be called from the JNI stuff.
335-
336-
All the source code is available at:
337-
338-
https://github.com/kivy/python-for-android/tree/master/recipes/android/src
339-
340-
341-
Example without PyJNIus
342-
-----------------------
343-
344-
::
345-
346-
import android
347-
348-
# activate the vibrator
349-
android.vibrate(1)
350-
351-
# read screen dpi
352-
print android.get_dpi()
353-
354-

0 commit comments

Comments
 (0)