I've an app which is basically a book, written in HTML deployed with phonegap to Apple Store and Google PlayStore.
I will soon updating my app in the store but I would like to officer "in-app purchase" for some of the sections of the book.
I've gone through several plugins in the market but could not figure out how to unlock the pages. The procedure in my app should be,
User taps on section
Section prompts a text to request payment
User completes payment (either consumable/annual subscription or non-consumable/life time)
User able to read rest of the HTML pages in the app.
I really much appreciate your comments/guidance to help. Thank you!
you can check your url in the webview WebViewClient.
so if you want to block page then show inapp purchase dialogue else you can show that page
wb_webview = findViewById(R.id.wb_webview);
wb_webview.setWebViewClient(new web_client());
WebSettings settings = wb_webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
private class web_client extends WebViewClient {
private web_client() {
}
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
//check page you want to show
if(show){
wb_webview.loadUrl(str);
}else{
//inapp purchase dialaug display
}
return true;
}
}
may be it`s work
Related
I am developing an android application where i have redirected to https://m.facebook.com/ inside a web-view.
What is required?
I want to check the login status, once login is successfully done and user is on home page i want to handle visibility of some views and redirect webview to another URL which is facebook video link.
What i have tried?
I have tried checking URLs in onLoadResource and found some URLs that we get on successful login and logout. But its still not enough as Facebook login can be done via different methods (i.e by number, by email, by already saved account etc).
To check Logout:
fun isFacebookLoggedOut(url: String?): Boolean {
return url?.startsWith("https://m.facebook.com/?stype=lo&jlou")!!
}
To check Login:
fun isFacebookLoggedIn(url: String?): Boolean {
if (url.equals("https://m.facebook.com/login/save-device/?login_source=login#_=_") || url.equals(
"https://m.facebook.com/login/save-device/cancel/?flow=interstitial_nux_retry&nux_source=regular_login"
) || url?.contains("https://m.facebook.com/login/device-based/validate-pin/?refid=")!!
|| url.startsWith("https://m.facebook.com/login/device-based/login/async/?") || url.startsWith(
"https://m.facebook.com/login/account_recovery/name_search/?flow=initiate_view&ls=initiate_view"
)
) {
return true
} else {
return false
}
}
This works in some cases and on some devices but there are scenarios when user log in with contact number, or saved account which goes through different phases like entering credentials then verifying any code if browser is new and so on.
Is there any method or proper way to track login status thats perfect for each scenario and each device?
Can somebody please help me out with this.
Any help will be appreciated
You can visit this link to have all the detailed information to implement the Facebook SDK and be able to login to Facebook throught your app.
I have an android application that has native framework and content itself is presented in web format and in webview. The meaning of the application is to allow users to use the device using predefined
services that may require autentication.
How ever when I try to clean up the webview caches after user has completed his/her tasks the webview will remember everything and all e.g. login credentials are in place, history remains etc.
I have tried the following to do the clean up without any success, what I am missing in this ?
(wvfo if the overlay fragment in which the webview is that each service is using)
wvfo.getWebView().clearCache(true);
wvfo.getWebView().clearFormData();
wvfo.getWebView().clearHistory();
wvfo.getWebView().clearMatches();
// wvfo.getWebView().setWebViewClient(new WebViewClient());
// wvfo.loadUrl("javascript:document.open();document.close();");
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
wvfo.destroyWebview();
Any ideas what is wrong with this and why the history doesn't get cleared ?
Thanks in advance
Yes, You have to delete webview default DB also. Check the below code.
static void clearWebViewAllCache(Context context, WebView webView) {
try {
AgentWebConfig.removeAllCookies(null);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
context.deleteDatabase("webviewCache.db");
context.deleteDatabase("webview.db");
webView.clearCache(true);
webView.clearHistory();
webView.clearFormData();
clearCacheFolder(new File(AgentWebConfig.getCachePath(context)), 0);
} catch (Exception ignore) {
//ignore.printStackTrace();
if (AgentWebConfig.DEBUG) {
ignore.printStackTrace();
}
}
}
I hope, this will help you.
Happy codding...
I have been working on a hybrid android application. Currently a WebView in our application is pointing to an AngularJS 1.5.7 application. When the user hits a button inside of the application that changes the route I was expecting the shouldOverrideUrlLoading function to be called inside of my WebViewClient. However, this is not the case. It looks like shouldOverrideUrlLoading does not get hit on Angualar route changes.
This being the case I have gone down the following rabbit holes:
onPageFinished - Overriding this function in the WebViewClient works, however, it is not being called until after the new route is getting hit. Which is adding to the application loading time and creating a choppy experience. ` #Override
public void onPageFinished(WebView view, String url) {
if (url.endsWith("/#/")) {
signOut();
} else if (url.endsWith("/login")) {
// TODO: show some sort of failure message?
Log.i("Login Route", "The webview just attempted to go to the login route.");
signOut();
} else if (url.endsWith("/security")) {
Intent intent = new Intent(getApplicationContext(), SecurityActivity.class);
startActivity(intent);
}
}`
shouldInterceptRequest - Overriding this function allows you to watch for requests. However, by the time the requests go out from the AngularJS application the web view is showing a new route once again providing a choppy user experience.
onLoadResource - same
JavaScriptInterface - Currently I have set up a JavaScript interface to watch for window.location changes. This seems to catch the route changes quicker than any of the above options, however, there is still a glimpse quick flicker of the web page I do not want to do go to. You can find how to do Javascript bridging on this post
Any suggestions would be greatly appreciated! Thanks.
I am creating an android application in xamarin. I am using a web view to display a website. After user login website create a cookie and should store in web view. There are two web view in app, One web view is displaying the pages and if there is any text box in the page that page is opened in second web view.
So now when user tries to login, second web view is opened(as login page contains text box), after user enter details and click next button, the second view is closed and next page is opened in first web view. After login a cookie is created and stored in web view and when user open the app next time its doesn't asks for login. This is what should happen.
The problem is, if the user enter details and after clicks the next button(next page is loading in first web view) and immediately quits the application then start app again then cookies does not exists and app asks for login again.
After login I am reading the cookie value on page finish event of webview and displaying in toast. If i quits the app after login, i gets the cookie value in toast but when i starts the app again the cookie doesn't exists anymore and it asks me for login again
public override void OnPageFinished (WebView view, string url)
{
try
{
if (view.Url == Urls.URL_INDEX)
{
var cookieManager = CookieManager.Instance;
if (cookieManager != null)
{
//getcookie string from the url
string cookie = cookieManager.GetCookie (view.Url);
if (!string.IsNullOrEmpty (cookie))
{
string[] cookies = cookie.Split (';');
foreach (var newcookie in cookies)
{
if (newcookie.Trim().StartsWith (Constants.COOKIE_NAME))
{
string cookieValue = newcookie.Substring (newcookie.IndexOf ('='));
Toast.MakeText(activity,cookieValue,ToastLength.Short).Show();
}
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine ("Exception in storing cookie in Home Activity : "+ex.Message);
Toast.MakeText (activity, "Exception : " + ex.Message,ToastLength.Long).Show();
}
}
I don't know why this is happening, please help.
The cookies are stored in RAM to get the best performance and synced every five minutes to the permanent storage. You'll need to manually force CookieSyncManager to sync the cookies in your OnPageFinished method so that they're still available when you start the application again. Refer to the CookieSyncManager documentation for more details.
I have a simple native Android app that is a webview of a website, effectively to make the mobile-ready site native-like if you will. The website already has Google Analytics installed.
What might be a good way to track which visitors are using the app?
I could adding Android Native App Tracking, but I presume that would
double track the users. Unless it's smart enough to connect the visits?
I could pass custom get variable to the site that maybe adds a custom
attribute to the tracking for native app users. But that doesn't
sound very clean.
What might be best for tracking? I feel there's got to be an obvious answer I'm missing.
that should help you:
Now getting back to the Analytics tracking of this web app, I used the code provided by Google here.
So the code becomes somewhat like this.
public class myWebApp extends Activity{
Webview mWebview;
GoogleAnalyticsTracker tracker;
protected void onCreate(Bundle savedInstanceState) {
tracker = GoogleAnalyticsTracker.getInstance();
// Start the tracker in manual dispatch mode. The following UA-xxxxxxx-x code must be replaced by //your web property ID.
tracker.startNewSession("UA-xxxxxxx-x", this);
mWebview = new WebView(this);
mWebview .setWebViewClient(new myWebViewClient());
mWebview .loadUrl("file:///android_asset/www/index.html");
private class myWebViewClient extends WebViewClient
{
//After the user visits a particular page, send the tracking notification to GoogleAnalytics.
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
tracker.trackPageView( mWebview.getUrl());
tracker.dispatch();
}
}
}
http://www.the4thdimension.net/2011/11/using-google-analytics-with-html5-or.html
And in stats of google analytics you should get some info at least about operating system android.