Keep display on during web app - javascript

I'm building a web app using Three.js (Javascript) and it's VR capabilities for mobile devices (android particullary). The issue I'm facing is that after some time screen gets dimmed and turned off. I was trying to find an API to keep the display on, but couldn't find any mention about it. However, if you go to http://vr.chromeexperiments.com/ and run any of those demos, the screen will be always on. I was trying to study their code but didn't find the solution. How do they do it? Thanks

Add a flag in the onCreate method of your activity.
#Override
protected void onCreate(Bundle b) {
super.onCreate(b);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
Read more here.

If you are running the app from any Browser (like chrome) is not possible to keep the screen awaken since you can't modify the device behavior via Javascript.
You can either get a third party app like KeepScreenOn (https://play.google.com/store/apps/details?id=com.nbondarchuk.android.keepscn&hl=es_419) to do that job or wrap the app inside a Webview using a hybrid App framework like PhoneGap or maybe Titanium. There you can use plug ins to do that job as well (like this one: https://build.phonegap.com/plugins/355)

Related

React Native Could not open URL No Activity found to handle Intent

I'm working with React Native and Square Point of Sale. I'm using Web API for Android.
Also I have installed Square Point of Sale.
This is my code:
componentDidMount() {
let url ="intent:#Intent;action=com.squareup.pos.action.CHARGE;package=com.squareup;S.browser_fallback_url=https://my.website.com/index.html;S.com.squareup.pos.WEB_CALLBACK_URI=https://my.website.com/index.html;S.com.squareup.pos.CLIENT_ID=sq0ids-yOurCLieNtId;S.com.squareup.pos.API_VERSION=v2.0;i.com.squareup.pos.TOTAL_AMOUNT=100;S.com.squareup.pos.CURRENCY_CODE=USD;S.com.squareup.pos.TENDER_TYPES=com.squareup.pos.TENDER_CARD,com.squareup.pos.TENDER_CARD_ON_FILE,com.squareup.pos.TENDER_CASH,com.squareup.pos.TENDER_OTHER;end";
Linking.openURL(url).catch(err => console.error("An error occurred", err));
}
This is my error message:
Could not open URL 'intent:#Intent; ... end': No Activity found to handle Intent { act=android.intent.action.VIEW dat=intent: flg=0x10000000 }
What I'm doing wrong?
I tried building using the web API but found that the flow wasn't great. The user doesn't always make it back to the app; sometimes they get stuck on the website.
I built react-native-square-pos to make things easier for the next developer. It uses Native Modules to communicate with the Android / iOS Square PoS APIs.. so you don't have to write Java or Objective-C.
The intent:#Intent that you're using there isn't really going to work from within React Native, since that is used for going from a web browser on an Android device into the Square POS app.
The Android Web API intent is intended to do a hand-off from your browser to the Square POS application, not from application to application.
It sounds like what you'd be wanting to do is use the Square Point of Sale SDK for Android with your React Native application. You'll want to take a look at https://facebook.github.io/react-native/docs/native-modules-android.html about how to link a native module with your React Native application.

Multiple detached webview instances seen in chrome devices while navigating in hybrid android app

We have an hybrid android application. I am trying to navigate from a WebView to a Native context back and forth. Using chrome://inspect/#devices I get to notice that multiple instances of device inspected are detached while one of all would be attached as displayed in chrome.
Referring to SO-28254614, now I have not developed the WebView though, but to what I know about our application the WebView are not designed using Cordova and are in JS.
An the question that I have are :
Why is it so that we see these detached devices on chrome?
Could this be a possibility of a leak in Android WebView?
So the way these web inspectors work is that they use the RemoteDebug Protocol.
This protocol defines the various messages and commands that are exchanged to let you 'inspect' your pages.
One instance of the inspector can only connect to one client at a time. So assuming that you are switching to and fro web-views and native context, you are basically spawning new webviews for every new context switch.
This would indicate that the previously opened webviews are now 'orphaned' and for all practical purposes detached.
You can try to inform the VM that a webview is no longer in use by calling destroy() on the webview to let the garbage collector know it is no longer required.
Hope this provides a deeper understanding on what is happening behind the scenes.

Allow access to weblink only via native iOS and Android apps

I have website link at which I have designed a html/javascript web app. I used iOS and Android app to create an app that encapsulates the web app.
Is there a way to block access to the website link and only allow access to the website link only thru the native apps calling the link.
In short safari, IE, Chrome must not be able to access the link, but the iPhone & Android app should be able to access it.
Is there some way to tell that the app is accessing the site and not the phone or pc browsers.
I am sure there a number of ways to implement this.
Thanks,
It depends on how is the web app implemented. Since native Web Views are pretty much the wrapper for the standard browser (Safari/Chrome), you will find it tough to filter it based on that.
What you can do, however, is to add an extra GET variable (for ex. &ref=youruniquecodehere) or a custom User-Agent, based on which you will be able to identify, whether your application authorized the request (with a proper access code) or if it's a generic request using browser.
However, both of these options can still be bypassed if researched, although it'd require slightly more time. Not sure whether a solution that would work in 100% of cases exists.
Hope that helps, please correct me if I'm wrong.

HTML5 and javascript in xcode

I'm quite new to xcode, because I mostly work with JS and HTML5. I've decided to create a simple webview app that enables me to work with JS and HTML5 (going to put it on Github asap)
Now my question is about accessing certian iPhone features that I cannot use in Safari or Chrome (the reason why I'm creating this).
So the question is: is this possible? for example, I can't access the camera (as a fullscreen background I mean) in an iOS browser, but can I use it in webview?
You need any method of communicating between UIWebView and the containing app. There are libraries out there that do just that, some better some less. In case you do not want them... So to outline the techniques to do that:
App talking to the webView - using [webView stringByEvaluatingJavaScript:...]
Webview talking to the app - using url directives. Which is essentialy window.location = ... with custom fake urls, and then parsing the NSURLs in the delegate method webView:shouldStartLoadWithRequest:navigationType: and of course returning NO to prevent actually navigating to your fake urls.
If you find that you are missing consecutive URL requests, you could write a JS function that takes the URLs, puts them all in an array, pops one by one and sending them to the browser in a setTimeout(..., 0).
You need to use something like this - Cordova or PhoneGap ( Both are the same thing )
"Apache Cordova is a set of device APIs that allow a mobile app developer to access native device function such as the camera or accelerometer from JavaScript. Combined with a UI framework such as jQuery Mobile or Dojo Mobile or Sencha Touch, this allows a smartphone app to be developed with just HTML, CSS, and JavaScript."
Here is a description of all the device features cordova or phonegap allow you to use - Plugin API's
Yes, is it possible, but using a web app container like Phonegap.
If you need more info how install it visit this web.

Sencha Touch and PhoneGap

You built your app in Sencha Touch, loaded it in a web view wrapper in PhoneGAP.
Now how would your Sencha Touch web app access data from PhoneGAP? since its in a web view?
Example you used PhoneGAP to get UDID, or device contact list etc, how are you suppose to send that to sencha? since its in a webview? Possible? If not what do you do?
An Intent? There is nothing more universal in Android than an Intent.
So Sencha Touch part issues an intent. Your PhoneGap HTML5 WebView catches this Intent. A WebView is still in an Activity. Its just a different type of activity I believe. So the activity webview can processed data/generate data based input or whatever and send out in the bundle of an Intent. Either side could also store in SQLite or SharedPreferences, and just use the intent to notify of the data change or request. Also consider startActivityForResult(intent) to get data back.
First for all Sencha Touch is just the framework you use to build your app.
It doesn't control your application.
If you are using Phonegap as your Webview wrapper. By the way Sencha now also offer a "Native Wrapper".
You would call the various javascript api's which Phonegap will map to its native counterpart. Depending which api you called and if any data was returned you can handle this in a callback.
That's about it, there is need send anything to Sencha as you describe it.
Its more a callback centered just like javascript.
The following links might help you.
http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap/
http://robertdougan.com/posts/packaging-sencha-touch-2-with-phonegap-cordova

Categories

Resources