Construct2 - Detect device type - plugins

I want to write small multiplatform game.
I created Contruct2 plugin for my game and i have any specific methods for different operation system.
How can i detect device type in plugins runtime.js?

I found solution:
if (this.runtime.isAndroid) {
// ...
} else if (this.runtime.isiOS) {
// ...
} else if (this.runtime.isWindowsPhone8 || this.runtime.isWindowsPhone81) {
// ...
}

Related

Detecting requests from PWA in standalone mode

I'm attempting to implement PWA server-side detection by altering all links on a page to add a query parameter if in standalone mode. Like this:
if (window.matchMedia('(display-mode: standalone)').matches) {
// #todo: this code breaks ios app.
$('a').each(function() {
var href = $(this).attr('href');
href += (href.match(/\?/) ? '&' : '?') + 'mode=pwa';
$(this).attr('href', href);
});
}
This seems to work fine on Android devices, but for some reason, breaks JS on iOS devices. Does anyone know why this code doesn't work on iOS? Or is there a better way?
Thanks, Joe
To do this with cookies:
// JS side.
if (window.matchMedia('(display-mode: standalone)').matches) {
document.cookie = 'deviceMode=pwa';
}
else {
document.cookie = 'deviceMode=mobile';
}
// PHP Side.
if ($_COOKIE['deviceMode'] == 'pwa') {
// Do something.
}
elseif ($_COOKIE['deviceMode'] == 'mobile') {
// Do something else.
}
else {
// And something else.
}

set flash not working in zxing scanner library

can u show the full code for button on click method for toggle turn on/off flash when scan? I have try this, but not working, Im using
val mScannerView = object : ZXingScannerView(this) {
override fun createViewFinderView(context: Context?): IViewFinder {
return CustomViewFinderView(context!!)
}
}
btn.setOnclickListener{
if(flashStatus){
mScannerView.setFlash(true)
}else{
mScannerView.setFlash(false)
}
thanks

How to add popup in google vr view on the click of hotspot.

What I'm trying to do is, When I click on hotspot it should open a popup with little text. It is okay if the text is static, Is there any way we can make it possible? FYI I'm creating it for the web.
Thanks in advance:)
I just started with google VR. I know it's a late reply but it is very possible.
function onVrViewLoad() {
// init scene here and then:
vrView.on('click', onHotspotClick)
}
function onHotspotClick(e) {
console.log('onHotspotClick', e.id)
triggerSidebar(e.id)
}
function triggerSidebar(id) {
// add the class
switch (id) {
case 'item':
document.querySelector('aside.item').classList.add('...')
break
}
}

Detecting an incoming call in my Unity app

I am trying to make my game pause on incoming phone call. I am wondering if any of this functions which I used can do this. I have used them in my source code but none of them worked.
void OnApplicationPause(bool paused)
{
if (paused == true)
{
if (!isPaused)
PauseResume(true);
}
}
void OnApplicationFocus(bool hasFocus)
{
if (hasFocus == false)
{
if (!isPaused)
PauseResume(true);
}
}
Also i had found Application.runInBackground() but it is mentioned in documentation that "Note: This property is ignored on Android and iOS".
In iOS and Android, OnApplicationPause(...) is expected to be called. This user had the same issue: https://forum.unity.com/threads/onapplicationpause-not-being-called-in-ios-build.455426/
His answer was:
Apparently, it was not working because I had 'Behaviour in Background' set to Custom instead of Suspend...

Windows Phone: How can I get a list of supported resolutions for the camera C++/CX?

I have the following function to initialize the camera:
LmiBool LmiVideoCapturerWinRTImplementation::Initialize(){
m_bRecording = LMI_FALSE;
m_bSuspended = LMI_TRUE;
m_bPreviewing = LMI_FALSE;
m_pMediaCapture = ref new MediaCapture();
try{
auto task = create_task(m_pMediaCapture->InitializeAsync(m_settings));
if (task.wait() == completed){
m_pMediaCapture->Failed += ref new MediaCaptureFailedEventHandler(this, &LmiVideoCapturerWinRTImplementation::MediaCaptureFailed);
m_pMediaCapture->RecordLimitationExceeded += ref new Windows::Media::Capture::RecordLimitationExceededEventHandler(this, &LmiVideoCapturerWinRTImplementation::RecordLimitationExceeded);
// create a video encoding profile with the default settings (Auto uses the current camera settings)
m_EncodingProfile = MediaEncodingProfile::CreateMp4(VideoEncodingQuality::HD720p);
m_pMediaCaptureSettings = m_pMediaCapture->MediaCaptureSettings;
return LMI_TRUE;
}
else{
return LMI_FALSE;
}
}
catch (Exception ^ex){
return LMI_FALSE;
}
}
Now as you can see, I am creating the video file using the following resolution: HD720p.
I found that the enum VideoEncodingQuality contains a list of resolutions the encoder could use.
What I want to know is, if it is possible to get a list of the resolutions that the device supports, somehow, so that if I choose HD1080p and my phone doesn't support that, it will not crash.
Is is possible in C++/CX to get a list of supported resolutions back from my device?