Example usage for android.app Activity getPackageName

List of usage examples for android.app Activity getPackageName

Introduction

In this page you can find the example usage for android.app Activity getPackageName.

Prototype

@Override
    public String getPackageName() 

Source Link

Usage

From source file:org.videolan.vlc.util.Permissions.java

private static Dialog createSettingsDialogCompat(final Activity activity, int mode) {
    int titleId = 0, textId = 0;
    String action = Settings.ACTION_MANAGE_WRITE_SETTINGS;
    switch (mode) {
    case PERMISSION_SYSTEM_RINGTONE:
        titleId = R.string.allow_settings_access_ringtone_title;
        textId = R.string.allow_settings_access_ringtone_description;
        break;//from  w  w  w.j  a v  a  2s.  c o m
    case PERMISSION_SYSTEM_BRIGHTNESS:
        titleId = R.string.allow_settings_access_brightness_title;
        textId = R.string.allow_settings_access_brightness_description;
        break;
    case PERMISSION_SYSTEM_DRAW_OVRLAYS:
        titleId = R.string.allow_draw_overlays_title;
        textId = R.string.allow_sdraw_overlays_description;
        action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
        break;
    }
    final String finalAction = action;
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setTitle(activity.getString(titleId))
            .setMessage(activity.getString(textId)).setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(activity.getString(R.string.permission_ask_again),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            SharedPreferences settings = PreferenceManager
                                    .getDefaultSharedPreferences(activity);
                            Intent i = new Intent(finalAction);
                            i.setData(Uri.parse("package:" + activity.getPackageName()));
                            try {
                                activity.startActivity(i);
                            } catch (Exception ex) {
                            }
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putBoolean("user_declined_settings_access", true);
                            editor.apply();
                        }
                    });
    return dialogBuilder.show();
}

From source file:com.lypeer.fcpermission.FcPermissionsB.java

/**
 * ????????/*  w w  w  .ja va2s . c  om*/
 */
private boolean checkDeniedPermissionsNeverAskAgain(final Object object, String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton,
        @Nullable DialogInterface.OnClickListener negativeButtonOnClickListener, List<String> deniedPerms) {
    boolean shouldShowRationale;
    for (String perm : deniedPerms) {
        shouldShowRationale = shouldShowRequestPermissionRationale(object, perm);
        if (!shouldShowRationale) {
            final Activity activity = getActivity(object);
            if (null == activity) {
                return true;
            }

            AlertDialog dialog = new AlertDialog.Builder(activity).setMessage(rationale)
                    .setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                            intent.setData(uri);
                            startAppSettingsScreen(object, intent);
                        }
                    }).setNegativeButton(negativeButton, negativeButtonOnClickListener).create();
            dialog.show();

            return true;
        }
    }

    return false;
}

From source file:com.irccloud.android.IRCCloudApplicationBase.java

public void onPause(final Activity context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (notifierSockerTimerTask != null)
        notifierSockerTimerTask.cancel();
    notifierSockerTimerTask = new TimerTask() {
        @Override//from   ww w.  j a v  a 2 s.  c o m
        public void run() {
            notifierSockerTimerTask = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
                    if (info.processName.equals(context.getPackageName())
                            && info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
                        return;
                }
            }
            if (!conn.notifier && conn.getState() == NetworkConnection.STATE_CONNECTED) {
                conn.disconnect();
                if (ServersList.getInstance().count() < 1) {
                    Crashlytics.log(Log.DEBUG, "IRCCloud",
                            "No servers configured, not connecting notifier socket");
                    return;
                }
                if (!(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && cm.isActiveNetworkMetered() && cm
                        .getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED)) {
                    try {
                        Thread.sleep(1000);
                        conn.notifier = true;
                        conn.connect();
                    } catch (Exception e) {
                    }
                }
            }
        }
    };

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && cm.isActiveNetworkMetered()
            && cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED) {
        notifierTimer.schedule(notifierSockerTimerTask, 5000);
    } else {
        notifierTimer.schedule(notifierSockerTimerTask, 300000);
    }
}

From source file:org.apache.cordova.file.FileUtils.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    this.filesystems = new ArrayList<Filesystem>();

    String tempRoot = null;//from w  w  w  .  ja  v  a 2 s. com
    String persistentRoot = null;

    Activity activity = cordova.getActivity();
    String packageName = activity.getPackageName();

    String location = preferences.getString("androidpersistentfilelocation", "internal");

    tempRoot = activity.getCacheDir().getAbsolutePath();
    if ("internal".equalsIgnoreCase(location)) {
        persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
        this.configured = true;
    } else if ("compatibility".equalsIgnoreCase(location)) {
        /*
         *  Fall-back to compatibility mode -- this is the logic implemented in
         *  earlier versions of this plugin, and should be maintained here so
         *  that apps which were originally deployed with older versions of the
         *  plugin can continue to provide access to files stored under those
         *  versions.
         */
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
            tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
                    + packageName + "/cache/";
        } else {
            persistentRoot = "/data/data/" + packageName;
        }
        this.configured = true;
    }

    if (this.configured) {
        // Create the directories if they don't exist.
        File tmpRootFile = new File(tempRoot);
        File persistentRootFile = new File(persistentRoot);
        tmpRootFile.mkdirs();
        persistentRootFile.mkdirs();

        // Register initial filesystems
        // Note: The temporary and persistent filesystems need to be the first two
        // registered, so that they will match window.TEMPORARY and window.PERSISTENT,
        // per spec.
        this.registerFilesystem(
                new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(), tmpRootFile));
        this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(),
                webView.getResourceApi(), persistentRootFile));
        this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi()));
        this.registerFilesystem(
                new AssetFilesystem(webView.getContext().getAssets(), webView.getResourceApi()));

        registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity));

        // Initialize static plugin reference for deprecated getEntry method
        if (filePlugin == null) {
            FileUtils.filePlugin = this;
        }
    } else {
        Log.e(LOG_TAG,
                "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
        activity.finish();
    }
}

From source file:com.csipsimple.ui.dialpad.DialerFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    Intent serviceIntent = new Intent(SipManager.INTENT_SIP_SERVICE);
    // Optional, but here we bundle so just ensure we are using csipsimple package
    serviceIntent.setPackage(activity.getPackageName());
    getActivity().bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE);
    // timings.addSplit("Bind asked for two");
    if (prefsWrapper == null) {
        prefsWrapper = new PreferencesWrapper(getActivity());
    }/*from   w ww.  j ava 2s . c o m*/
    if (dialFeedback == null) {
        dialFeedback = new DialingFeedback(getActivity(), false);
    }

    dialFeedback.resume();

}

From source file:net.kourlas.voipms_sms.Billing.java

public void preDonation(final Activity sourceActivity) {
    try {/* w ww  .j  a v a  2s.c o  m*/
        Bundle ownedItems = billingService.getPurchases(3, applicationContext.getPackageName(), "inapp", null);
        int response = ownedItems.getInt("RESPONSE_CODE");
        if (response == 0) {
            List<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
            for (String purchaseData : purchaseDataList) {
                JSONObject json = new JSONObject(purchaseData);
                String pid = json.getString("productId");
                final String token = json.getString("purchaseToken");

                if (pid.equals(applicationContext.getString(R.string.billing_pid_donation))) {
                    new AsyncTask<Void, Void, Void>() {
                        @Override
                        protected Void doInBackground(Void... params) {
                            try {
                                billingService.consumePurchase(3, sourceActivity.getPackageName(), token);
                            } catch (Exception ignored) {
                                // Do nothing.
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void aVoid) {
                            showDonationDialog(sourceActivity);
                        }
                    }.execute();
                    return;
                }
            }
        }
    } catch (Exception ignored) {
        // Do nothing.
    }

    showDonationDialog(sourceActivity);
}

From source file:org.chromium.chrome.browser.download.OMADownloadHandler.java

/**
 * Shows a dialog to ask whether user wants to open the nextURL.
 *
 * @param omaInfo Information about the OMA content.
 *//*from ww w.  j  a v  a  2  s  .c  o  m*/
private void showNextUrlDialog(OMAInfo omaInfo) {
    if (omaInfo.isValueEmpty(OMA_NEXT_URL)) {
        return;
    }
    final String nextUrl = omaInfo.getValue(OMA_NEXT_URL);
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.next_url_post_oma_download, null);
    TextView textView = (TextView) v.findViewById(R.id.oma_download_next_url);
    textView.setText(nextUrl);
    final Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
    DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == AlertDialog.BUTTON_POSITIVE) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(nextUrl));
                intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
                intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
                intent.setPackage(mContext.getPackageName());
                activity.startActivity(intent);
            }
        }
    };
    new AlertDialog.Builder(activity).setTitle(R.string.open_url_post_oma_download)
            .setPositiveButton(R.string.ok, clickListener).setNegativeButton(R.string.cancel, clickListener)
            .setView(v).setCancelable(false).show();
}

From source file:com.deltadna.android.sdk.ads.core.AdServiceImpl.java

AdServiceImpl(Activity activity, AdServiceListener listener, String sdkVersion) {

    Preconditions.checkArg(activity != null, "activity cannot be null");
    Preconditions.checkArg(listener != null, "listener cannot be null");

    Log.d(BuildConfig.LOG_TAG, "Initialising AdService version " + VERSION);

    String version = "";
    int versionCode = -1;
    try {//from   ww w.  j a  va2  s  .  c o  m
        final PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);

        version = info.versionName;
        versionCode = info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(BuildConfig.LOG_TAG, "Failed to read app versions", e);
    }
    exceptionHandler = new ExceptionHandler(activity.getApplicationContext(), version, versionCode, sdkVersion,
            BuildConfig.VERSION_NAME);
    Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);

    this.activity = activity;
    this.listener = MainThread.redirect(listener, AdServiceListener.class);

    metrics = new AdMetrics(
            activity.getSharedPreferences(Preferences.METRICS.preferencesName(), Context.MODE_PRIVATE));
    broadcasts = LocalBroadcastManager.getInstance(activity.getApplicationContext());
    adAgentListeners = Collections
            .unmodifiableSet(new HashSet<>(Arrays.asList(new AgentListener(), new Broadcaster())));

    // dynamically load the DebugReceiver
    try {
        @SuppressWarnings("unchecked")
        final Class<BroadcastReceiver> cls = (Class<BroadcastReceiver>) Class
                .forName("com.deltadna.android.sdk.ads.debug.DebugReceiver");
        broadcasts.registerReceiver(cls.newInstance(), Actions.FILTER);
        Log.d(BuildConfig.LOG_TAG, "DebugReceiver registered");
    } catch (ClassNotFoundException ignored) {
        Log.d(BuildConfig.LOG_TAG, "DebugReceiver not found in classpath");
    } catch (IllegalAccessException e) {
        Log.w(BuildConfig.LOG_TAG, "Failed to load DebugReceiver", e);
    } catch (InstantiationException e) {
        Log.w(BuildConfig.LOG_TAG, "Failed to load DebugReceiver", e);
    }
}

From source file:com.etalio.android.EtalioBase.java

/**
 * Redirects the end user to Etalio sign in. Sign in will happen through the
 * Etalio app if installed, else through the web browser.
 *
 * <code>mEtalio.initiateEtalioSignIn(this, "profile.basic.r profile.email.r");</code>
 *
 * @param activity the activity used to call Etalio sign in.
 * @param scope    scopes for the sign in. The scopes should be separated by spaces, like "profile.basic.r profile.email.r"
 *///from   w  ww  . ja  va 2  s. c om
public void initiateEtalioSignIn(Activity activity, String scope) {
    resetState();
    if (!isEtalioInstalled(activity)) {
        activity.startActivity(new Intent(Intent.ACTION_VIEW, getSignInUrl(scope)));
    } else {
        Intent etalio = new Intent();
        etalio.setClassName("com.etalio.android", "com.etalio.android.app.ui.activity.SingleSignOnActivity");
        etalio.putExtra(EXTRA_CLIENT_ID, mClientId);
        etalio.putExtra(EXTRA_PACKAGE_NAME, activity.getPackageName());
        etalio.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        activity.startActivityForResult(etalio, REQUEST_CODE_SSO);
    }
}

From source file:com.suarez.cordova.mapsforge.MapsforgePlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("global-status".equals(action)) {
        this.status();
        callbackContext.success();/*from   www  .  ja v a  2s  .  c o  m*/
        return true;
    } else if (action.contains("native-")) {
        if ("native-set-center".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setCenter(args.getDouble(0), args.getDouble(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-zoom".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.show();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
            return true;
        } else if ("native-hide".equals(action)) {
            MapsforgeNative.INSTANCE.hide();
            return true;
        } else if ("native-marker".equals(action)) {
            try {
                Activity context = this.cordova.getActivity();

                int markerId = context.getResources().getIdentifier(args.getString(0), "drawable",
                        context.getPackageName());
                if (markerId == 0) {
                    Log.i(MapsforgePlugin.TAG, "Marker not found...using default marker: marker_green");
                    markerId = context.getResources().getIdentifier("marker_green", "drawable",
                            context.getPackageName());
                }

                int markerKey = MapsforgeNative.INSTANCE.addMarker(markerId, args.getDouble(1),
                        args.getDouble(2));
                callbackContext.success(markerKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-polyline".equals(action)) {

            try {
                JSONArray points = args.getJSONArray(2);

                if (points.length() % 2 != 0)
                    throw new JSONException("Invalid array of coordinates. Length should be multiple of 2");

                int polylineKey = MapsforgeNative.INSTANCE.addPolyline(args.getInt(0), args.getInt(1), points);

                callbackContext.success(polylineKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-delete-layer".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.deleteLayer(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-initialize".equals(action)) {

            try {

                MapsforgeNative.createInstance(this.cordova.getActivity(), args.getString(0), args.getInt(1),
                        args.getInt(2));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-max-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMaxZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-min-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMinZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-controls".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setBuiltInZoomControls(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-clickable".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setClickable(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-scale".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.showScaleBar(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy-cache".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.destroyCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            }

            return true;
        } else if ("native-map-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMapFilePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException iae) {
                callbackContext.error(iae.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-cache-name".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-theme-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setRenderThemePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-stop".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStop();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-start".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStart();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-online".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOnline(args.getString(0), args.getString(1), args.getString(2),
                        args.getString(3), args.getInt(4));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-offline".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOffline(args.getString(0), args.getString(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    } else if (action.contains("cache-")) {
        if ("cache-get-tile".equals(action)) {

            try {
                final long x = args.getLong(0);
                final long y = args.getLong(1);
                final byte z = Byte.parseByte(args.getString(2));
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {
                    public void run() {
                        try {
                            String path = MapsforgeCache.INSTANCE.getTilePath(x, y, z);
                            callbacks.success(path);
                        } catch (IOException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-initialize".equals(action)) {

            try {
                MapsforgeCache.createInstance(cordova.getActivity(), args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-map-path".equals(action)) {

            try {
                final String mapFile = args.getString(0);
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setMapFilePath(mapFile);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-age".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheAge(args.getLong(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-cleaning-trigger".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanCacheTrigger(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-enabled".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheEnabled(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-external".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setExternalCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-name".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-tile-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setTileSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-clean-destroy".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanOnDestroy(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-theme-path".equals(action)) {

            try {
                final CallbackContext callbacks = callbackContext;
                final String themePath = args.getString(0);

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setRenderTheme(themePath);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-screen-ratio".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setScreenRatio(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-overdraw".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setOverdrawFactor(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-destroy".equals(action)) {
            try {
                MapsforgeCache.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    }
    return false; // Returning false results in a "MethodNotFound" error.
}