Issue with phonegap plugin for adjusting screen orientation

I encountered the following issue:

Uncaught TypeError: Object # has no method 'exec' at file:///android_asset/www/JS/pg-plugin-screen-orientation.js:4

var screenOrientation = function() {}
    
    screenOrientation.prototype.set  = function(str, success, fail) {
    
     PhoneGap.exec(success, fail, "ScreenOrientation", "set", [str]); // ERROR OCCURS HERE
     
    };
    
    navigator.screenOrientation = new screenOrientation();
    

I have carefully followed the instructions provided in this document: https://github.com/champierre/pg-plugin-screen-orientation


After making necessary changes, the functionality is working correctly. However, the application crashes when executing this line of code:

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    

07-24 18:01:19.200: E/AndroidRuntime(12001): FATAL EXCEPTION: main
    07-24 18:01:19.200: E/AndroidRuntime(12001): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4054e820 is not valid; is your activity running?
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.ViewRoot.setView(ViewRoot.java:527)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.view.Window$LocalWindowManager.addView(Window.java:424)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.Dialog.show(Dialog.java:241)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.Notification$1.run(Notification.java:205)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.Activity.runOnUiThread(Activity.java:3717)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.Notification.alert(Notification.java:208)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.Notification.execute(Notification.java:70)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.api.PluginManager.exec(PluginManager.java:212)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:185)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.os.Handler.dispatchMessage(Handler.java:99)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.os.Looper.loop(Looper.java:123)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at android.app.ActivityThread.main(ActivityThread.java:3683)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at java.lang.reflect.Method.invokeNative(Native Method)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at java.lang.reflect.Method.invoke(Method.java:507)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    07-24 18:01:19.200: E/AndroidRuntime(12001):    at com...
    

Answer №1

Could you please specify the version of PhoneGap/Cordova you are currently utilizing? It's worth noting that in more recent iterations, the PhoneGap object has been rebranded as cordova. Therefore, it may be necessary to revise the JS file to reference cordova.exec as opposed to PhoneGap.exec.

Answer №2

Whenever I try to execute the exec function before the onDeviceReady() event is triggered, I encounter this error.

The onDeviceReady() event must be fired first.

This error occurs when the event has not yet been triggered.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript: Eliminate specific value from sub-array within an array of objects by using a designated key

My data array structure is as follows: { "filters": [ { "filterProperty": "companyType", "filterValues": [ "Private" ] }, { "filterProperty": "city", "filterValues": [ "Mumbai", "SanJo ...

Finding all elements with a specified attribute in jQuery: A comprehensive guide

While looking for an example, I came across one that searches only inputs instead of all elements: https://api.jquery.com/attribute-equals-selector/ Is there a way to modify this example so that it can search all elements in the DOM, and not just inputs ...

Creating an art piece on canvas using Javascript based on an image selection

Using the webpage below, I am attempting to draw a photo selected with an iPhone on the canvas so that it can be later uploaded to a webpage via ajax. The code includes downsampling, which has been omitted for simplicity. While this code works perfectly i ...

Showing error messages in Angular when a form is submitted and found to be invalid

My form currently displays an error message under each field if left empty or invalid. However, I want to customize the behavior of the submit button when the form is invalid. <form #projectForm="ngForm" (ngSubmit)="onSubmit()"> ...

Different ways to modify the CSS file of the bx-slider plugin for multiple sliders within a single webpage

Currently in the process of building a website using bx slider. I am looking to incorporate three sliders onto a single page for sliding HTML content. Initially, I added a bx slider to the page and customized it using CSS. I made modifications within jqu ...

The People and Groups selection dialog is displaying incorrectly in IE 10

I've been working on a Sharepoint web application and have created a site column of type “People or Group”. This should be automatically associated with a user selection dialog as shown below: However, as you can see in the image above, the users ...

What happens when I click "OK" in the dialog box? Will the server method be executed, and if I click "Cancel",

I am looking to incorporate a dialog box with "ok" and "cancel" options into my aspx page. Upon pressing "ok," I want my server-side code to execute. If "cancel" is pressed, I do not want anything to happen, including avoiding any postback action. The de ...

"Bringing the power of JavaScript to your WordPress

I have set up a wordpress page and integrated some JavaScript into it. When working in wordpress, there are two tabs on a page where you can input text - 'Visual' and 'Text'. The 'Text' tab is used for adding HTML and scripts ...

Obtaining Album Artwork for an Android Music Player

Can anyone provide the code (Function) to retrieve the album art image from a music player? What parameters need to be passed when calling the function? The file path can be passed as an argument. import necessary libraries public class SongsManager { ...

Different from SimplyScroll but with added functionalities

Searching for a replacement for the now deprecated SimplyScroll with specific features. I am in need of a continuous, automatic carousel of boxes/images that halts when hovering over with the mouse (a feature SimplyScroll possesses), and allows movement ...

Determine the expiration date of an SSL certificate by accessing the client-cert.pem file saved locally on an Android

To check the expiration date of an SSL certificate, I can utilize IdHTTP connected to IdSSLIOHandlerSocketOpenSSL. IdHTTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1; I can then access OnVerifyPeer: function TForm1.IdSSLIOHandlerSocketOpenSSL1VerifyPeer( ...

What is causing the image to not be centered in the canvas when using AngularJS?

Can you please help me troubleshoot why my image is not centered using the method below? function drawImage() { clear(); element.save(); element.scale(currentScale, currentScale); ...

Strategies for Increasing Index Values in JavaScript

I attempted to modify the data attribute in my code snippet below. After clicking on the square, the data attribute should be incremented. However, it appears that the incrementing is not happening as expected. How can I resolve this issue? Additionall ...

Encountering difficulty in adding content to a table using JavaScript. An error message appears stating that assignment to a function

I am utilizing ajax to retrieve an item from a web API, and then attempting to allocate attributes of that item to a table: function find() { var id = $('#contentID').val(); $.getJSON(uri + '/' + id) .done( ...

Sending information from a rails controller to a react component

Wondering how to pass the example @post = Post.all from the controller to React component props while integrating Rails with React via Webpacker. Is it necessary to do this through an API or is there another way? ...

Troubleshooting VueJS Promise.all Problem

I need help implementing promise-based logic for asynchronous data fetching in VueJS. Previously, I had the following logic: if (influencer.suggested?.length && url.length) { const [ interactions, suggested_ids ] = await Promise.all([ $axios.$ ...

Choosing OnChange JavaScript in Laravel

https://i.sstatic.net/CRQCa.png I am looking to implement a feature where clicking on a dropdown menu will immediately display the corresponding value based on the record ID in the related table. For instance, when selecting "golongan," the "gaji pokok" v ...

What is the optimal amount of data to store in memory for single page applications?

Is there a limit to data caching in single page applications when using shared services or ngrx? Does storing excessive data on the front end impact the overall performance of the web application (DOM)? Imagine having a very large and complex nested objec ...

Emulator having issues with sunshine app crashing unexpectedly

As a complete beginner in android development, I am currently following a tutorial for the Sunshine app. While running the app, it was supposed to display details on the DetailActivity but instead gave an error. Can someone help me figure this out? MainAc ...

Exploring the Positives and Negatives of Using JQuery and Glow JavaScript Libraries

Is there a detailed analysis available that compares JQuery with the BBC's Glow JavaScript libraries? ...