I'd like to make an Android app, and I prefer to not have to step out of my comfort zone which is Python. I heard that the Kivy package can make Android apps, but I heard that it likely doesn't have the full Android UI functionality that you could access using Java.
My desired app should have a persistent notification, that's visible even when the screen is locked, and which has 4 buttons on it, which should respond to pressing and holding them. Is that possible with Kivy? Can anyone point me to the functions or classes that I'd use to make this notification and buttons?
I don't know answer for this question, but I have few thoughts you may find useful.
When it comes to calling platform specific API in Kivy it's almost always being done with calling native Java function from Python using pyjnius module. There're not much places where it's actually happens in Kivy: in python-for-android android recipe (source) that provides some basic stuff and plyer project that tries to provide high-level cross-platfrom API to some platform functionalities.
I guess that's all you have now and I didn't see there something that does what you want. I guess only way left is:
Investigate Android API
Write Java solution
Use it from Kivy/Python by pyjnius
But note that if most part of your app is Android API related you probably wouldn't need Kivy at all: you can just avoid third step in this case.
Related
How should I go about making my kivy application work on a Samsung Galaxy S7? How much of the code do I have to change to make it work? Do I get features of the phone like handling "back" or vibration? Currently my code has two files, a calc.py file which handles all the back-end calculations that are given from main.py which is a KivyApp class which returns my main class.
There are also images that are used in the same folder from main.py
If there is a better place to post this please tell me
Thank you!
You are on the right place to ask this.
First you have to convert your app in a apk using python-for-android, the easiest way is to use buildozer.
You'll probably need to make your code compatible with python2, apparently there is a new buildozer that allow pure python3, but the classic one work on python2.
For the images, if you want to keep them here, it will work, but I recommend that you put them on a "img" repo.
For the vibrations, and other android behaviors, there are 3 way to do this:
pyjnius that let you use every component you want by creating a binding to the android class.
plyer that have already create you a easy binding but don't have all the fonctionnalities.
python-for-android api, that is also really easy.
I recommand you check if you can do what want first with python-for-android or plyer, and if you can't, give a try to pyjnius.
Does anyone have experience with NativeScript and can compare it to developing native apps, especially for Android?
I have read all these articles:
FIRST THOUGHTS ON NATIVESCRIPT
SECOND THOUGHTS ON NATIVESCRIPT
Introduction to Native Script – Is It Worth Your Time?
My Experience Developing with Telerik NativeScript
I know especially three of them may be outdated. But I want to ask all of you developers:
How is your experience with NativeScript?
Are there any Android-Components you cannot use? Which are these ones?
Is styling really so limited?
Do apps really look so different at runtime as in the mockup as in the pictures of the first article referenced above?
Does loading of native Android objects into JavaScript Code always work correctly?
Does NativeScript generate Java-Code for Android-Platform out of the NativeScript code I write?
Is it possible to modifiy this code if I want to use some native-only features? What if I want to make UI changes then? Do I have to regenerate the code and do I miss my native extensions then?
Very glad to see that you are evaluating NativeScript to eventually use it in present and future projects.
I'll try to condense answers to a few of the questions into one, as they really are mostly related.
Skipped.*
That depends on what has already been exposed through a custom view/plugin or module. The core-modules that every NativeScript app comes with contains the most basic of wrappers for both Android and iOS under a common API. There are plugins (nativescript npm modules) that provide additional wrappers on native android views (nativescript-telerik-ui for one, nativescript-carousel), most of which are created by the NS community.
As RexSplode mentioned before me - it's mostly the platform that imposes certain limitations. NS uses CSS to declare style, but you can also access the native components and manage their style and appearance programatically if what you need isn't readily available out of the box.
First I'd like to note that the first 3 articles you've linked are over a year old now, and trust me, NativeScript has evolved a lot since then. With all the available components (remember the npm modules I mentioned earlier?) there's a good chance that you will get a close to 1:1 similarity to a well-styled native Android mockup.
At build time metadata is generated for the Android/Java public API used in the project. When the JavaScript Engine (V8) fires up, that metadata is loaded into memory, prototype chains are constructed, and callbacks are attached, so that when you call new android.widget.Button(); in your JavaScript code, the proper virtual machine instructions will be called, and a native button will be created. Static methods are accessed similarly, check out the official docs to get a better understanding of how it all works.https://docs.nativescript.org/runtimes/android/advanced-topics/execution-flow
and 7., and a cont. of 2. Java code, or rather compiled Java code is generated whenever you wish to extend a native Android class that isn't available already in a module or in the native Framework. Extending classes is very similar to how you would do it in Java - you extend a class, and create new implementations of interfaces. That means that you won't have to open Android Studio to create a new class, build it into a native plugin and then add it to your project, since you can do it all in your NativeScript code using JavaScript/TypeScript. https://docs.nativescript.org/runtimes/android/generator/extend-class-interface
Disclaimer: I am on the NativeScript Engineering team
I investigated the Native Script a little and my colleague at work writes an app with it, so I can offer you a bit of information that I have.
1. skipped
There are limited amount of components you can use with native script out of the box. However, if you have a native-java developer who can write a wrapper for you - you can use everything.
It is limited to the platform you are using. Android itself has a lot of style limitations which cannot be easily overwhelmed.
don't know
It works a little different. Your JS object, or rather widgets are translated to java code. So with the items from the box - yes, they are okey. If you write a wrapper for your custom component, then all is up to you.
Yes it does.
No, the code is generated, how are you going to modify it? Changes will be undone on the next build. However, you can write a native module for your application and use any features you want. It is like defining an interface, which you can use in JS code afterwards.
As we all know, when developing an Android app in native Java, we use activities. I was wondering that, in developing Android apps in Python(with Kivy), does Kivy implements activities for the apps in itself or not? because I don't see any activity implementation on the sample codes.
If it doesn't implement activities, Do we lose performance or any functionality in the application compared to coding in native Java?
Simply put, you can use Activities (starting them using pyjnius), but not really define them, at least, it's not usually the way one work with kivy.
Kivy doesn't adjust its way of working for targetted platform, it uses its own systems, and make them work there. For what i know the advantages of separating Activities on android is just a way to make your code more neatly organized, and doesn't imply performance changes. It can allow you to start your app in various ways (from a share, for example) but you can do that with p4a/buildozer too, by dispatching messages about the intent, if you need to. With kivy, you'll organise your code like you would do for any python project, using modules.
Kivy is a great tool for developing Android Apps. The best advantage of using Kivy is that it is cross platform and the same project can be used to publish apps on mutti-platforms.
However , it has some performance related disadvantages(as do most cross-platform tools like unity , cocos etc). If you're developing only for Android , I'd suggest taking a look into development tools which use Java. This will help create a smaller APK file which in turn helps in better user retention.
I guess you are real loyal fan of Python, but I have to tell you about its advantage and disadvantage.
Advantages
Pure python and its almightiness is in your hand.
Relatively simple to deploy with buildozer without any need to dive too deep into the details of particular platform.
You can run your app on desktop also, so there is no need to install some extra emulators/VMs to get it work
Disadvantages
Not that much information in Internet, even on stackoverflow
Pretty messy documentation
No obvious way to test the application
Not obvious machanisms of placing widgets, especially in built in layouts, which causes situations like: you want place widget in the center of it's parent, but kivy places it anywhere but not where you want it to be.
Official examples are quite ugly, so you may get false vision of how your application could look like.
Is it possible to program and build an Android Homescreen widget without doing it in Java?
For example I imagine it doing this via Cordova/Phonegap or Python Kivy? Is it possible with one of these? Or is there even another way?
You can interact with java from python using pyjnius (a kivy subproject, but it doesn't depend on kivy and can be used without it), including on android calling the apis to create and position native android widgets. For instance, kivy-gmaps is a kivy application that displays and controls a native google maps widget through kivy. I think I've also seen simple examples with webviews, a native android video player, and basic native popups.
Pyjnius is very powerful, and people have raised the possibility of using it to create native java-widget applications via python alone (as opposed to kivy's own opengl interface), but in practice I think there are some technical and practical barriers to overcome and I haven't seen signficant work in that direction. That is, it may well be possible, but nobody has done more than examples like the above yet.
(I assume that by 'Android widget' you mean the widgets of the native java api. Of course kivy has its own widget system that works fine, and the html options like cordova also let you make apps without touching java).
I have some issues in working with Android layouts and make them adapt for all screen sizes..
I have found that there is an alternative solution : Android Bootstrap http://www.androidbootstrap.com/ for that and provide nice UI components (buttons etc...).
Since I'm developing natively, is this kind of frameworks won't make the App runs slower ?
Is this only a UI framework like for the web (Bootstrap from twitter) ? if not, can we use with it everything in Android (Camera, micro etc...) and Can we include some Jars like Zbar ?
Thank you.
I have found that there is an alternative solution : Android Bootstrap
It is not an "alternative solution". You still will need to be "working with Android layouts and make them adapt for all screen sizes", because Android Bootstrap does not change much related to that.
and provide nice UI components (buttons etc...)
It uses the same Android widget set that all other Android apps use.
is this kind of frameworks won't make the App runs slower ?
There is nothing in an Android Bootstrap project that would necessarily make the app significantly slower.
Is this only a UI framework like for the web (Bootstrap from twitter) ?
It is not even that. It is a starter project that demonstrates how to tie together a dozen or so open source libraries for Android app development. You can think of it as an extended version of the templates used to create new applications and activities in Eclipse or Android Studio.
This is not to say that Android Bootstrap is bad -- far from it. However, it does not resemble your description.
can we use with it everything in Android (Camera, micro etc...)
I have no idea what "micro" is with respect to Android. Since you are writing an Android application, just like any other Android application, you can use it with whatever parts of Android you choose to.
Can we include some Jars like Zbar ?
I see no reason why not.
It is very common for such templating engines not to have exactly most components you need. for android it is basicallly about adding support third party libraries to get the exact experience you need.
Thus you may want to consider adding more or lacking parts by leveraging some external libraries like those from HERE