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).
Related
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.
I am currently planning the development of a multiplatform app, and I am not sure wich way to do it fits my requirements best, since all possibilties I could think of failed to satisfy me.
First I want to write an app for android, which should feel like a normal typical android app. So I want to use the standard actionbar and android design look and feel in my other gui elements. After finishing the android app I am planning on developing an ios app, which should have a different design, so i am going to redevelop the gui for this anyway.
But I don´t want to rewrite the other code wich represents the intelligence of the app, independent from the gui. I came up with the following possibilities:
1. Java GUI With native library
Here I abstract all the code of my app in a C++ library (since as far as I know ios supports the usage of c++ libraries too) and develop the gui android typically in java. The library would than have a function to start and would inform the gui about every change via callback functions.
Pro
I can reuse all the code that would be the same on both platforms. I just would implement the gui seperately
The design of the android gui is straightforward as I want it to be. It looks like typical android because it is typical android.
Cons
I dislike the usage of JNI very much. Especially the signature and names of the callback functions (calling java functions from c++) are not checked at compile time and require a lot of manual work. If I rename a function and forget to rework the native part I only notice this mistake at runtime.
2. Build the GUI on the native side
Here I had difficulties finding out what is possible, especially for 2.2
2.1 Use Qt
I have only a few first step experiences with Qt in general but as far as I understood i would have the following pros and cons:
Pro
Reuse most parts of the code for ios and Android. I would than redesign the gui for each platform to make them feel natural. I can´t evaluate how much qt may even assists me at doing that
Cons
I have to copy the android gui by using other qt widgets. This is more effort and I don´t know if one can replicate the android gui elements (like the actionbar) so that the user wouldn´t notice it.
2.2 Using the android framework from the native side
I dont know if this is possible at all, I wasn´t able to find this information. Can I use the class "NativeActivity" and use the android framework to build the gui and use e.g. the actionbar? If this is possible somehow it would have the pros from 1. and maybe wouldn´t have it cons?
Do you have any feedback to my ideas or maybe even new approaches I didn´t think of? How do other multiplatform apps like WhatsApp solve this problem? Do they have redundant code for each platform?
Thank you,
Tobi
I would say that it depends very much on your application requirements. By my opinion, a better solution is to develop a separate application for each platform using recommended SDK's for that platform, and implement in native C++ only the time consuming data processing algorithms.
Application runtime on mobile platforms is not so straightforward as on desktop platforms. You should take into account background and foreground processing, specific application life cycling, accessing system resources such as network, file system, etc. And all these issues do differ on iOS and Android.
Regarding possibilities that you listed.
Qt/QML is ok only in case two requirements are met:
1.1 Your application is a foregroud application without any background operations.
1.2 You purchase a commercial Qt license because only commercial Qt can be submitted to Apple iTunes app store (even GPL apps are under
question).
Using NDK Native Activities on Android with cross-platform C/C++ backend. Android NDK API offers much less API then Android Java SDK, so a lot of things you will have to implement or wrap manually. It is a hard road.
Mixing Java code and C/C++ using JNI gives you more of Android SDK API. But you should remember that an Android activity's life cycle is not somewhat that you're used to deal with when developing on C/C++.
Approach that we are using
We've been developing an application with a huge amount of cross platform functionality that should work on Windows/Linux/Mac OSx/Android/iOS. We're using the approach as follows.
Cross-platform core is written in pure C++.
We have adaptors to GUI interface for each platform.
On desktop we use Qt as it reaches all desktop platforms with minor adapting to each platform.
On iOS the GUI is built using iOS SDK with Objective-C and C++ core is linked as a Framework. Still, we had to patch our core in some way for iOS background requirements and so.
On Android we wrap our C++ core in a background process and build all the GUI using only Android Java SDK. Foreground GUI activities interact with the core via local sockets, so we don't need to bother with activities life cycling in our C++ core. But the adaptor is a litle bit complicated.
Nevertheless, both mobile platforms often require workarounds and adaptations in C++ core which add a number of #ifdef'ed branches in code for each platform.
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.
I have an Air mobile language learning app on the Google Play store that I'm happy with. It performs at 60fps and does what I need it to do.
I plan on adding more language packs and was wondering if I could use a native slide-out tray and action bar.
I have no idea if I can add any native android UI elements to an air mobile app. Does anyone have experience doing this?
you'd need a native extension to interact with OS related items. checked out this yet? http://help.adobe.com/en_US/air/build/WS597e5dadb9cc1e0253f7d2fc1311b491071-8000.html
This is technically possible using an ANE, though this is not what ANEs are meant for. ANEs are meant to give you access to native APIs, not native GUI elements. You should refrain from mixing AIR and native GUI elements. If you want to use native elements, you should switch to using native code.
If using native code is not something you wish to do, you can write your own implementation. The GUI structure is not difficult to mimic and AS3 offers a multitude of MouseEvents and TouchEvents that would allow you to properly write an AIR version of that GUI element (I've done so in the past, actually).
Another option is to use Flex or Starling or another GUI framework that offers a pre-built component for this. If you are not already using one, however, it will require you re-build your entire app.
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