org.apache.cordova.LOG Java Examples

The following examples show how to use org.apache.cordova.LOG. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CordovaActivity.java    From wildfly-samples with MIT License 6 votes vote down vote up
@Override
/**
 * The final call you receive before your activity is destroyed.
 */
public void onDestroy() {
    LOG.d(TAG, "CordovaActivity.onDestroy()");
    super.onDestroy();

    // hide the splash screen to avoid leaking a window
    this.removeSplashScreen();

    if (this.appView != null) {
        appView.handleDestroy();
    }
    else {
        this.activityState = ACTIVITY_EXITING; 
    }
}
 
Example #2
Source File: FileHelper.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
Example #3
Source File: CordovaActivity.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
@Override
/**
 * The final call you receive before your activity is destroyed.
 */
public void onDestroy() {
    LOG.d(TAG, "CordovaActivity.onDestroy()");
    super.onDestroy();

    // hide the splash screen to avoid leaking a window
    this.removeSplashScreen();

    if (this.appView != null) {
        appView.handleDestroy();
    }
    else {
        this.activityState = ACTIVITY_EXITING; 
    }
}
 
Example #4
Source File: SystemWebViewClient.java    From BigDataPlatform with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        parentEngine.client.clearLoadTimeoutTimer();

        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }
    parentEngine.client.onReceivedError(errorCode, description, failingUrl);
}
 
Example #5
Source File: FileHelper.java    From reader with MIT License 6 votes vote down vote up
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
Example #6
Source File: CordovaWebViewClient.java    From CordovaYoutubeVideoPlayer with MIT License 6 votes vote down vote up
/**
 * Notify the host application that a page has started loading.
 * This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted
 * one time for the main frame. This also means that onPageStarted will not be called when the contents of an
 * embedded frame changes, i.e. clicking a link whose target is an iframe.
 *
 * @param view          The webview initiating the callback.
 * @param url           The url of the page.
 */
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    isCurrentlyLoading = true;
    LOG.d(TAG, "onPageStarted(" + url + ")");
    // Flush stale messages.
    this.appView.jsMessageQueue.reset();

    // Broadcast message that page has loaded
    this.appView.postMessage("onPageStarted", url);

    // Notify all plugins of the navigation, so they can clean up if necessary.
    if (this.appView.pluginManager != null) {
        this.appView.pluginManager.onReset();
    }
}
 
Example #7
Source File: AmazonWebViewOnUiThread.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
public void printBackForwardList() {

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                AmazonWebBackForwardList currentList = copyBackForwardList();
                int currentSize = currentList.getSize();
                for (int i = 0; i < currentSize; ++i) {
                    AmazonWebHistoryItem item = currentList.getItemAtIndex(i);
                    String url = item.getUrl();
                    LOG.d("cordovaamzn", "The URL at index: " + Integer.toString(i)
                        + "is " + url);
                }
            }
        });
    }
 
Example #8
Source File: FileUtils.java    From keemob with MIT License 6 votes vote down vote up
/**
 * Write contents of file.
 *
 * @param data				The contents of the file.
 * @param offset			The position to begin writing the file.
 * @param isBinary          True if the file contents are base64-encoded binary data
 */
/**/
public long write(String srcURLstr, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException {
    try {
    	LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr);
    	Filesystem fs = this.filesystemForURL(inputURL);
    	if (fs == null) {
    		throw new MalformedURLException("No installed handlers for this URL");
    	}

        long x = fs.writeToFileAtURL(inputURL, data, offset, isBinary); LOG.d("TEST",srcURLstr + ": "+x); return x;
    } catch (IllegalArgumentException e) {
        MalformedURLException mue = new MalformedURLException("Unrecognized filesystem URL");
        mue.initCause(e);
    	throw mue;
    }

}
 
Example #9
Source File: FileUtils.java    From keemob with MIT License 6 votes vote down vote up
private JSONObject requestAllPaths() throws JSONException {
    Context context = cordova.getActivity();
    JSONObject ret = new JSONObject();
    ret.put("applicationDirectory", "file:///android_asset/");
    ret.put("applicationStorageDirectory", toDirUrl(context.getFilesDir().getParentFile()));
    ret.put("dataDirectory", toDirUrl(context.getFilesDir()));
    ret.put("cacheDirectory", toDirUrl(context.getCacheDir()));
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      try {
        ret.put("externalApplicationStorageDirectory", toDirUrl(context.getExternalFilesDir(null).getParentFile()));
        ret.put("externalDataDirectory", toDirUrl(context.getExternalFilesDir(null)));
        ret.put("externalCacheDirectory", toDirUrl(context.getExternalCacheDir()));
        ret.put("externalRootDirectory", toDirUrl(Environment.getExternalStorageDirectory()));
      }
      catch(NullPointerException e) {
        /* If external storage is unavailable, context.getExternal* returns null */
          LOG.d(LOG_TAG, "Unable to access these paths, most liklely due to USB storage");
      }
    }
    return ret;
}
 
Example #10
Source File: SystemWebViewClient.java    From lona with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        parentEngine.client.clearLoadTimeoutTimer();

        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }
    parentEngine.client.onReceivedError(errorCode, description, failingUrl);
}
 
Example #11
Source File: PermissionHelper.java    From cordova-background-geolocation-services with Apache License 2.0 6 votes vote down vote up
/**
 * Requests "dangerous" permissions for the application at runtime. This is a helper method
 * alternative to cordovaInterface.requestPermissions() that does not require the project to be
 * built with cordova-android 5.0.0+
 *
 * @param plugin        The plugin the permissions are being requested for
 * @param requestCode   A requestCode to be passed to the plugin's onRequestPermissionResult()
 *                      along with the result of the permissions request
 * @param permissions   The permissions to be requested
 */
public static void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) {
    try {
        Method requestPermission = CordovaInterface.class.getDeclaredMethod(
                "requestPermissions", CordovaPlugin.class, int.class, String[].class);

        // If there is no exception, then this is cordova-android 5.0.0+
        requestPermission.invoke(plugin.cordova, plugin, requestCode, permissions);
    } catch (NoSuchMethodException noSuchMethodException) {
        // cordova-android version is less than 5.0.0, so permission is implicitly granted
        LOG.d(LOG_TAG, "No need to request permissions " + Arrays.toString(permissions));

        // Notify the plugin that all were granted by using more reflection
        deliverPermissionResult(plugin, requestCode, permissions);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when requesting permissions " + Arrays.toString(permissions), illegalAccessException);
    } catch(InvocationTargetException invocationTargetException) {
        // This method does not throw any exceptions, so this should never be caught
        LOG.e(LOG_TAG, "invocationTargetException when requesting permissions " + Arrays.toString(permissions), invocationTargetException);
    }
}
 
Example #12
Source File: CordovaActivity.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
@Override
/**
 * Called when the system is about to start resuming a previous activity.
 */
protected void onPause() {
    super.onPause();

    LOG.d(TAG, "Paused the application!");

    // Don't process pause if shutting down, since onDestroy() will be called
    if (this.activityState == ACTIVITY_EXITING) {
        return;
    }

    if (this.appView == null) {
        return;
    }
    else
    {
        this.appView.handlePause(this.keepRunning);
    }

    // hide the splash screen to avoid leaking a window
    this.removeSplashScreen();
}
 
Example #13
Source File: CordovaActivity.java    From reader with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
@Deprecated // Call init() instead and override makeWebView() to customize.
public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) {
    LOG.d(TAG, "CordovaActivity.init()");

    appView = webView != null ? webView : makeWebView();
    if (appView.pluginManager == null) {
        appView.init(this, webViewClient != null ? webViewClient : makeWebViewClient(appView),
                webChromeClient != null ? webChromeClient : makeChromeClient(appView),
                pluginEntries, internalWhitelist, externalWhitelist, preferences);
    }

    // TODO: Have the views set this themselves.
    if (preferences.getBoolean("DisallowOverscroll", false)) {
        appView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    }
    createViews();

    // TODO: Make this a preference (CB-6153)
    // Setup the hardware volume controls to handle volume control
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
 
Example #14
Source File: NetworkManager.java    From ultimate-cordova-webview-app with MIT License 6 votes vote down vote up
/**
 * Updates the JavaScript side whenever the connection changes
 *
 * @param info the current active network info
 * @return
 */
private void updateConnectionInfo(NetworkInfo info) {
    // send update to javascript "navigator.network.connection"
    // Jellybean sends its own info
    JSONObject thisInfo = this.getConnectionInfo(info);
    if(!thisInfo.equals(lastInfo))
    {
        String connectionType = "";
        try {
            connectionType = thisInfo.get("type").toString();
        } catch (JSONException e) {
            LOG.d(LOG_TAG, e.getLocalizedMessage());
        }

        sendUpdate(connectionType);
        lastInfo = thisInfo;
    }
}
 
Example #15
Source File: CordovaWebViewClient.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // Clear timeout flag
    this.appView.loadUrlTimeout++;

    // Handle error
    JSONObject data = new JSONObject();
    try {
        data.put("errorCode", errorCode);
        data.put("description", description);
        data.put("url", failingUrl);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    this.appView.postMessage("onReceivedError", data);
}
 
Example #16
Source File: SystemWebViewClient.java    From app-icon with MIT License 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        parentEngine.client.clearLoadTimeoutTimer();

        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }
    parentEngine.client.onReceivedError(errorCode, description, failingUrl);
}
 
Example #17
Source File: InAppChromeClient.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
/**
 * Handle database quota exceeded notification.
 *
 * @param url
 * @param databaseIdentifier
 * @param currentQuota
 * @param estimatedSize
 * @param totalUsedQuota
 * @param quotaUpdater
 */
@Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
        long totalUsedQuota, AmazonWebStorage.QuotaUpdater quotaUpdater)
{
    LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d  currentQuota: %d  totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);

    if (estimatedSize < MAX_QUOTA)
    {
        //increase for 1Mb
        long newQuota = estimatedSize;
        LOG.d(LOG_TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
        quotaUpdater.updateQuota(newQuota);
    }
    else
    {
        // Set the quota to whatever it is and force an error
        // TODO: get docs on how to handle this properly
        quotaUpdater.updateQuota(currentQuota);
    }
}
 
Example #18
Source File: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 6 votes vote down vote up
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);

    // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager.getInstance().sync();
    }

    // https://issues.apache.org/jira/browse/CB-11248
    view.clearFocus();
    view.requestFocus();

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);

        sendUpdate(obj, true);
    } catch (JSONException ex) {
        LOG.d(LOG_TAG, "Should never happen");
    }
}
 
Example #19
Source File: SystemWebViewClient.java    From ultimate-cordova-webview-app with MIT License 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        parentEngine.client.clearLoadTimeoutTimer();

        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }
    parentEngine.client.onReceivedError(errorCode, description, failingUrl);
}
 
Example #20
Source File: InAppChromeClient.java    From reader with MIT License 6 votes vote down vote up
/**
 * Handle database quota exceeded notification.
 *
 * @param url
 * @param databaseIdentifier
 * @param currentQuota
 * @param estimatedSize
 * @param totalUsedQuota
 * @param quotaUpdater
 */
@Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
        long totalUsedQuota, AmazonWebStorage.QuotaUpdater quotaUpdater)
{
    LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d  currentQuota: %d  totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);

    if (estimatedSize < MAX_QUOTA)
    {
        //increase for 1Mb
        long newQuota = estimatedSize;
        LOG.d(LOG_TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
        quotaUpdater.updateQuota(newQuota);
    }
    else
    {
        // Set the quota to whatever it is and force an error
        // TODO: get docs on how to handle this properly
        quotaUpdater.updateQuota(currentQuota);
    }
}
 
Example #21
Source File: CameraLauncher.java    From jpHolo with MIT License 6 votes vote down vote up
/**
 * Create entry in media store for image
 *
 * @return uri
 */
private Uri getUriFromMediaStore() {
    ContentValues values = new ContentValues();
    values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    Uri uri;
    try {
        uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    } catch (RuntimeException e) {
        LOG.d(LOG_TAG, "Can't write to external media storage.");
        try {
            uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
        } catch (RuntimeException ex) {
            LOG.d(LOG_TAG, "Can't write to internal media storage.");
            return null;
        }
    }
    return uri;
}
 
Example #22
Source File: CordovaWebViewClient.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedLoadError(XWalkView view, int errorCode, String description,
        String failingUrl) {
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // Clear timeout flag
    this.appView.loadUrlTimeout++;

    // Handle error
    JSONObject data = new JSONObject();
    try {
        data.put("errorCode", errorCode);
        data.put("description", description);
        data.put("url", failingUrl);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    this.appView.postMessage("onReceivedError", data);
}
 
Example #23
Source File: X5WebViewClient.java    From x5webview-cordova-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        parentEngine.client.clearLoadTimeoutTimer();

        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }
    parentEngine.client.onReceivedError(errorCode, description, failingUrl);
}
 
Example #24
Source File: SystemWebViewClient.java    From pychat with MIT License 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
@SuppressWarnings("deprecation")
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        parentEngine.client.clearLoadTimeoutTimer();

        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }
    parentEngine.client.onReceivedError(errorCode, description, failingUrl);
}
 
Example #25
Source File: SystemWebViewClient.java    From keemob with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
Example #26
Source File: CordovaActivity.java    From wildfly-samples with MIT License 6 votes vote down vote up
@Override
/**
 * Called when the system is about to start resuming a previous activity.
 */
protected void onPause() {
    super.onPause();

    LOG.d(TAG, "Paused the application!");

    // Don't process pause if shutting down, since onDestroy() will be called
    if (this.activityState == ACTIVITY_EXITING) {
        return;
    }

    if (this.appView == null) {
        return;
    }
    else
    {
        this.appView.handlePause(this.keepRunning);
    }

    // hide the splash screen to avoid leaking a window
    this.removeSplashScreen();
}
 
Example #27
Source File: PermissionHelper.java    From cordova-plugin-dbmeter with Apache License 2.0 6 votes vote down vote up
/**
 * Requests "dangerous" permissions for the application at runtime. This is a helper method
 * alternative to cordovaInterface.requestPermissions() that does not require the project to be
 * built with cordova-android 5.0.0+
 *
 * @param plugin        The plugin the permissions are being requested for
 * @param requestCode   A requestCode to be passed to the plugin's onRequestPermissionResult()
 *                      along with the result of the permissions request
 * @param permissions   The permissions to be requested
 */
public static void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) {
    try {
        Method requestPermission = CordovaInterface.class.getDeclaredMethod(
                "requestPermissions", CordovaPlugin.class, int.class, String[].class);

        // If there is no exception, then this is cordova-android 5.0.0+
        requestPermission.invoke(plugin.cordova, plugin, requestCode, permissions);
    } catch (NoSuchMethodException noSuchMethodException) {
        // cordova-android version is less than 5.0.0, so permission is implicitly granted
        LOG.d(LOG_TAG, "No need to request permissions " + Arrays.toString(permissions));

        // Notify the plugin that all were granted by using more reflection
        deliverPermissionResult(plugin, requestCode, permissions);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when requesting permissions " + Arrays.toString(permissions), illegalAccessException);
    } catch(InvocationTargetException invocationTargetException) {
        // This method does not throw any exceptions, so this should never be caught
        LOG.e(LOG_TAG, "invocationTargetException when requesting permissions " + Arrays.toString(permissions), invocationTargetException);
    }
}
 
Example #28
Source File: SystemWebViewEngine.java    From keemob with MIT License 5 votes vote down vote up
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
Example #29
Source File: SystemWebViewClient.java    From chappiecast with Mozilla Public License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
Example #30
Source File: SystemWebViewEngine.java    From BigDataPlatform with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void evaluateJavascript(String js, ValueCallback<String> callback) {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        webView.evaluateJavascript(js, callback);
    }
    else
    {
        LOG.d(TAG, "This webview is using the old bridge");
    }
}