How to install a PWA with Android WebView/TWA - android

Scenario
I have an existing native android app in which I want to add some new features. These features have already been implemented as a PWA because some users needed to use them directly from the web.
I want to be able to open the PWA with an Android WebView (as if it was part of my native application) and install it 'locally'. With 'locally' I mean that the PWA should not be visible as an app in the phone, it would just be part of my existing native app. In a way, what I'm trying to achieve is a king of "plugin" system, where I could have extra features that the user can install to the native app.
Where am I stuck?
Opening the PWA with a WebView is fairly straight forward. The part that I am unable to do is installing the PWA. Maybe TWA could solve this issue, but I am not sure it is meant for that.
Moreover, ideally I would like to keep everything in a Fragment since I would like to have the toolbar and others created by the native app (that is why I've leaned more towards using WebView instead of TWA).
EDIT---------------
After messing around I was able to understand that it actually gets installed with WebView. Since I haven't been able to find any information about how it works online I've been researching it on my own.
First of all ServiceWorkerController is only available from Android 7 (24). I haven't been able to test if with Android 6 this can work or not due to the fact that I don't have any phone with that version and I can't update the WebView apk of my emulators for some reason.
Then, I found out that the webpage crashed in my newer emulators because the WebView apk installed was too low and didn't support some newer features. So another thing to take into consideration the WebView version installed. This apk gets installed separately from the Android version (it's as if it was an app on your phone). The solution to this is to just use a real device, because the apk is usually always up to date.
As you can see in the following picture the PWA gets installed inside the app folder and it also keeps all the info (databases, localstorage, sessionstorage, etc.) in there.
It is unclear how this data is handled (I created this question) but it appears to be at least in the following cases:
WebStorage.Instance.DeleteAllData()
App uninstalled
App Data Cleared
Clearing the Cache of the app doesn't delete the persistent data.
So now I would say that the question would be:
From which Android Version does the Service Worker install? Just from the Android version that has support for the webview apk version that supports Service Workers?
Does it depend at all on ServiceWorkerController? Or is it just a utility class to have more control over what happens?

Related

Load hybrid iOS and Android mobile app from server

I am using Ionic and Cordova to build a mobile app which will go on the iOS and Android stores. I have done this many times, and I really hate the process of having to update the app (specifically with Apple).
Would it be safe to dynamically load all of my templates and controllers from my server when the app loads, potentially caching them or having a server call to check if there is a new version? Basically, I would have all images and styles saved locally to the phone, but load the templates and controller code on app load.
And, if it was ok to do programmatically, are there any rules against this in Apple or Android's terms of use?
This is possible and there are tools like Cordova Hot Code Push to help you accomplish it. As long as you don't use this to break other app store review rules or significantly change the purpose of your app it's fine with Apple.

Track Navigation in Android Webview

I'm wondering if there are any good tools for analyzing the navigation of an android application within a web view or within something like Cordova.
If an android application is changing states, is there a good tool to determine, for example the underlying URL that the application is currently on or was previously on? I'm doing an analysis of an already built android application and part of the requirements is to see what URL's the application navigates to but this isn't visible from the application itself. I only have the APK.
Perhaps ADB has this functionality or there are some third party tools available?
In my experience, the best tool is Chrome inspector: just type chrome://inspect in Chrome's address bar and connect to your device. Please note that your APK must be compiled in debug mode.

How to run application without activity in android version 4.X

Actually my application is running a service only when boot completed. it runs fine in android 2.2.
But when i install 4.0 android supported device it does not work. even after installation application is not running. I know after 3.X android have a change that application is not running when installed.
So how only service oriented application run in > 3.x android version ?
any help is appreciable.
How to run application without activity in android version 4.X
You don't.
First, you pretty much always need an activity:
You need to have your copyright notice somewhere
You need to have your license agreement somewhere
You need to have your disclosures of other open source components that you are using somewhere
You need to provide access to technical support, even if it is just a link to your Web site, somewhere
You need to allow the user to configure the behavior of the service somewhere
You need to give the user access to online help somewhere
You want to avoid the one-star ratings that come from apps that do not have a launcher activity, when the user installs the app, then cannot figure out how to run the app, and thinks that you are a complete moron as a result
This is above and beyond the technical requirement for a component of your app to be manually started before any manifest-registered BroadcastReceivers will work.

iPhone/Android webapp wrapper

I work at a large company that is looking at building apps for internal use only (iPhone/iPad). We are looking for a SIMPLE way of creating apps that essentially are just a web browser with a predefined URL and no address bar/tabs, etc. Essentially a very dumbed down browser with a custom logo. What is the easiest way to accomplish this?
We would obviously be distributing these oursevlves and they wouldn't be available in the App Store, so app guidelines aren't an issue. We are on Windows boxes and are Java/Web developers so we'd rather not get into too much C sharp if at all possible, fyi. Basically it'd be nice if the tool (if one exists), were to allow us to give it a URL, an icon image, and it builds the app from there.
And while we are starting out with Apple devices, we need to be cross platform compliant with whatever tools we use because I can imagine the day when they decide to buy Android or WindowsPhone devices later on.
MobiOne? PhoneGap? Appcelerator Titanium SDK? Can either of these do what we need? Something else?
A big 'No' for MobiOne. I bought it for 99 dollars. As they advertised, I was able to create a static app within hours. But that's pretty much what MobiOne can do. The moment you start using html, javascript or even audio, all sorts of problem seem to creep up. And there is no support in their forums either. My basic question about using the audio player remains unanswered for a month now.
Here is the worst part:
The tool has a poorly built emulator. Often times, my app worked fine in the emulator but failed to run when deployed to a real device. And at times, i have seen the vice versa too.
Since then, I switched over to PhoneGap(which is free). It took me 2 days to just set my environment right. But once I had the environment setup, it took only minutes to deploy my app in to a virtual device.
Looking at your requirement, I would say that your safe bet is PhoneGap.
I don't have a working knowledge in Titanium but I read in a lot of forums that it supports less platforms when compared to PhoneGap. Titanium seems to give a more native feel to the app but that also means you cannot port it to multiple platforms without changing the code.
Apple may reject your app if all it does is wrap a web site in a WebView. You need to have more functionality in your app than just loading a web page.
From the app review guidelines for iOS:
2.12 Apps that are not very useful, are simply web sites bundled as apps, or do not provide any lasting entertainment value may be rejected
You would need to add additional screens to the app like an about page and a contact us page in order for your app not to be rejected.
As you say you know JavaScript, look into appcelerator.com it allows you to build cross platform apps and only writing your code once.
I would re-evaluate your reason for wanting to create these projects as an app in the first place. What app functionality do you want that you don't have now with your web page? You didn't mention anything in your question that would indicate this needs to be an app.
On Apple devices, you could create an icon that points to a web site. You could define the pages in a way that hides the address bar. Lastly, the web pages could easily be cross-platform already.
Wrapping this into an app would just possibly complicate the process. You may need to deploy updated app code to the device, where a refresh in a browser works just as well.

How can I determine if an Android app is built with a web view?

I am new with Android programming and I am investigation the various approaches to built an app. Right now I am learning native app development using Eclipse and ADT but I also wish to look at webviews and their possibilities. Either done directly using Eclipse/ADT or via tools such as PhoneGap.
I know the pros and cons of webviews, but to better learn under what circumstances they are appropriate and likewise where they fail, I would like to analyze various existing apps and check if they are built upon a webview or programmed natively.
The thing is that I sometimes have a feeling that a given app is a webview because the look and feel is a bit different, but on the other hand perhaps the developers simply chose that look for some reason.
So, can I somehow determine if an app is made from a webview?
Try the following option that exist in different phones like S3:
Go to: "setting" -> "Developer options" -> check "show layoutboundaries"
I think that if the app is done native, the boundaries will be displayed for all the objects, while if it is a webview, no boundaries are displayed.
hope that will help...
Without too much trouble, you can look inside the apk and determine if the app uses WebView:
A. find the apk:
Installed apps are on your Android device in the folder /data/app and has domain-style filenames
/system/app has android apks
B1. If the Android device where the apk is installed is rooted, you can explore the apk on the device using for example the app Solid Explorer.
B2. Alternatively, you can enable debug on your Android device and copy the apk to a computer using adb (apks are actually zip archives.)
C. Then for a WebView app:
C1. Inside the apk, in folder assets, there are typically files with .html extension. These are Web pages displayed in the WebView.
C2. Inside the apk, in file /res/layout/main.xml (or perhaps views by other names with .xml extension), the phrase "WebView" is used.
Many slow apps are in fact not WebViews :)
If you have the source code to the app, look at the source code.
If you do not have the source code for the app, see if it has an About menu or something that indicates what they used, or see if the Web site for the app discloses how they wrote it.
I would venture that 95% or more of Android apps are native. Of the remaining 5%, the vast majority that use WebView do so to simply wrap an existing Web site but have it "be an app" for marketing purposes. While PhoneGap is a very slick tool, IMHO only a small percentage of Android apps on the Market use it or similar WebView-based technologies (e.g., Rhodes). That percentage will likely grow over the next few years, particularly as people use PhoneGap to do cross-platform development, or wrap an HTML5 Web app for offline use.
This works for me:
Install & open the app
Uninstall WebView by running adb uninstall com.google.android.webview
If the app closes after uninstalling WebView then it's using WebView
I'm assuming that you have an updated version of WebView and not the stock version that comes pre-installed on the device
To check if WebView has been updated run adb shell dumpsys package com.google.android.webview | grep versionName and there should be two different versions, one is the current version and the other is the stock version.
A certain way (but perhaps more complicated) is to root the device and install a Proxy (like https://play.google.com/store/apps/details?id=org.proxydroid&hl=en). Then you can observe HTTP traffic and try to determine if the app is using a WebView.

Categories

Resources