Why wakeLock doesn't work in Samsung Internet - android

I have a React app that attempts to prevent a screen from sleeping when a component loads or on press of a button. For some reason it doesn't work in Samsung Internet. I does work in Chrome on Mac and in Chrome on Samsung phone. I can't find anything to suggest that this is a common problem. It looks like it is a supported feature. I do see the code being executed in logs, but the phone goes to sleep anyway. Is there anything that maybe should be enabled on the phone or in Samsung Internet settings of some sort?
Here is my implementation
async requestLock() {
Debugger.log('requesting wakeLock')
try {
if ('wakeLock' in navigator) {
this.wakeLock = await navigator.wakeLock.request('screen');
Debugger.log('wakeLock requested')
}
} catch (e) {
Debugger.log('wakeLock error');
}
}
async releaseLock() {
if (this.wakeLock) {
Debugger.log('releasing wakeLock')
await this.wakeLock.release();
Debugger.log('wakeLock released')
this.wakeLock = null;
}
}

Related

Flutter - Denying permission on camera throws exception

Here is my initializeCamera code :
initializeCamera() async {
try {
final cameras = await availableCameras();
final firstCamera = cameras.first;
ContextManager.camera = firstCamera;
setState(() {
cameraAuthorized = true;
ContextManager.cameraAuthorized = cameraAuthorized;
});
} catch(e) {
ContextManager.camera = null;
setState(() {
cameraAuthorized = false;
ContextManager.cameraAuthorized = cameraAuthorized;
});
print(e);
}
}
Here is my initState code where I call the initializeCamera function and after that initialize the CameraController :
#override
void initState() {
super.initState();
initializeCamera().then((value) {
if (ContextManager.camera != null) {
setState(() {
_controller = CameraController(
ContextManager.camera,
ResolutionPreset.medium,
);
_initializeControllerFuture = _controller.initialize();
});
}
});
}
When I am running the code with flutter web from my computer browser I get this popup from my initializeCamera step :
When I click "allow" the rest of the code which is called in the then()
and especially _controller.initialize(), which initialize my camera on the device, is executed and the camera starts working. When I click "deny" another part of the code that I customed is run to display a message on the screen, in other words everything works fine.
When I'm running on the Android Emulator everything from my initializeCamera() function to _controller.initialize() is run without interruption until I get this popup :
Whether I choose "while using the app" or "only this time" the camera starts working and everything is ok. But when I click "deny" the app throws a CameraException.
I tried to wrap this line (which is causing the issue) :
_initializeControllerFuture = _controller.initialize()
in try/catch, and also specifying the name of the exception, but nothing worked.
What I don't get here, is that _controller.initialize() function is called before the popup show in the emulator, so the camera is initialized on the device before we can actually choose to deny/allow it.
While on the computer you actually get to choose whether you deny/allow the camera before the _controller.initialize() function is executed, which make perfect sense to me.
The ways it works on the emulator doesn't make any sense for me, if someone more knowledgeable could enlighten me, thanks.

External links not opening in Android

Folks,
I'm facing a problem here that I can't find a solution for it.
In my app I offer external links that the user can click on and open websites in browser.
They work fine in both IOS and Android emulator, but do not work in real Android phones.
Here the code that operates that:
void _makeAction(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
_showMessage(Translate.of(context)!.translate('cannot_make_action'));
}
}
Future<bool> canLaunch(String urlString) async {
return await UrlLauncherPlatform.instance.canLaunch(urlString);
}
Any idea what can be happening?
Thanks in advance.

Hunting a spooky offline.html

I once wrote a quick ‘offline.html‘. Just be be sure I understood how offline PWA worked:
This is offline.html (My App Name)
I thought it worked as expected. So I deleted it and wrote a better one, with a back button, some info etc.
Now when this app is offline it starts on the page the manifest.json days, as expected.
However, if I try to refresh the page that spooky "offline.html" shows up. From nowhere.
I've tried to understand where it lurks, but I can't find it. (The new "offline.htmi" is there when I go to it in the web browser.)
I've tried Firefox offline on my mobile to see if the spoky "offline.html" jumps up there to. It does. 😐
I've cleared the cache in Chrome. The spoky "offline.html" is still there.
Any ideas?
(This is on Android 9)
Offline pages are not exactly stored in caches as regular cached items, there are stored quite differently, relative to the current installed service worker. I tried looking for an article to explain this more but can't walk around any currently.
However you'll have to unregister your service worker or learn how Updating service worker works,
The aim is to remove the lurking offline.html served to the new offline.html that exists.
This is what I finally landed on. It seems to work. The test for 404 is of course not optimal, but I leave it that way for now, hoping that the emerging standard will address this issue soon.
async function setupServiceWorker() {
let reg;
if (navigator.serviceWorker.controller) {
console.log("Active service worker found, no need to register");
// new Popup("registered service worker, .active.scriptURL", reg.active.scriptURL, null, true).show();
reg = await navigator.serviceWorker.getRegistration();
} else {
reg = await navigator.serviceWorker.register("service-worker.js", { scope: "./" });
console.log("Service-worker.js registered, scope: " + reg.scope);
}
try {
if (navigator.onLine) {
const newReg = await reg.update();
}
} catch (err) {
const is404 = err.message.match("404");
new Popup("err", is404 + " " + err.message).show();
if (is404) {
let wasUnregistered;
try {
wasUnregistered = await reg.unregister();
} catch (errUnreg) {
new Popup("unregister() service worker failed", errUnreg.message).show();
}
if (wasUnregistered) {
setTimeout(setupServiceWorker, 1000);
}
}
}
}
setTimeout(setupServiceWorker, 5000);

HTML5 video controls disappear in full-screen mode on android devices

I'm developing a cross platform app using cordova with an angular material front end.
I use HTML5 video tags in a list of md-cards to play videos with external urls. When inline the videos play correctly, and display the native controls as expected.
<video class="project-video" video-directive item="$ctrl.project" ng-src="{{$ctrl.project.videoUrl | trustUrl}}" preload="auto"
controls poster="{{$ctrl.project.video.thumbnail_url}}">
Your browser does not support the video tag.
</video>
However when I click the "toggle full-screen" button the video does go to full-screen, but the default controls disappear. I cannot get back to the app after this - the native android back button does not close the full screen - instead it closes the whole app.
The solution I am looking for will make the controls always appear even in full screen mode; this works out the box running the same code on iOS.
Therefore I do not want to spend time developing my own custom video controls just for android, if I can help it! So please do not post answers about how to do that (plenty already available on SO and elsewhere).
I am using a Meizu m2 note android device.
Thanks!
EDIT:
The controls are still there but are showing up in the shadow DOM tree in css as being of size 0 x 0px. Even when I change their size in chrome dev tools using the !important flag, they do not show up.
Any ideas?
This is an issue with Flyme OS which is used by Meizu devices. Since the controls are available and not visible, this should be resolved by ugrading the Flyme OS.
Please update Flyme OS to resolve this as the older versions of Flyme seems to have quiet some problems with fullscreen video mode. Hope it helps. Cheers
set the values which then allow to exit fullscreen.
var videoElement = document.getElementById("myvideo");
function toggleFullScreen() {
if (!document.mozFullScreen && !document.webkitFullScreen) {
if (videoElement.mozRequestFullScreen) {
videoElement.mozRequestFullScreen();
} else {
videoElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
document.mozFullScreen = true;
document.webkitFullScreen = true;
} else {
if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else {
document.webkitCancelFullScreen();
}
}
}
document.addEventListener("keydown", function(e) {
if (e.keyCode == 13) {
toggleFullScreen();
}
}, false);
add these two lines ..
document.mozFullScreen = true;
document.webkitFullScreen = true;
if you want something better
fullScreenButton.addEventListener("click", function() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.msRequestFullscreen) {
video.msRequestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen();
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
});
How about this in your code your not mentioned controls attribute fully may be that could cause the problem
<video id="myvideo">
<source src="path/to/movie.mp4" />
</video>
<p onclick="toggleControls();">Toggle</p>
<script>
var video = document.getElementById("myvideo");
function toggleControls() {
if (video.hasAttribute("controls")) {
video.removeAttribute("controls")
} else {
video.setAttribute("controls","controls")
}
}
</script>

Meteor.call doesn’t work on android App

I created a simple app using Meteor 1.3, which has only one method. It works like that: When a button is clicked, the method is invoked - it calculates a specific value and returns the result.
The app works perfectly on the localhost server, but when I launch it on my device with "meteor run android-device", it cannot access the method (simply opens the app, but nothing happens when I press a button.
Do you know how I could resolve this?
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { ReactiveDict } from 'meteor/reactive-dict';
import './main.html';
Template.check.onCreated(function checkOnCreated() {
this.state = new ReactiveDict();
});
Template.check.events({
'click .checkit'(event, instance) {
Meteor.call('code.check', function(error, result){
if(error){
console.log('Error from the client side!');
} else {
instance.state.set('fett', result.titles[0]);
}
});
},
});
Template.check.helpers({
fett() {
const instance = Template.instance();
if (instance.state.get('fett')) {
return instance.state.get('fett');
} else {
return 'Value still not known...'
}
},
});
Ensure your smartphone's WiFi is turned on and it connected to the same WiFi network as you computer where meteor app is running. Then everything should work fine.
Also, I recommend to use chrome://inspect feature (more info here) in order to debug your app on Android. Then, you will be able quickly investigate any problems with mobile app.

Categories

Resources