Context getApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context getApplicationContext method.

This code example shows how to use the following methods:getApplicationContext, getResources, getSharedPreferences
 
    private LocalBluetoothPreferences() { 
    } 
 
    private static SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    } 
 
    static long getDiscoverableEndTimestamp(Context context) {
        return getSharedPreferences(context).getLong(
                KEY_DISCOVERABLE_END_TIMESTAMP, 0);
    } 
 
    static boolean shouldShowDialogInForeground(Context context,
            String deviceAddress) {
        LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context);
        if (manager == null) {
            return false; 
        } 
 

8
CodeRank
This code example shows how to use the following methods:getApplicationContext, getSharedPreferences
        this.cacheKey = Utility.isNullOrEmpty(cacheKey) ? DEFAULT_CACHE_KEY : cacheKey;
 
        // If the application context is available, use that. However, if it isn't 
        // available (possibly because of a context that was created manually), use 
        // the passed in context directly. 
        Context applicationContext = context.getApplicationContext();
        context = applicationContext != null ? applicationContext : context;
 
        this.cache = context.getSharedPreferences(
                this.cacheKey,
                Context.MODE_PRIVATE);
    } 
 
    /** 
     * Returns a Bundle that contains the information stored in this cache 
     * 
     * @return A Bundle with the information contained in this cache 
     */ 
    public Bundle load() {
        Bundle settings = new Bundle();
7
CodeRank
This code example shows how to use the following methods:getApplicationContext, getSystemService
 
    @IgnitedLocation 
    protected Location currentLocation;
 
    public IgnitedAbstractLastLocationFinder(Context context) {
        this.context = context.getApplicationContext();
        locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        criteria = new Criteria();
        // Coarse accuracy is specified here to get the fastest possible result. 
        // The calling Activity will likely (or have already) request ongoing 
        // updates using the Fine location provider. 
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    public Location getLastBestLocation(int minDistance, long minTime,
            boolean refreshLocationIfLastIsTooOld) {
7
CodeRank
This code example shows how to use the following methods:getApplicationContext
public class SocialItemViewBinder implements ViewBinder { 
 
	private ImageLoader imageLoader;
 
	public SocialItemViewBinder(final Context context) {
		this.imageLoader = ((NewsBlurApplication) context.getApplicationContext()).getImageLoader();
	} 
	 
	@Override 
	public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
		final String columnName = cursor.getColumnName(columnIndex);
		final int hasBeenRead = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_READ));
		if (TextUtils.equals(cursor.getColumnName(columnIndex), DatabaseConstants.FEED_FAVICON_URL)) {
			String faviconUrl = cursor.getString(columnIndex);
			imageLoader.displayImage(faviconUrl, ((ImageView) view), false);
			return true; 
		} else if (TextUtils.equals(columnName, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS)) {
			int authors = cursor.getInt(columnIndex);
			int tags = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TAGS));
			int feed = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_FEED));
7
CodeRank
This code example shows how to use the following methods:getApplicationContext
	public static Kirin create(Context context) {
		return new Kirin(context, null, null, null);
	} 
 
	public Kirin(Context androidContext, INativeContext nativeContext, IJsContext jsContext, IKirinState state) {
		mContext = androidContext.getApplicationContext();
		if (nativeContext == null) {
			nativeContext = new NativeContext();
		} 
		mNativeContext = nativeContext;
		 
		if (jsContext == null) {
			jsContext = new KirinWebViewHolder(mContext, mNativeContext);
		} 
		mJsContext = jsContext;
		 
		if (state == null) {
			state = new KirinAppState(mContext);
		} 
		mKirinState = state;

8
CodeRank
This code example shows how to use the following methods:getApplicationContext, getDefaultSharedPreferences
 
	private SharedPreferences appSettings;
 
	private boolean shouldStartService(Context context) {
		this.appSettings = PreferenceManager
				.getDefaultSharedPreferences(context.getApplicationContext());
		return this.appSettings.getBoolean("doAutoSync", false);
	} 
 
	@Override 
	public void onReceive(Context context, Intent intent) {
		if (this.shouldStartService(context)) {
			SyncService.startAlarm(context);
		} 
		 
		Intent calIntent = new Intent(context, CalendarSyncService.class);
		calIntent.putExtra(CalendarSyncService.FILELIST, new String[] {});
		context.startService(calIntent);
	} 
} 
7
CodeRank
This code example shows how to use the following methods:getApplicationContext, getSystemService
          return false; 
        } 
      }; 
 
  public IncomingRinger(Context context) {
    this.context = context.getApplicationContext();
    vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
    player = createPlayer();
  } 
 
  private MediaPlayer createPlayer() {
    MediaPlayer newPlayer = new MediaPlayer();
    try { 
      Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
      newPlayer.setOnErrorListener(playerErrorListener);
      newPlayer.setDataSource(context, ringtoneUri);
      newPlayer.setLooping(true);
      newPlayer.setAudioStreamType(AudioManager.STREAM_RING);
      return newPlayer;
    } catch (IOException e) {
7
CodeRank
This code example shows how to use the following methods:getApplicationContext
package proton.inject.receiver; 
 
import proton.inject.Proton; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
 
public class ProtonBroadcastReceiver extends BroadcastReceiver {
	@Override 
	public void onReceive(Context context, Intent intent) {
		Proton.getInjector(context.getApplicationContext()).inject(this);
	} 
} 

7
CodeRank
This code example shows how to use the following methods:getApplicationContext
		this(ctx, getUserAgent(null), false);
	} 
 
	public RESTClient(Context ctx, String userAgent,
			boolean forceApacheHttpClient) {
		this.ctx = ctx.getApplicationContext();
		this.forceApacheHttpClient = forceApacheHttpClient;
		httpClientWorker = useHttpURLConnection() ? null
				: new HttpClientWorker(userAgent);
		httpURLConnectionWorker = useHttpURLConnection() ? new HttpURLConnectionWorker(
				userAgent) : null;
		if (cookieJar == null) {
			cookieJar = new CookieJar(ctx);
		} 
		if (Build.VERSION.SDK_INT >= 14) {
			HttpURLConnectionWorker.setHttpResponseCacheEnabled(ctx, true);
		} 
	} 
 
	public Context getContext() {
		return ctx;
7
CodeRank
This code example shows how to use the following methods:getApplicationContext, getSystemService
     *            is a no-op) 
     */ 
    static void handleApplicationClosing(final Context context, int keyCode) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            ActivityManager am = (ActivityManager) context
                    .getSystemService(Context.ACTIVITY_SERVICE);
            List<RunningTaskInfo> tasks = am.getRunningTasks(2);
 
            RunningTaskInfo currentTask = tasks.get(0);
            RunningTaskInfo nextTask = tasks.get(1);
 
            // if we're looking at this application's base/launcher Activity, 
            // and the next task is the Android home screen, then we know we're 
            // about to close the app 
            if (currentTask.topActivity.equals(currentTask.baseActivity)
                    && nextTask.baseActivity.getPackageName().startsWith("com.android.launcher")) {
                DroidFuApplication application = (DroidFuApplication) context
                        .getApplicationContext();
                application.onClose();
            } 

7
CodeRank

Related Context getApplicationContext Questions & Answers:

Other Context getApplicationContext Examples

22:	
23:	    // Build the intent to call the service
24:	    Intent intent = new Intent(context.getApplicationContext(),
25:	        UpdateWidgetService.class);
26:	    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);

Read More

getApplicationContext Method Overview
Return the context of the single, global Application object of the current process.
See Code Examples for other Android Context Methods: