Friday, 28 September 2018

"errmsg":"Invalid JSON Response: response is not starting with { or [

"errmsg":"Invalid JSON Response: response is not starting with { or [


Calling Create createAlert -  { message : Exception while occuring : {"errmsg":"Invalid JSON Response: response is not starting with { or [ for operation Name","opstatus":5001,"httpStatusCode":200,"httpresponse":{"headers":{"X-Android-Received-Millis":"1538126431428","Cache-Control":"no-store, no-cache, must-revalidate","Access-Control-Allow-Methods":"GET, HEAD, POST, TRACE, OPTIONS, PUT, DELETE, PATCH","X-Kony-Service-Message":"Invalid JSON Response: response is not starting with { or [ for GET_COUNTRY_LIST","X-Android-Selected-Protocol":"http/1.1","Server":"Kony","X-Android-Sent-Millis":"1538126430220","X-Kony-RequestId":"6f897b62-d172-4ebe-b31a-f7136ce79b73","Date":"Fri, 28 Sep 2018 09:20:32 GMT","Access-Control-Allow-Origin":"*","X-Kony-Service-Opstatus":"5001","Content-Type":"text/plain;charset=UTF-8","X-Android-Response-Source":"NETWORK 200","Pragma":"no-cache","Content-Length":"130"},"url":"http://192.168.0.108:8080/services/GetCountryCode/GET_COUNTRY_LIST","responsecode":200}}, alertType : 0.0,  }



Kony-Service-Opstatus":"5001 :

solutions : Header is missing

var headers= {"Content-Type":"application/json"};

or other header


Monday, 17 September 2018

how to Check Internet Availability in Kony?




 isNetworkStatus : function() {

      var request = new kony.net.HttpRequest();
      var url = "https://google.com";
      request.open(constants.HTTP_METHOD_GET, url);
      request.onReadyStateChange = this.callbackHandler;
      request.timeout=0;
      request.send();

    },
    callbackHandler : function (request) {

    kony.print("----------------------chandru-----------------check Internet Availabilitiy---------");

      if(request.readyState == 4){
        var requeststatus = request.status;
        if(requeststatus == 200 || requeststatus == "200"){
          alert("online");
        }else{
          alert("offline");
        }
      }
   kony.print("----------------------chandru-----------------check Internet Availabilitiy-------");

    }

how to check Internet Connectivity in Android Native


public static boolean isInetConnectivityStatus() {
    boolean success = false;
    try {
        URL url = new URL("https://google.com");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(10000);
        connection.connect();
        success = connection.getResponseCode() == 200;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return success;
}

//purpose for to avoid android.os.NetworkOnMainThreadException
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
 StrictMode.setThreadPolicy(policy);

//isInternetWorking function calling
boolean resultOnlineStatus = isInetConnectivityStatus();
Toast.makeText(getApplicationContext(), "Status : "+resultOnlineStatus, Toast.LENGTH_SHORT).show();






Tuesday, 11 September 2018

To Find Device Type in kony


Kony Reference Architecture.

var types = kony.os.deviceInfo().name;
var deviceType = this.getDeviceType ;
if(types ==="android" && deviceType  === " Mobile"){

    kony.print("Android Mobile");

}else if(types ==="android" && deviceType  === " Tablet"){

   kony.print("Android Tablet");

}


getDeviceType : function(){

      try{
        var KonyMain = java.import("com.konylabs.android.KonyMain");
        var displayMetrics = java.import("android.util.DisplayMetrics");
        var Math = java.import("java.lang.Math");
        displayMetrics = KonyMain.getAppContext().getResources().getDisplayMetrics();
        var screenWidth  = displayMetrics.widthPixels / displayMetrics.xdpi;
        var screenHeight = displayMetrics.heightPixels / displayMetrics.ydpi;
        var size = Math.sqrt(Math.pow(screenWidth, 2) +
                             Math.pow(screenHeight, 2));
        if(size>=6)
          return "Tablet";
        else
          return "Mobile";
      }catch(err){
        kony.print("Error Exception is : "+JSON.stringify(err));
      }
    }

Monday, 10 September 2018

How to call Another Controller function




firstControllerfrom.js

define(function(){
  return {
    onNavigate : function(context){
      alert("Entering");
    },
    passDataAnother : function(){
      return "chandru";
    }
  };
});



secondControllerfrom.js

define(function(){

  return {

    onNavigate : function(context){
      kony.print("Entering");
    },
    callAnotherContr : function(){

      var controllerRef = require("firstControllerfrom");
      var result = controllerRef.passDataAnother ();

      alert("welcome "+result);
    }
  };
});

Friday, 7 September 2018

Get the file extention from file path




JAVA Example : 

public String getExt(String filePath){
        int strLength = filePath.lastIndexOf(".");
        if(strLength > 0)
            return filePath.substring(strLength + 1).toLowerCase();
        return null;
    }

JAVASCRIPT Example
function file_get_ext(filePathORname){
 return typeof filePathORname != "undefined" ? filePathORname.substring(filePathORname.lastIndexOf(".")+1, filePathORname.length).toLowerCase() : false;
}

How to get the Application Version Code using Kony NFI







 function getVersionControl (){
      try{
        var KonyMain = java.import("com.konylabs.android.KonyMain");
        var packageManager = java.import("android.content.pm.PackageManager");
        packageManager = KonyMain.getAppContext().getPackageManager();
        if (packageManager !== null) {
          try {
            packageInfo = packageManager.getPackageInfo(KonyMain.getAppContext().getPackageName(), 0);
            var  versionName = packageInfo.versionName;
            kony.print("Result print is : "+versionName);
            var  versionCode = packageInfo.versionCode;

            kony.print("Result print is : "+versionCode);
          } catch (eee) {
            kony.print("Exception is : "+JSON.stringify(eee));
          }
        }
      }catch(err){
        kony.print("Error Exception is : "+JSON.stringify(err));
      }
    }

Thursday, 6 September 2018

How to open PDF using Intent in KONY visualizer?


var pdfFilePath = "storage/emulated/0/filename.pdf";
function openPDFFile(pdfFilePath){

try{
        var KonyMain = java.import("com.konylabs.android.KonyMain");
        var File = java.import("java.io.File");
        var Intent = java.import("android.content.Intent");
        var Uri = java.import("android.net.Uri");
        var file = new File(pdfFilePath);
        var intentObject = new Intent(Intent.ACTION_VIEW);   
        intentObject.setDataAndType(Uri.fromFile(file), "application/pdf");
        intentObject.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        var contextObject = KonyMain.getActContext();
        contextObject.startActivity(intentObject);
      }catch(err){
        kony.print("Error in "+JSON.stringify(err));
      }
    }

A failure occurred while executing com.android.build.gradle.tasks

Error in Kony visualizer V9 service pack 6 and FX11  [2023-01-09 22:23:32.695] [DEBUG] ~~~~ - INFO [exec-shell] Execution failed for task ...