Android restart application on configuration change - javascript

Hi in my application i am loading local html pages in my webview ,this html pages will load based on the locale or language selected , these pages also have values which i pass dynamically using JS ,but when i am changing the language, i am unable to change the dynamical values so i thought to restart the application if there is configuration change no matter in what screen i am. The application should start from scratch that is splash screen .How can i achieve this. Go code to restart the app, but is it correct way
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
MainActivity.this.finish();
this is the which works for me. i have a splashscreen before MainActivity and is works fine..

Related

Open Barcode Scanner from WebView in Swift

So I have a BarcodeScanner implemented in my iOS app and it works fine for when a user clicks on a field in the app, it opens the scanner and fills out the data. However, there is another part of the app with a WebView and in that WebView are fields that I would also like to trigger the BarcodeScanner in my app to open up and fill those out. I'm not sure where to get started with this, since I don't really do web development and I'm guessing it requires coding there? Any help would be appreciated. Thanks!
Create a class which implements the BarcodeScanner (assuming you are either using a pod or an import in swift). Once you create that, you can connect it to how many pages/buttons you'd like. Initialise the web view, add a button, and choose your custom BarcodeScanner class to direct to the scanner in the app.
func stopLoading() {
mWebView.removeFromSuperview()
self.moveToVC()
}
func moveToVC() {
print("Write code where you want to go in app")
// Note: [you use push or present here]
let vc =
self.storyboard?.instantiateViewController(withIdentifier:
"storyboardID") as! YourViewControllerName
self.navigationController?.pushViewController(vc, animated: true)
}

How to Prevent refreshing the page moves to root page in ionic 2/3

I am creating more pages in ionic 2, when i refresh the page it always redirect to the root page index, how to prevent it.
Example:
I created login page and welcome page after logging in if i press refresh it automatically moves to root page as login.
When you create a project using ionic-CLI usually you have a in src/app/app-component.ts a variable called rootPage: any = 'HomePage';
This is your root page. If you want to change to go to your AuthPage
rootPage: any = 'AuthPage';
Here AuthPage is the name of the class of your authpage
This behavior is typically observed when you are testing locally (through ionic serve command). I noticed that this should not be the case after deployment to a server. Have you tried doing that and testing it again?
i've manage to find some solution that solve this problem.
As i know and under my understand the ionic framework use the navcontroller state(push, pop) to navigate the page then if we refresh the browser this navcontroller state will gone and then go to the root.
So the solution that i've found is in this Question from stack overflow also. the answer give you 2 choices "LazyLoad" and "Deeplink"
But ive manage to solve my solution with "LazyLoad" Method by given custom ionic page segment name that different from the default. for more informantion is here

how to access the device camera from webview of android application

I have an android app with a WebView, it is written in Java Script and Angular JS code to access the Camera , I just load the URL in web view and had given camera access permission and read and write external storage permission, still it is not able to access the camera , I had browsed for this problem ,but didn't find the exact solution.
I just want to open the camera , when user click on take photo on his profile page which was written in java script code , don't know when this will happen because I have base URL only which was loaded in web view.
How to let the user open the camera in this application? And also it should support from Kitkat onward, Can any one help me to figure out this?
Use openChooser method when implement UIClient
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.addCategory(Intent.ACTION_CAMERA_BUTTON);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i,"File Chooser"), 111);
}

Android webview displaying differently when from file instead of from online

I am trying to save the HTML from a webpage into a file so if my app is opened and no internet is available then the webview loads from a file instead. Here is my debugging code - the first time the view is created it downloads the file. The second time onwards it opens the files
WebView cwebView = (WebView) rootView.findViewById(R.id.aboutWebview);
if(loadedLatest) {
cwebView.loadData(FileUtils.read(Values.aboutWebviewOfflineFile,getContext()),"text/html", "UTF-8");
cwebView.getSettings().setJavaScriptEnabled(true);
//cwebView.getSettings().setBuiltInZoomControls(true);
}else {
cwebView.loadUrl(Values.aboutPageURL);
new GetWebviewContents(getContext()).execute(Values.aboutPageURL, Values.aboutWebviewOfflineFile) //Saves the HTML to a file;
loadedLatest = true;
}
The HTML download and file seem to be working correctly however the webview looks completely different when from online and when from the file - it is much narrower and images overlap. I have tried using .loadurl(File...) and it has the same effect. Enabling Javascript makes no difference.
Does anyone have any idea what could be causing this?
Thanks
I don't know for sure, but it could be the issue of Cross-Origin blocking by the WebView. To verify that this is the issue, open the same webpage that you saved on your app, on your laptop or desktop, and save it on your disk. Then try to open that saved page and see the Javascript console on your's browser Developer Tools and see if it shows any Cross-Origin access restriction errors.

how to load a url with URLLoader in Adobe Air with javascript disabled?

i am writing an Adobe Air application using flex builder.the application loads a URL using HTML control and URLLoader.
the problem that the page has an instant redirection JavaScript that redirects the page to another one. I would like to disable that redirection.
I think this can be achieved either by disabling JavaScript on page load or telling the HTML control that do not follow the direction. i don't know how to do that?
thank you so much.
hey, i found a solution to load html source for a remote html document without loading it in htmlloader.so the javascript will not redirect me.
here is the code (from htmlscout sample application of adobe dev).
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,
function(e:Event):void
{
trytogetsource.text = loader.data;
});
loader.load(new URLRequest("http://www.google.com"));

Categories