The articles created so far are as follows.
This time, I will explain the Android output among the mobile (iOS, Android) output, which is an advantage when Kivy compares with the Qt library. From the conclusion first, it is subtle personally. It's short on the obi and long on the tasuki, or it's hard to stand behind.
Let's execute the previous Linkage with WebAPI (from sending and receiving requests to displaying results) on an Android device.
The content is almost the same as the previous code. We will introduce the changed parts as appropriate.
There are three methods, but the execution method differs depending on the purpose.
① Run on your own Android device (2) Create an APK and distribute it on Google Play etc. so that it can be used by an unspecified number of people. ③ Execute Python on android terminal using python-for-android
In case of ①, it is realized by using an Android application called Kivy Launcher. This time, I will explain using this method.
In case of (2), install a package called Buildozer on Ubuntu to realize it. In the case of windows, VM is distributed, so please use that. You can download it from the Virtual Machine section at https://kivy.org/#download.
In case of actual use, it is better to actually execute it with the post Create # 2 APK to publish Kivy application on Goole Play Store. Please refer to it.
In case of ③, the method is different from ① and ②, and the method is to actually execute the Python script on the Android device. If you search with Qpython, you will find various things.
Regarding the contents of this area, [“Using Python with android” as of 2016](http://hhsprings.pinoko.jp/site-hhs/2016/08/2016%E5%B9%B4%E7%8F % BE% E5% 9C% A8% E3% 81% AE% E3% 80% 8Cpython-% E3% 82% 92-android-% E3% 81% A7% E4% BD% BF% E3% 81% 86% E3 It is explained in detail in the article% 80% 8D /), so please read it if you are interested.
reference
Although it is a verification environment, Kivy will be 1.9.1. On the other hand, Python is ** Python 2.7 **. Looking at Kivy's official website, it is said that Android is provisionally compatible with Python 3, but as of February 2017, it is better to think that it is practically compatible with Python 2 series and not compatible with Python 3 series. The reason will be described later In addition, iOS is compatible with Python 2.7, and it seems that support for Python 3 series is currently being supported.
The models I tried are the following two types.
Android itself has unique functions for each manufacturer and model, so it may not work depending on the model and OS.
It will be the actual operation.
Kivy Launcher is an app distributed on Google Play, and by using it, Kivy on Android You can easily use a Python script that uses. The following is a simple usage.
In order to explain how to use it, we will use "touchtracer", which is a demo program distributed on the Kivy official website.
reference
Please install Kivy Lancher on Android from Play Store in advance
Select file transfer.
Create a directory called "Kivy". Create a folder under the directory and place the program.
Place the following files.
It is android.txt, but the contents are as follows
title=Touchtracer
author=Kivy team
orientation=landscape
Enter the name of the app in "title" and the author's name in "author". "Orientation" is whether to display the portrait or landscape orientation at startup. "Landscape" is landscape orientation, and "portrait" is portrait orientation.
It is a program started with Kivy Lanucher, but it seems that it can be run in the background. If you use it, you can also create alarm apps.
reference
I will actually move it.
Run Kivy Lancher on your Android device.
The waiting screen is displayed.
A list of apps will be displayed, so select the app.
After selecting, the waiting screen is displayed, and after standing for a while, the selected application can be operated on the terminal.
Let's actually run the previous app. I try to move it like "Touch tracer", but when I select it from Kivy Lancher and try to start it, it does not work well and the app itself crashes. I tried to collect the Log inside .kivy of the Android main unit. Below is an excerpt of the contents of the log.
[INFO ] Kivy: v1.9.1
[INFO ] Python: v2.7.2 (default, Mar 20 2016, 23:30:13)
It was running on Python 2.7 ... Therefore, in order to run the program I was writing last time, I had to convert from Pytho3 to Python2. Specifically, the following conversions were performed. I started Python from the 3rd system, so I didn't do the 2nd system.
Of these, the last modification of UrlRequest is explained.
The corrected part in the source is excerpted below.
main.py
from kivy.network.urlrequest import UrlRequest
import urllib
class AddSearchBookForm(BoxLayout):
def search_book(self):
set_title = urllib.quote((self.search_input.text).encode('utf-8'))
req_url = "http://iss.ndl.go.jp/api/sru?operation=searchRetrieve&query=title%3d%22{0}%22%20AND%20from=%22{1}%22&maximumRecords={2}&mediatype=1".format(set_title, set_fromdate, set_maximum_records)
res = UrlRequest(req_url, self.gotBooklists)
def gotBooklists(self, req, results):
result_records = result_parse(results)
Regarding UrlRequest, there are two features associated with this modification.
Looking at the API reference of UrlRequest, the specifications are as follows.
req = UrlRequest(url, on_success, on_redirect, on_failure, on_error,
on_progress, req_body, req_headers, chunk_size,
timeout, method, decode, debug, file_path, ca_file,
verify)
First, the URL needs to be a% string, so I converted it to a% string with urllib and put it in the first argument. Also, the req of the value returned at runtime stores the POST return result from the url, but due to asynchronous communication, the result is not returned from the server and the value does not come in immediately, so the program advances. It will be. Therefore, if it is left as it was last time, there is a problem that the processing of the POST result does not go well. It is necessary to set the process (method) when the POST result from the server side is returned in the second argument on_success, or use wait () for the return value and wait for the return result to be returned. .. This time, using the former method of using on_success, gotBooklists () is set to on_sucess, and the process of parsing the result to gotBooklists () and performing formatting is executed.
reference
The program could be executed on Kivy Lancher when the operation was performed with the support of Pytho2 system.
Regarding Japanese input, IME did not open when inputting full-width on Windows OS, but IME opens when inputting Japanese on Android devices and you can input comfortably.
I won't use it this time, but Kivy can do Android-specific JAVA APIs by using Plyer and Pyjnius. By using this, you can start the camera in the app, take a picture or send an email. Standard functionality in Android apps can be achieved using Plyer or Pyjnius.
I will give the article of the person who is actually used in Japan and the link of the official website
I haven't tried iOS, but it is possible to develop iOS apps. The code is only compatible with Python 2 series, not Pytho 3 series. It seems that you can create a project for Xcode using a function called toolchain and build from that project.
reference
Regarding iOS specific API, it seems that this can also be used in the application by using Pyobjus.
reference
In Japan, Professor Haraguchi of Otaru University of Commerce creates a Kivy app and puts it on the App Store. Dr. Haraguchi is also one of the key members of the translation of Kivy's official manual (https://pyky.github.io/kivy-doc-ja/).
reference Otaru University of Commerce Haraguchi Laboratory
To use a non-standard Python library such as Matplotlib on mobile, you need to use an add-on function called Kivy garden.
reference
[Graph in kivyLauncher environment (+ About kivy garden)](http://hhsprings.pinoko.jp/site-hhs/2016/08/kivylauncher-%E7%92%B0%E5%A2%83%E3%81 % A7% E3% 82% B0% E3% 83% A9% E3% 83% 95-kivy-garden-% E3% 81% AB% E3% 81% A4% E3% 81% 84% E3% 81% A6 / )
If you look at the Wiki on the official website, you will find a list of app projects created using Kivy. If you look at this, you can see what kind of apps you can actually create.
reference
I was able to actually run an application that is displayed in cooperation with the server side on an Android device. Regarding Android apps, if it is a 2D image-based app, I think it is possible to develop most things such as card-based social games and search apps.
Personally, whether or not to use Kivy when creating an Android app is a delicate point. I think that the mainstream of releasing an Android application is to consider the development of the iOS version as well. In that case, development with Pytho2 system is a prerequisite, but it takes time to handle Japanese (multibyte characters). Since there is no community in Japan, I think it would be better at this point to develop multi-platforms using C # such as Xamarin and Unity, or to develop with Andori native. At least in combination with the number of Python engineers in Japan, I don't think it will be actively adopted.
I think that the story will change again if Python3 support is officially released on iOS and a simple preview application like Kivym Lancher is made, but at this stage it will be evaluated like this.
I explained how to use Kivy four times. Animation is a major feature that I haven't discussed yet, but I'll take the opportunity to touch it. If you read the explanation so far, you can develop a general application, or you can get started. I also think that Kivy has a vague idea of what libraries can and cannot do.
I think the advantages and disadvantages of Kivy are as follows.
advantage
Disadvantage
Based on this, I hope you will consider whether to use Kivy or not. Also, since bugs are open source, they will be improved by raising issues and requests, improving and committing, so I think that it depends on the user.
reference
Kivy is still actively interacting on github and I think it has potential as open source. I hope you read this article and would like to use Kivy.
Recommended Posts