I am writing an application for a client that will have several devices that are open to customers to look at and play with. They want to be able to clear the browser history on a regular basis so that if a customer opens the browser to an inappropriate web site the next customer to come along will not see this.
I am currently using this to clear the history and searches:
Browser.clearHistory(getContentResolver());
Browser.clearSearches(getContentResolver());
This correctly clears the history. But any windows(tabs) that were open in the browser remain open. How can I tell the browser to close all of these tabs so that the next time someone opens the browser it will load the start page only?
I've noticed that killing the browser with the TaskManager that comes pre-loaded on the device works. Is killing the browser task the only way that I can get it to close any open tabs? If so how can I go about killing/restarting the browser process? I've tried this:
am = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
am.killBackgroundProcesses("com.android.browser");
But this method doesn't seem to be doing anything. I do have
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"></uses-permission>
In my manifest but after I run this and go back to the browser it is still sitting on whatever tabs were left open. What is the proper way to use the permission that is granted by this?
Id rather find some way other than Task Kill to make it work, but at this point I am coming up empty on all fronts.
If your device is rooted, you can use the command below, to clear all data of the application. I don't know if this is applicable for each device, as it depends on the package manager
Runtime.getRuntime().exec("su -c /system/bin/pm clear com.android.browser");
I tried to close the browser via the ActivityManager and it works fine. I tested this on an HTC 2.2 and it works perfect.
Maybe you should also try this:
am.killBackgroundProcesses("com.google.android.browser");
in case the browser on your phone is not at com.android.browser
or even try to finish the activity: com.android.browser.BrowserActivity
Hope this helps!
Much like a computer browser, Android browsers will keep all records that you search onto the device. If you’re worried about browser history or don’t want any records in your Android, you can remove all browser history within minutes. After delete your browser records will delete all cache data where you’re login into Chrome.
Related
Testing mobile application using appium. When I run to test, my application opens, I can do some action, and then when I login, app takes me to browser to login to the cloud which is OK, but my problem is in the emulator. I have a question that pops-up, Open with Chrome or other app (JUST ONCE / ALWAYS). How can I avoid this dialog?
added below code but this does not help
caps.setCapability("appPackage", "com.android.browser");
I expect that when app switch me to browser then I can paste my credentials and switch back to my application and I can continue my testing
I experienced similar popups too when testing apps with Appium. The only solution that works for me is extracting the xpath (UIAutomatorViewer) and perform a click on the popup. There must be a OK or cancel button somewhere. (I do this for app crash popups, chrome privacy stuff, ...)
I perform something like:
if(element.isDisplayed()){
element.click();
}
//proceed with your test
It is not optimal but it works. Remember if you would test this app manually you would also have to click the popup away, so I think this is OK.
You can trigger KeyEvent to put apps in the background and see the home screen. Then you search for browser icon and click it. Once in browser, you can use the context commands to automate the webview.
After you done with browser, you can resume the native app.
Sometimes there are some testing that makes us out of the application, Appium provides features for us to switch to the application we want. Please try this method :
driver.startActivity(new Activity("com.example", "ActivityName"));
You must know the name of your application bundle and its main activity.
You can read the documentation here.
My app opens a WebView, which in turn loads a simple page from my remote host. Recently I've been trying to minimise the amount of data usage, by maximising cache usage, and have started using a network connections monitor app like this and this to check what connections are actually being made by my app (and others).
These are showing that, as well as a connection being made to the host when the webview loads, a connection is also being made to nnn.n.nnn.nn.bc.googleusercontent.com. The first of the above apps resolves this to an admin address of Google Inc.
But I have no idea why this connection is being made. My webpage does not have any google-related tracking code or anything like that, has no links to adverts, nothing at all along those lines. And the Android app itself, that loads the WebView, likewise does not at any point try to fetch "user content" from googleusercontent.com.
I would post some code, but since I have no idea where this call is initiated from, I wouldn't know what to show. I would also say that I have noticed on my phone that occasionally a full-page advert will pop up, and I have no idea where it's coming from... but it doesn't happen at the same time as these calls to googleusercontent.com.
Any insight on this would be most welcome.
OK I think I figured it out. My web page makes a call to my node.js app running on Cloud 9... I think that the mysterious nnn.n.nnn.nn.bc.googleusercontent.com must just be where the node app is being hosted. When I call this page from my production app (where the node app is running on heroku) I get a call to a different yet similarly mysterious-looking address: xxxxxxx.eu-west-1.compute.amazonaws.com... so that must be where the heroku node app is hosted.
I have built an android and ios application using phonegap.
I need a user to navigate to another application on the phone and copy a token (string) and return to my app and paste it.
This works perfectly fine on android devices, but on IOS (both devices I've tested on are iphone 5 with ios7) when the user navigates away from my application and then returns, it is restarting my app. It loads on the first page of my app & of course the context & the form they needed to paste the string into are gone.
Is there some way to keep the application from closing just for 30 seconds while a user navigates to another app and then returns?
(I've searched for information on this, but all I can find is information on creating a service. I don't need the application to run in the background continuing to perform tasks. It just needs to not close while a user navigates away to copy a string from another app)
I resolved this by disabling debugging and hydration and rebuilding my app with "Phonegap Build". I guess hydration was forcing a restart of the app when it would lose and regain focus.
I have a web app and on the Android I would like to display an alert describing how to add my app to the home screen. (Add it to "Bookmarks" and then "Add it to home screen" or "Add to shortcut in Home"). Then a icon will be displayed on the screen that opens my app.
But off course I only want this to show if the app is not added to the home screen.
Does anybody know how to do this?
Any input appreciated, thanks.
Yes, you can.
While technically a page open in Chrome browser tab can't directly check whether a home screen shortcut exists, the page's local data (localStorage, IndexedDB) is shared between home screen instance and browser tabs, so this can be used to communicate the existence of the home screen version.
Detect if the app is running from home screen
If it's ran from home screen, save this fact to localStorage
Profit! (by reading this from localStorage in any tab)
When the app is in standalone view (which is possible only when launched from home screen), the CSS media query (display-mode: standalone) will match. In Javascript you can read it using:
matchMedia('(display-mode: standalone)').matches
(BTW: the non-standard iOS equivalent of this is navigator.standalone, but iOS doesn't share state between home screen and Safari, so you're out of luck there).
However, instead of custom instructions I suggest meeting Chrome's criteria for "progressive web app" and let Chrome do the prompting for you.
You can't check a web app if its added to home screen on android. At least for now. (Chrome 67)
But you can tell if the app is running in standalone mode using display-mode media query.
Add this inside your <style> tag.
#media all and (display-mode: standalone) {
body {
background-color: yellow;
}
}
Then in your <script> tag.
if (window.matchMedia('(display-mode: standalone)').matches) {
console.log('display-mode is standalone');
}
Or this
if (window.navigator.standalone === true) {
console.log('display-mode is standalone');
}
You can check more from here.
The short answer is: from a Web Site you can't.
The longer answer is: from a Web site you might be able to get a hint in Chrome.
Chrome on Android two new features 1) Web App Manifest that describes what should be launched from the home screen and how it should look on the homescreen, and 2) Chrome now has an beforeinstallprompt event that will trigger for Web apps that we think are app-like and can be installed to the homescreen.
There are a number of criteria for the onbeforeinstallprompt event to fire which might make it an "ok" heuristic (although I suspect not).
The event only fires if:
The site has a manifest, is on https and has a service worker. (this can be quite a stretch).
The user has engaged with the site multiple times (right now, twice within at least 5 minutes).
The user has not already added your site to the home-screen.
So, in summary it is complex and full of false positives and false negatives. However if all you want to do is detect if you should display a banner to prompt the user to add your web-app to the homescreen then Chrome already has a solution for you.
We also have a full range of samples on our samples site.
I think you can do it. Simply add query string to start_url in manifest.json and in your javascript check if start url is having that query string. If query string is found then yeah app is installed.
first you get the list of apps on the device
List<ApplicationInfo> packs = pm.getInstalledApplications(0);
then you use getLaunchIntentForPackage()
Now that you've got the list of packages installed on your device,
iterate through them and call getLaunchIntentForPackage() on each
item.
If a valid intent is returned, it exists on the Launcher, else if null
is returned, the package does not launch from the Launcher screen.
Note that Home screen shortcuts are a subset of the Launcher apps.
I created an new Android app and succeeded in its working. Its all functionality are working fine. While starting it will ask use name and password.
What my problem was "If my Application is idle for some 4 to 5 hours, then automatically it get quit , while restarting its again asking to login"
I need to know how to avoid automatic quit of my app.
I'm sorry if its simple or already asked quetions.
I need to know how to avoid automatic quit of my app.
No, you do not. Simply redirect the user to log in again, or, as #Rasel suggests, persistently cache credentials in a file or database or something.
Android applications do not and must not live forever. Phones have limited RAM. Android will terminate unused applications after a period of inactivity, to free up RAM for other applications. This is perfectly normal, just as it is perfectly normal for a user to close a Web browser after visiting a Web app.
Its completely natural for the android application.Android OS automatically kill the process when it needs to do.So if you want keep your application alive you have to think differently.To keep always running you can use service that will monitor your application states and handle the situation when it prompts for the login info again.
Another option you can write the login information in the shared preference and can clean when user intentionally leave the application.So when starting again if you find the information you can directly prompt to the user without entering the login information