List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:Main.java
public static void ring(Context context) { if ((System.currentTimeMillis() - beepTime) > 6 * 1000) { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), notification); r.play();//ww w . ja va2 s . c o m beepTime = System.currentTimeMillis(); } else { beepTime = 0; } }
From source file:com.sublimis.urgentcallfilter.MyPreference.java
public synchronized static void setContext(Context context) { if (mContext == null) mContext = context.getApplicationContext(); }
From source file:com.liferay.alerts.database.DatabaseHelper.java
public static DatabaseHelper getInstance(Context context) { if (_instance == null) { _instance = new DatabaseHelper(context.getApplicationContext()); }// w w w . j a va 2 s . c o m return _instance; }
From source file:Main.java
public static void showSingleToast(Context ctx, String msg, int duration) { int showDuration = duration <= Toast.LENGTH_SHORT ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT; if (null == toast) { toast = Toast.makeText(ctx.getApplicationContext(), msg, showDuration); toast.show();//from w ww. ja v a 2 s . com oneTime = System.currentTimeMillis(); } else { twoTime = System.currentTimeMillis(); if (msg.equals(oldMsg)) { if (twoTime - oneTime > showDuration) { toast.show(); } } else { oldMsg = msg; toast.setText(msg); toast.show(); } } oneTime = twoTime; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static boolean isAllowed(Context context, int op) { Log.d(TAG, "api level: " + Build.VERSION.SDK_INT); if (Build.VERSION.SDK_INT < 19) { return true; }/*from w w w. j a v a 2s . co m*/ Log.d(TAG, "op is " + op); String packageName = context.getApplicationContext().getPackageName(); AppOpsManager aom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); Class<?>[] types = new Class[] { int.class, int.class, String.class }; Object[] args = new Object[] { op, Binder.getCallingUid(), packageName }; try { Method method = aom.getClass().getDeclaredMethod("checkOpNoThrow", types); Object mode = method.invoke(aom, args); Log.d(TAG, "invoke checkOpNoThrow: " + mode); if ((mode instanceof Integer) && ((Integer) mode == AppOpsManager.MODE_ALLOWED)) { Log.d(TAG, "allowed"); return true; } } catch (Exception e) { Log.e(TAG, "invoke error: " + e); e.printStackTrace(); } return false; }
From source file:Main.java
/** * Turns a string into an array of drawable resource IDs. * 'string' must contain string equivalent of valid drawable names without file endings * separated by commas.// w w w .j a v a 2 s . c o m * @param string * @param context * @return an array of drawable resource IDs */ public static int[] stringToDrawableResIDArray(String string, Context context) { String[] strArray = string.split(","); int[] intArray = new int[strArray.length]; Resources resources; int resId; int i = 0; for (String str : strArray) { resources = context.getApplicationContext().getResources(); intArray[i] = resources.getIdentifier(strArray[i], "drawable", "com.domnibus.sfarinas.youtubetest"); i++; } return intArray; }
From source file:com.devsh.androidlogin.library.FacebookLoginUtil.java
public static void initialize(Context context) { sContext = context.getApplicationContext(); FacebookSdk.sdkInitialize(sContext); }
From source file:Main.java
public static ArrayList<String> getAllAccessibilityServices(Context context) { TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':'); ArrayList<String> allAccessibilityServices = new ArrayList<String>(); String settingValue = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); if (settingValue != null) { colonSplitter.setString(settingValue); while (colonSplitter.hasNext()) { String accessabilityService = colonSplitter.next(); allAccessibilityServices.add(accessabilityService); }//from www. j a v a 2 s.c o m } return allAccessibilityServices; }
From source file:at.wada811.utils.PreferenceUtils.java
/** * {@link PreferenceManager#getDefaultSharedPreferences(Context)} should pass application * context.//from w w w. ja v a2 s.c o m * * @param context * @return */ public static SharedPreferences getDefaultSharedPreferences(Context context) { return PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); }
From source file:Main.java
public static void showLongToast(final Context mContext, final int resId) { sharedHandler(mContext).post(() -> { if (toast != null) { toast.setText(resId);// w ww. j a v a 2 s.c om toast.setDuration(Toast.LENGTH_LONG); } else { toast = Toast.makeText(mContext.getApplicationContext(), resId, Toast.LENGTH_LONG); } toast.show(); }); }