Search in sources :

Example 31 with JavascriptInterface

use of android.webkit.JavascriptInterface in project Gadgetbridge by Freeyourgadget.

the class JSInterface method getAppStoredPreset.

@JavascriptInterface
public String getAppStoredPreset() {
    try {
        File destDir = PebbleUtils.getPbwCacheDir();
        File configurationFile = new File(destDir, this.mUuid.toString() + "_preset.json");
        if (configurationFile.exists()) {
            return FileUtils.getStringFromFile(configurationFile);
        }
    } catch (IOException e) {
        GB.toast("Error reading presets", Toast.LENGTH_LONG, GB.ERROR);
        LOG.warn("Error reading presets", e);
    }
    return null;
}
Also used : IOException(java.io.IOException) File(java.io.File) JavascriptInterface(android.webkit.JavascriptInterface)

Example 32 with JavascriptInterface

use of android.webkit.JavascriptInterface in project Gadgetbridge by Freeyourgadget.

the class JSInterface method getCurrentPosition.

@JavascriptInterface
public String getCurrentPosition() {
    if (!isLocationEnabledForWatchApp()) {
        return "";
    }
    // we need to override this because the coarse location is not enough for the android webview, we should add the permission for fine location.
    JSONObject geoPosition = new JSONObject();
    JSONObject coords = new JSONObject();
    try {
        CurrentPosition currentPosition = new CurrentPosition();
        geoPosition.put("timestamp", currentPosition.timestamp);
        coords.put("latitude", currentPosition.getLatitude());
        coords.put("longitude", currentPosition.getLongitude());
        coords.put("accuracy", currentPosition.accuracy);
        coords.put("altitude", currentPosition.altitude);
        coords.put("speed", currentPosition.speed);
        geoPosition.put("coords", coords);
    } catch (JSONException e) {
        LOG.warn(e.getMessage());
    }
    LOG.info("WEBVIEW - geo position" + geoPosition.toString());
    return geoPosition.toString();
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JavascriptInterface(android.webkit.JavascriptInterface)

Aggregations

JavascriptInterface (android.webkit.JavascriptInterface)32 JSONObject (org.json.JSONObject)9 JSONException (org.json.JSONException)7 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 WebViewClient (android.webkit.WebViewClient)4 IOException (java.io.IOException)4 Annotation (java.lang.annotation.Annotation)4 Method (java.lang.reflect.Method)4 File (java.io.File)3 SharedPreferences (android.content.SharedPreferences)2 IBaseForumPost (forpdateam.ru.forpda.api.IBaseForumPost)2 HashMap (java.util.HashMap)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SslError (android.net.http.SslError)1 Bundle (android.os.Bundle)1 AlertDialog (android.support.v7.app.AlertDialog)1 JsPromptResult (android.webkit.JsPromptResult)1