Monday, 9 July 2018

Degrading android version to build the APK

To build an apk for android device, you need to first degrade your android version to 6.2.3.

Here is the command to remove the existing Android version.

Steps: You have to go to your Hybrid folder in your root directory.

command: cordova platform remove android

Example: D:\SVN Repo\07-06-2018\MOBILEAPP\hybrid>cordova platform remove android

Here is the command to add the Android version.

command: cordova platform add android@6.2.3

Example: D:\SVN Repo\07-06-2018\MOBILEAPP\hybrid>cordova platform add android@6.2.3

Once you have added the Android version then build your apk file to run on the mobile device.

Grunt command: 

Build project: build --platform=android
Run project: serve --platform=android --device=Nexus_6P_API_27

Ojet command to generate the debug- apk file

ojet build android

Note : Use ojet command to build the apk. This is more stable.

Your apk path:

 D:/SVN Repo/07-06-2018/MOBILEAPP/hybrid/platforms/android/build/outputs/apk/android-debug.apk


Sunday, 8 July 2018

Code to retrieve an image from Oracle mobile cloud Storage collection

Calling the Storage API from Your App


Here’s code you can use to retrieve an image :

<html>
<body>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<img id="img" width=100%>


<script>
jQuery.ajax({
async: true,
  crossDomain: true,
  cache:false,
        url:'https://Your IDCS domain/mobile/platform/storage/collections/Your Collection name/objects/Your image object Id',
        method: "GET",
  headers: {
    authorization: "Your Mobile backend Authorization token",
    
'oracle-mobile-backend-id': "Your Mobile Backend ID"
   
},
xhr:function(){
            var xhr = new XMLHttpRequest();
            xhr.responseType= 'blob'
            return xhr;
        },success: function(data){
            var img = document.getElementById('img');
            var url = window.URL || window.webkitURL;
            img.src = url.createObjectURL(data);
        },
        error:function(){
            
        }
    });
</script>
</body>
</html>

Wednesday, 4 July 2018

Get State,City name from a latitude and longitude

JavaScript and Geolocation

In our JavaScript, we can use getCurrentPosition() method to obtain user’s current location, but first, we need to know whether Geolocation API is available in the browser before we can continue.

Geolocation API is an important feature available in modern HTML5 web browsers, which allows us to request current location of the user using JavaScript, the location information is represented by latitude and longitude coordinates. For privacy reasons, the user permission is required to access its location information.



<p><button onclick="getLocation()">Get My Location</button></p>
<p id="demo"></p>
<script src="http://maps.google.com/maps/api/js?key=AIzaSyCiRgLZ_8pFomu9f-7TEzhsgQmY4Q-c11c"></script>

<script>
var x=document.getElementById("demo");
function getLocation(){
    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
    else{
        x.innerHTML="Geolocation is not supported by this browser.";
    }
}

function showPosition(position){
    lat=position.coords.latitude;
    lon=position.coords.longitude;
    displayLocation(lat,lon);
}

function showError(error){
    switch(error.code){
        case error.PERMISSION_DENIED:
            x.innerHTML="User denied the request for Geolocation."
        break;
        case error.POSITION_UNAVAILABLE:
            x.innerHTML="Location information is unavailable."
        break;
        case error.TIMEOUT:
            x.innerHTML="The request to get user location timed out."
        break;
        case error.UNKNOWN_ERROR:
            x.innerHTML="An unknown error occurred."
        break;
    }
}

function displayLocation(latitude,longitude){
    var geocoder;
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(latitude, longitude);

    geocoder.geocode(
        {'latLng': latlng},
        function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[0]) {
                    var add= results[0].formatted_address ;
                    var  value=add.split(",");

                    count=value.length;
                    country=value[count-1];
                    state=value[count-2];
                    city=value[count-3];
                    x.innerHTML = "state name is: " + state ;

<!--Below method is used to remove PIN Code from the String using Regex method. You can use an online tool to customize your String. https://txt2re.com/index-javascript.php3?s=Uttar%20Pradesh%20201301&11&4-->

var txt=state;
      var re4='(\\s+)'; // White Space 1
      var re5='(\\d+)'; // Integer Number 1

      var p = new RegExp(re4+re5,["i"]);
      var m = p.exec(txt);
      if (m != null)
      {
          var ws1=m[1];
          var int1=m[2];

  var remove = ws1 + int1;

          <!-- document.write("("+ws1.replace(/</,"&lt;")+")"+"("+int1.replace(/</,"&lt;")+")"+"\n"); -->
    var res = txt.replace(remove, "");

x.innerHTML = "state name is: " + res ;

      }


                }
                else  {
                    x.innerHTML = "address not found";
                }
            }
            else {
                x.innerHTML = "Geocoder failed due to: " + status;
            }
        }
    );
}

</script>