List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:ca.psiphon.tunneledwebview.WebViewProxySettings.java
public static boolean setProxy(Context ctx, String host, int port) { boolean worked = false; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { worked = setWebkitProxyGingerbread(ctx, host, port); } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { worked = setWebkitProxyICS(ctx, host, port); } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { worked = setWebkitProxyKitKat(ctx.getApplicationContext(), host, port); } else {// www . j a v a 2 s. com worked = setWebkitProxyLollipop(ctx.getApplicationContext(), host, port); } return worked; }
From source file:biz.bokhorst.xprivacy.Util.java
public static boolean isDebuggable(Context context) { return ((context.getApplicationContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); }
From source file:org.wso2.emm.agent.utils.CommonUtils.java
/** * Get installed package list of applications in device * @param context Context object//from ww w . j av a2 s.com * @return list of installed app packages */ public static List<String> getInstalledAppPackages(Context context) { ApplicationManager applicationManager = new ApplicationManager(context.getApplicationContext()); List<ApplicationInfo> installedApplications = applicationManager.getInstalledApplications(); List<String> installedAppPackages = new ArrayList<>(); for (ApplicationInfo appInfo : installedApplications) { installedAppPackages.add(appInfo.packageName); } return installedAppPackages; }
From source file:com.aegiswallet.utils.WalletUtils.java
public static BigDecimal getExchangeRate(Context context, SharedPreferences prefs) { File file = context.getApplicationContext().getFileStreamPath(Constants.BLOCKCHAIN_CURRENCY_FILE_NAME); if (file.exists()) { JSONObject jsonObject = BasicUtils.parseJSONData(context, Constants.BLOCKCHAIN_CURRENCY_FILE_NAME); try {/*from w ww . j a va2s . c o m*/ if (jsonObject != null) { JSONObject newObject = jsonObject .getJSONObject(prefs.getString(Constants.CURRENCY_PREF_KEY, null)); double doubleValue = newObject.getDouble("last"); BigDecimal bigDecimal = BigDecimal.valueOf(doubleValue); return bigDecimal; } } catch (JSONException e) { Log.e("Wallet Utils", "JSON Exception " + e.getMessage()); } } return null; }
From source file:com.aegiswallet.utils.WalletUtils.java
public static String getExchangeRateWithSymbol(Context context, SharedPreferences prefs) { File file = context.getApplicationContext().getFileStreamPath(Constants.BLOCKCHAIN_CURRENCY_FILE_NAME); if (file.exists()) { JSONObject jsonObject = BasicUtils.parseJSONData(context, Constants.BLOCKCHAIN_CURRENCY_FILE_NAME); try {/*from w ww . j ava 2 s .c om*/ if (jsonObject != null) { JSONObject newObject = jsonObject .getJSONObject(prefs.getString(Constants.CURRENCY_PREF_KEY, null)); double doubleValue = newObject.getDouble("last"); BigDecimal bigDecimal = BigDecimal.valueOf(doubleValue); return newObject.getString("symbol") + bigDecimal.toString(); } } catch (JSONException e) { Log.e("Wallet Utils", "JSON Exception " + e.getMessage()); } } return null; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
private static void showError(Context ctx) { Toast.makeText(ctx.getApplicationContext(), ctx.getApplicationContext().getText(R.string.auth_fail), Toast.LENGTH_SHORT).show();/*from ww w .j a v a 2 s . c o m*/ }
From source file:com.wbtech.common.CommonUtil.java
/** * wifi??/* w w w .ja v a2s. c o m*/ * @param inContext * @return */ public static boolean isWiFiActive(Context inContext) { if (checkPermissions(inContext, "android.permission.ACCESS_WIFI_STATE")) { Context context = inContext.getApplicationContext(); ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) { return true; } } } } return false; } else { if (UmsConstants.DebugMode) { Log.e("lost permission", "lost--->android.permission.ACCESS_WIFI_STATE"); } return false; } }
From source file:com.foxykeep.datadroid.internal.network.NetworkConnectionImplF.java
private static String convertStreamToString(InputStream is, boolean isGzipEnabled, File file, Context con) throws IOException { InputStream cleanedIs = is;/*from w w w .ja v a2 s. c o m*/ if (isGzipEnabled) { cleanedIs = new GZIPInputStream(is); } FileOutputStream fos = null; final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(con.getApplicationContext()); final SimpleWrapper downloaded = new SimpleWrapper(); final Editor ed = sp.edit(); final String path = "DL" + file.getParentFile().getName(); class MyThread extends Thread { volatile boolean finished = false; public void stopMe() { finished = true; } @Override public void run() { while (!finished) { ed.putLong(path, downloaded.dl); ed.commit(); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } ; final MyThread thread = new MyThread(); try { fos = new FileOutputStream(file); byte[] buffer = new byte[8192]; int len1 = 0; thread.start(); while ((len1 = cleanedIs.read(buffer)) != -1) { fos.write(buffer, 0, len1); downloaded.dl += len1; } ed.putLong(path, downloaded.dl); ed.commit(); fos.flush(); } catch (IOException e) { throw e; } finally { thread.stopMe(); if (fos != null) { fos.close(); } cleanedIs.close(); if (isGzipEnabled) { is.close(); } } return ""; }
From source file:de.madvertise.android.sdk.MadvertiseUtil.java
public static String getHashedAndroidID(Context context, HashType hashType) { String id = Secure.getString(context.getApplicationContext().getContentResolver(), Secure.ANDROID_ID); if (id == null) { id = "";/*from w w w .j av a 2 s . co m*/ } else { id = MadvertiseUtil.getHash(id, hashType); } return id; }
From source file:at.florian_lentsch.expirysync.net.ServerProxy.java
/** * Creates an instance retrieving the host name from the shared preferences * @param context the context containing the shared preferences * @return the requested instance/*ww w . j av a2 s.c o m*/ */ public static ServerProxy getInstanceFromConfig(Context context) { SharedPreferences sharedPref = context.getApplicationContext().getSharedPreferences("main", Context.MODE_PRIVATE); String hostStr = sharedPref.getString(SettingsActivity.KEY_HOST, ""); ServerProxy articleProxy = ServerProxy.getInstance(hostStr); if (!articleProxy.caller.getHost().equals(hostStr)) { try { articleProxy.caller.setHost(hostStr); } catch (URISyntaxException e) { Log.d("ERR", "Could not set host from config - keeping the old one"); } } return articleProxy; }