The sound, like a beep, is not generating properly using createOscillator on Android version 8.0

I am currently working on an application using HTML and JavaScript which is accessed from an Android app through a webview. I have a specific requirement where, upon pressing a button in the webview, a beep sound should be played using a JavaScript function called createOscillator. Interestingly, the sound plays fine in the browser (Mozilla) on my PC but not on the mobile device via the webview (I tested it on Android 8.0.0 OS, Samsung Galaxy A5 (2017)). Why is there no sound on the cellphone? Thank you for your help...

HTML

<button name="zavrsisnimi" id="zavrsisnimi1" type="submit" onClick="zavrsisnimi(this.id)"
                style="width:100%; height:100%; margin:0%; 
                background-color:white; font-size:xx-large; font-size:2.0vw; font-size:3.0vh;" >
                SEND                 
    </button>  

JavaScript

function zavrsisnimi(id)
 {   
     var y;
     y="yes";       
     navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
     if (navigator.vibrate)
       {
        alert("I am using navigator vibrate");        
        beep2();
       }     
     window.open('/somefolder/file2?zavrsisnimi='+y,'_self');
     return;
     }


function beep2() 
{

a=new (AudioContext || webkitAudioContext); 
beepc(300,520,2000);

function beepc(vol, freq, duration)
  {
  v=a.createOscillator();
  u=a.createGain();
  v.connect(u);
  v.frequency.value=freq;
  v.type="square";
  u.connect(a.destination);
  u.gain.value=vol*0.01;
  v.start(a.currentTime);
  v.stop(a.currentTime+duration*0.001);
  } 
}

In Android Studio AndroidManifest.xml

<uses-permission android:name="android.permission.VIBRATE" />

Answer №1

This method worked perfectly for me on my Android device. The window.open function now waits for half a second before redirecting.

function finishTask(id)
 {   
     var status;
     status = "completed";        
     navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;     
     beep2();
     beep3();
     setTimeout(function () { window.open('/somefolder/file2.php?status='+status,'_self'); }, 500);      
     return;
     }

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

Issues have arisen with Google Maps functionality following the API integration, resulting in a blank grey

I am experiencing an issue with Google Maps where it is displaying a grey box or sometimes showing nothing/white. I have tried various solutions found online but none of them have worked for me. Does anyone have a solution? I even attempted to change the ...

Encountering issues with compiling the Android test application

My venture into Android programming began with following a tutorial. However, I hit a roadblock early on as I couldn't run the application that the first project supposedly creates automatically. The issue seems to stem from my computer's setup, ...

A Step-by-Step Guide on Sending Response to ajaxError Callback in Perl

When working with JavaScript, I have a method of capturing errors that looks like this: $(document).ajaxError(function(event, jqxhr, settings, thrownError) { handleError(MSG_SAVE_ERROR); }); Now, my question is how can I retrieve an error message fro ...

Issues with MediaRecorder on Kindle device

For a while now, I have been successfully using the code below on all Android devices without any issues. However, after updating my Amazon code to match, their test results have shown that the code is failing. Upon testing on the emulator, the following ...

Maintain hover effect of main menu on sub-menu in CSS3 flip dropdown menu

Check out the fiddle I created for my query https://jsfiddle.net/e7te8hf1/ <section id="action-bar"> <div id="logo"> <a href="#"><img src="img/logo.png"></a> </div><!-- end logo --> <nav class="navbar navigat ...

Why is the appsecret_proof invalid?

Currently, I am in the process of developing a new application. I am utilizing the Javascript API for logging in (v2.4) and the latest version of the PHP API (v5). To test the functionality of my app, I have created a Test App. With the Javascript API, I h ...

The calculator is malfunctioning and unable to perform calculations

export default function App() { const [activeKey, setActiveKey] = useState(0); const [storeArr, setStoreArr] = useState([]); function click(selector) { setActiveKey(selector); if (activeKey !== "=") { setStoreArr([...storeArr ...

Attempting to use Selenium in JavaScript to download a file with a new element called 'TransitionRejection'

I am looking to streamline the process of downloading multiple files from a website. To achieve this, I navigate through several pages to obtain the file IDs using selenium and a perl script. Since selenium does not have a built-in download function and u ...

Can you use WallpaperManager from Android in Flutter?

I am currently working on developing an Android app using Flutter that will allow users to set their wallpaper. However, I am facing difficulties in figuring out how to achieve this since Flutter is designed to compile for both iOS and Android platforms, ...

Icon toggling menu bug

I recently designed a menu featuring an animated icon that, when clicked, opens with two columns. The issue I'm facing is that after clicking on a link in the right column (view JSFiddle), the menu disappears but requires two additional clicks on the ...

Prevent elements from displaying until Masonry has been properly set up

My goal is to merge Masonry elements with existing ones. Currently, the items appear before Masonry initializes then quickly adjust into position a moment later. I want them to remain hidden until they are in their proper place. This is the snippet (with ...

Dynamic translation using Angular 6's i18n functionality

I'm working on translating a piece of code using Angular's i18n. Everything seems to be in order, but I'm facing a challenge with translating the words 'Enable' or 'Disable' based on the dynamic status of the item. The se ...

Store the selected checkbox values in an array when submitting in Ionic

One issue I am facing is that the checked checkboxes are returning true instead of the value of input (type="checkbox"). Array displaying responded checked or unchecked items I am unable to store this data in an array as needed. Additionally, I cannot sp ...

Sending data from a parent component to a child component through a function

In the process of developing an app, I have implemented a feature where users must select options from four dropdown menus. Upon clicking the "OK" button, I aim to send all the selections to a child component for chart creation. Initially, I passed the sel ...

Unable to process GoogleMaps DirectionsResult Object for deserialization

Currently, I am facing an issue with the GoogleMaps API v3.0 where I am trying to store a DirectionsResult in my database and then retrieve it later for use on a map. The problem arises when I attempt to restore the saved object by extracting its JSON repr ...

Troubleshooting issues with resizing multiple Echarts in React

I'm facing an issue with resizing Echarts components when the window size changes. I have two components rendered, but only one of them is able to resize properly. Below is the source code for your reference - you can observe the problem by resizing y ...

Utilize Vuex's $store.watch method to dynamically add and remove event listeners

Here's the section where I'm monitoring my store using mounted(): this.$store.watch( (state, getters) => state.windowState && state.chatState == 0, (val, oldVal) => { if (val) { console.log('state is tr ...

The click event is triggering before it is able to be removed by the code preceding the trigger

Here's a scenario I recently experienced that involves some code written using JQuery. It's more of a statement than a question, but I'm curious if others have encountered this as well: <input type="submit" value="Delete" o ...

employing async/await in the function of a backend API

I'm facing an issue with the following code snippet: service.js module.exports = { getUser }; async function getUser({ data }) { return new Promise((resolve, reject) => { const id = data["id"]; const doc = await db.colle ...

The parameters for Vue.js @change events are consistently returning as 0 whenever a file is uploaded by clicking on the picture

Check out my JSFiddle here:: https://jsfiddle.net/includephone/o9gpb1q8 I've encountered an issue involving the @change event on an input field. My goal is to create a carousel of images with 4 images per slide. Data Object Structure data: functio ...