To add to code which was writhed for desktop devices also code which will work for android.

I have code for PC operating systems for my app. And it works also fine on android. But now would like to
 add to general desktop <scrip><script/> also code to make my app run while  screen is off on android.

How is possible to do this?

I was googling for code, but i could find only code for android os.

Actually what is the way to solve problems as this. To add  to code which was writhed for desktop devices also code which will work for android?
Ivan GolubarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brandon LyonSenior Frontend DeveloperCommented:
I'm not sure that there is a way around this without building a mobile app. Phones have to aggressively manage battery life. When the screen is off most apps stop running unless they're whitelisted in a battery manager. On a mobile device, usually any website which isn't visible isn't running. If you built a mobile app then you can request that the app keep running when the display is off.
0
Ivan GolubarAuthor Commented:
Thank you. I don't have any idea how to write mobile app.
 
But probably i could use all my exiting code and just add preventing app to stop running when screen is of?
0
Brandon LyonSenior Frontend DeveloperCommented:
What is the app you are building trying to do and why does it need to run in the background? That will help determine how to get it to run in the background.
0
Ivan GolubarAuthor Commented:
Next is all code.
It reads bitcoin value from bitstamp (bitcoin value) page on intervals sent from select element.
It takes last fife readings and calculate the arithmetic average. It does it every reading. If last  three reading are  going up it beeps "up" and if last three reading are going down it beeps "down".

So if screen switches off, i don't get beeps from my phone.

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BTC</title>

<style type="text/css">

#tablescroll {
  height:500px;
  overflow-y: scroll;  
width: fit-content;
}


#buyButtonID{
 width: 200px; 
 height:80px;
 font-weight: 700;
  font-size: 30px;
}
#sellButtonID{
 width: 200px; 
 height:80px;
 font-size: 30px;
}
#newButtonID{

}
#settingsBcdID{
    
}
#CalculationsWindowID{ 
margin: 30px;  
}
#timeBtcID{ 
    float: left;
    margin: 10px;
    /* background-color: #e6f2ff;
    border-style: solid;
    border-width: 1px;*/
}
#newBtcID{ 
    float: left;
    margin: 10px ;
}

#oldBtcID{ 
     float: left;
    margin: 10px;
}
#differenceBtcID{ 
    float: left;
    margin: 10px;}
#updownnBtcID{ 
    float: left;
    margin: 10px;}
#summaaBtcID{ 
    float: left;
    margin: 10px;
}
#round5BtcID{ 
    float: left;
    margin: 10px;}    
</style>
 <script src="/wp-content/themes/n4/js/jquery-3.2.1.min.js"></script>
<script>
  var btcData=[];
  var refButton ;
  var tableBtc;
  var myBtc;
  var textBtc;
  var myTime;
  var lastV;
  var calculate1;
  var selectTime;
  var boughtBtc=0;
  var choice2;
  var sumasumaG=0;
  var sumasuma=0;
  var sellValue=0;
  var r=1;
 
var myVarT;
var beepVol=0.5;
var volcontrol;
function myTimerLow() {
    snd = new Audio("/wp-content/themes/n4/project_folder/high.wav");
    snd.volume = beepVol;
    snd.play();
   clearInterval(myVarT);
}
function myTimerHigh() {
    snd = new Audio("/wp-content/themes/n4/project_folder/low.wav");
    snd.volume = beepVol;
    snd.play();
   clearInterval(myVarT);
}

var lowButton;
var snd;
function playhigh(){
        snd = new Audio("/wp-content/themes/n4/project_folder/low.wav");
        snd.volume =beepVol*0.5;
        snd.play();
        myVarT = setInterval(function(){ myTimerLow() }, 500);
        }
 var highButton;    
 function playlow(){
        snd = new Audio("/wp-content/themes/n4/project_folder/high.wav");
        snd.volume = beepVol*0.5;
        snd.play();
        myVarT = setInterval(function(){ myTimerHigh() }, 500);
        
    } 


function onBuy(choice){
    if (lastV==null){
        alert("Read data as first");
        return;
    }
    if (choice =="Buy"){
  boughtBtc=lastV;
  choice2="Buy";
  document.getElementById("buyButtonID").style.color='#52CA4A  ';
  document.getElementById("buyButtonID").value='Buying';
   document.getElementById("sellButtonID").disabled = false;
  
    }else{choice2="Sell";
         document.getElementById("buyButtonID").style.borderColor = '';
         document.getElementById("buyButtonID").style.color = '';
         document.getElementById("buyButtonID").value='Buy';
         document.getElementById("sellButtonID").disabled = true;
         sellValue=sumasumaG;
    }
  newIDf();  
}
function calculateProfit(){
    if (choice2 =="Buy"){
   sumasumaG=sumasumaG+calculate1; 
    }
}

 var Jcal5=0;
      var Jcal4=0;
      var Jcal3=0;
      var Jcal2=0;
      var Jcal1=0;
      var calculateJ;
      var soundon=true;
function calculateF3(){/////////////////////////////////////////////////////////////___________________calculate 3
      Jcal5=Jcal4;
      Jcal4=Jcal3;
      Jcal3=Jcal2;
      Jcal2=Jcal1;
      Jcal1=calculate1;
     calculateJ=Math.round((Jcal1+Jcal2+Jcal3+Jcal4+Jcal5)/5 * 10) / 10;
     cal3=cal2;
     cal2=cal1;
     cal1= calculateJ;
     console.log(cal1+"  calculate1");
     console.log(cal2+"  cal2");
     console.log(cal3+"  cal3");
     if ((cal1 > cal2 && cal2 > cal3)&&(updown2!="Up")){
         updown="Up";
         updown2=updown;
         Calculate1up=lastV;
         if (soundon==true){playhigh();}
       //playhigh();
     }else{
         if ((cal3 > cal2 && cal2 > cal1)&&(updown2!="Down")){
             updown="Down";
             updown2=updown;
             calculate1down= lastV;
            if (soundon==true){playlow();}
          //playlow();
         }
         else
         {updown="/";
         }
       // calculateProfit();
     }
  
 }
 var ii=1;
var cal1;
var cal2;
var cal3;
var updown="/";
var updown2;
 var sumasumaGold=0;
var Calculate1up=0;
var calculate1down=0;
 var sumaJPrevious=0;
 var sumaJ=0;
 var updownJ;
var objDiv;

function newIDf(){

    $.ajax({
  method:"POST",
 url: 'https://www.bitstamp.net/api/ticker/',//_________________________________________________________________get data
  data:  {
    },
    datatype: "text",
    success: function(strdate){
   console.log(strdate);
     console.log(strdate["last"]);
     lastV=strdate["last"];
      var timestampV=strdate["timestamp"];
       date = new Date(timestampV * 1000);

   var zear=date.getFullYear();
   var month=date.getMonth();
   var day=date.getDate();
   var hour=date.getHours();
   var Min=date.getMinutes();
   var sec=date.getSeconds();
   myTime=zear+'-'+month+'-'+day+' '+hour+':'+Min+':'+sec;
   console.log(myTime);
       var row = timeBtc.insertRow(r);
       var cell1 = row.insertCell(0);
       cell1.innerHTML = myTime;
       var row = newBtc.insertRow(r);
       var cell1 = row.insertCell(0);
       cell1.innerHTML = lastV;
       var previousV= lastV;
       var row = oldBtc.insertRow(r);
       var cell1 = row.insertCell(0);
       cell1.innerHTML =newBtc.rows[r-1].cells[0].innerHTML;
       var row = differenceBtc.insertRow(r);
       var cell1 = row.insertCell(0);
       calculate1 = newBtc.rows[r].cells[0].innerHTML-newBtc.rows[r-1].cells[0].innerHTML;
       if (isNaN(calculate1)){calculate1=0};
       calculate1=Math.round(calculate1 * 1) / 1; 
       cell1.innerHTML=calculate1;
       calculateF3();
       var row = round5Btc.insertRow(r);
       var cell1 = row.insertCell(0);
       cell1.innerHTML =calculateJ;
        var row = updownnBtc.insertRow(r);
       var cell1 = row.insertCell(0);
       cell1.innerHTML = updown;
        var row = summaaBtc.insertRow(r);
       var cell1 = row.insertCell(0);
       sumasumaG=Math.round(sumasumaG * 1) / 1;
       if (choice2 =="Buy"){
       if (sellValue==0){sumasumaG=sumasumaG+calculate1;}
       else{sumasumaG=sellValue;sellValue=0;}
       cell1.innerHTML = sumasumaG;
       if (calculate1>=0){row.style.backgroundColor = "lime";}else{row.style.backgroundColor = "red";}
       }else{cell1.innerHTML = 0};
       r=r+1;
     },
     error: function(error, txtStatus) {
      console.log(txtStatus);
      console.log('error');
    }
 });
  objDiv.scrollTop = objDiv.scrollHeight; 
}
var checkBoxVolumeOFF;
var checkBoxVolumeON;
function CBchangeONF(){
      checkBoxVolumeOFF.checked=false;
      soundon=true;
     
}
function CBchangeOFFF(){
      checkBoxVolumeON.checked=false;
      soundon=false;
     
}
   window.onload = function(){
  var interval = false;
    var tick = 1;
     setTimer(0.16);
     document.getElementById('selectTimeID').addEventListener('change', function() {
    setTimer(this.value);
  });
   function setTimer(minutes)
  {
    if (interval) clearInterval(interval);
    interval = setInterval(newIDf, minutes * 60 * 1000);
  }
           round5Btc=document.getElementById("round5BtcID");
           timeBtc=document.getElementById("timeBtcID");
            newBtc=document.getElementById("newBtcID");
             oldBtc=document.getElementById("oldBtcID");
            updownnBtc=document.getElementById("updownnBtcID");
            summaaBtc=document.getElementById("summaaBtcID");
            highButton=document.getElementById("highButtonID");
              lowButton=document.getElementById("lowButtonID");
            highButton.onclick=playhigh; 
             lowButton.onclick=playlow; 
             differenceBtc=document.getElementById("differenceBtcID");
              newButton = document.getElementById("newButtonID");
              volcontrol=document.getElementById("volcontrolID");
              volcontrol.value=20;
               beepVol= volcontrol.value/100; 
                checkBoxVolumeOFF=document.getElementById("checkBoxVolumeOFFid");
                checkBoxVolumeON=document.getElementById("checkBoxVolumeONid");
                  checkBoxVolumeOFF.onchange=CBchangeOFFF;
                checkBoxVolumeON.onchange=CBchangeONF;
               objDiv = document.getElementById("tablescroll");

             newButton.onclick = function() {
                newIDf();
            }
        }
  function volumeChange(){
      console.log(volcontrol.value/100);
   beepVol= volcontrol.value/100; 
  }   
   
</script>
</head>
<body>

<div id="settingsBcdID">
  <input type="button" id="newButtonID" value="Read data now" style="display:inline-block"/>
  &nbsp; &nbsp;or on every:&nbsp;<select id="selectTimeID" style="display:inline-block">
   <option value="0.16">10 sec</option>
   <option value="1">1 min</option>
   <option value="5">5 min</option>
   <option value="15">15 min</option>
   <option value="30">30 min</option>
   <option value="60">60 min</option>
  </select> &nbsp; &nbsp; &nbsp; &nbsp;
  <div><br><br>
   Sound on automatic reading  &nbsp;Enabled&nbsp;<input id="checkBoxVolumeONid" type="checkbox" checked >&nbsp;Disabled&nbsp;<input id="checkBoxVolumeOFFid" type="checkbox"><br><br>
   Test sound&nbsp;<input type="button" id="highButtonID" value="Up" />
   <input type="button" id="lowButtonID" value="Down" /><br><br>
   Volume&nbsp;&nbsp;<input id="volcontrolID" type="range" min="0" max="100" step="1" value="25" onChange="volumeChange()"></input>
  </div>
 </div><br><br>
<div id="tablewrapper">
<div id="tablescroll">
<table id="timeBtcID">
    <tr>
         <th >Date time</th>
    </tr>
</table>
<table id="newBtcID">
    <tr>
         <th >Actual</th>
    </tr>
</table>
<table id="oldBtcID">
 <tr>
         <th>Previous</th>
    </tr>
</table>
<table id="differenceBtcID">
 <tr>
         <th>Diference</th>
    </tr>
</table>
<table id="round5BtcID">
 <tr>
         <th>Round last 5</th>
    </tr>
</table>
<table id="updownnBtcID">
 <tr>
         <th>Up/Down</th>
    </tr>
</table>

<table id="summaaBtcID">
 <tr>
         <th>Profit</th>
    </tr>
</table>
</div>
</div>
</div>
<div>
   <div id="CalculationsWindowID">
    <input type="button" id="buyButtonID" value="Buy" onClick="onBuy('Buy')" style="display:inline-block;"  />&nbsp; &nbsp; &nbsp; &nbsp;
    <input type="button" disabled id="sellButtonID" value="Sell" onClick="onBuy('Sell')"  style="display:inline-block" />
   </div>
</div><br>
</body>
</html>

Open in new window

0
Brandon LyonSenior Frontend DeveloperCommented:
Unfortunately that won't be possible on a phone using a plain website. What I would recommend is to add an API to your website which uses a service such as IFTTT in order to trigger an alert on your phone.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.