android.content.Context#getApplicationContext ( )源码实例Demo

下面列出了android.content.Context#getApplicationContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: box-android-sdk   文件: BoxSession.java
/**
 * Create a BoxSession using a specific box clientId, secret, and redirectUrl. This constructor is not necessary unless
 * an application uses multiple api keys.
 * Note: When setting the userId to null ui will be shown to ask which user to authenticate as if at least one user is logged in. If no
 * user has been stored will show login ui.
 *
 * @param context      current context.
 * @param clientId     the developer's client id to access the box api.
 * @param clientSecret the developer's secret used to interpret the response coming from Box.
 * @param redirectUrl  the developer's redirect url to use for authenticating via Box.
 * @param userId       user id to login as or null to login as a new user.
 */
public BoxSession(Context context, String userId, String clientId, String clientSecret, String redirectUrl) {
    mClientId = clientId;
    mClientSecret = clientSecret;
    mClientRedirectUrl = redirectUrl;
    if (getRefreshProvider() == null && (SdkUtils.isEmptyString(mClientId) || SdkUtils.isEmptyString(mClientSecret))) {
        throw new RuntimeException("Session must have a valid client id and client secret specified.");
    }
    mApplicationContext = context.getApplicationContext();
    if (!SdkUtils.isEmptyString(userId)) {
        mAuthInfo = BoxAuthentication.getInstance().getAuthInfo(userId, context);
        mUserId = userId;
    }
    if (mAuthInfo == null) {
        mUserId = userId;
        mAuthInfo = new BoxAuthentication.BoxAuthenticationInfo();
    }
    mAuthInfo.setClientId(mClientId);
    setupSession();
}
 
/**
 * Install location collection client
 *
 * @param context         non-null reference to context object.
 * @param defaultInterval default session rotation interval.
 * @return instance of location collector client
 */
public static LocationCollectionClient install(@NonNull Context context, long defaultInterval) {
  Context applicationContext;
  if (context.getApplicationContext() == null) {
    // In shared processes content providers getApplicationContext() can return null.
    applicationContext = context;
  } else {
    applicationContext = context.getApplicationContext();
  }

  synchronized (lock) {
    if (locationCollectionClient == null) {
      locationCollectionClient = new LocationCollectionClient(new LocationEngineControllerImpl(applicationContext,
        LocationEngineProvider.getBestLocationEngine(applicationContext), new LocationUpdatesBroadcastReceiver()),
        new HandlerThread("LocationSettingsChangeThread"),
        new SessionIdentifier(defaultInterval),
        applicationContext.getSharedPreferences(MAPBOX_SHARED_PREFERENCES, Context.MODE_PRIVATE),
        // Provide empty token as it is not available yet
        new MapboxTelemetry(applicationContext, "",
          String.format("%s/%s", LOCATION_COLLECTOR_USER_AGENT, BuildConfig.VERSION_NAME)));
    }
  }
  return locationCollectionClient;
}
 
源代码3 项目: Abelana-Android   文件: Settings.java
static void publishInstallAsync(final Context context, final String applicationId,
    final Request.Callback callback) {
    // grab the application context ahead of time, since we will return to the caller immediately.
    final Context applicationContext = context.getApplicationContext();
    Settings.getExecutor().execute(new Runnable() {
        @Override
        public void run() {
            final Response response = Settings.publishInstallAndWaitForResponse(applicationContext, applicationId, false);
            if (callback != null) {
                // invoke the callback on the main thread.
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        callback.onCompleted(response);
                    }
                });
            }
        }
    });
}
 
源代码4 项目: LeisureRead   文件: StatusBarUtil.java
/**
 * Default status dp = 24 or 25
 * mhdpi = dp * 1
 * hdpi = dp * 1.5
 * xhdpi = dp * 2
 * xxhdpi = dp * 3
 * eg : 1920x1080, xxhdpi, => status/all = 25/640(dp) = 75/1080(px)
 * <p/>
 * don't forget toolbar's dp = 48
 *
 * @return px
 */
@IntRange(from = 0, to = 75)
public static int getStatusBarOffsetPx(Context context) {

  if (isLessKitkat()) {
    return 0;
  }
  Context appContext = context.getApplicationContext();
  int result = 0;
  int resourceId =
      appContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
  if (resourceId > 0) {
    result = appContext.getResources().getDimensionPixelSize(resourceId);
  }
  return result;
}
 
private AdvertisementManager(@NonNull Context context) {
    mContext = context.getApplicationContext();
    mPreferences = mContext.getSharedPreferences("ad", Context.MODE_PRIVATE);

    mLocalAdVersion = mPreferences.getInt("version", 0);

    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    mGson = new Gson();
}
 
源代码6 项目: deltachat-android   文件: AccountManager.java
private void resetDcContext(Context context) {
    // create an empty DcContext object - this will be set up then, starting with
    // getSelectedAccount()
    ApplicationContext appContext = (ApplicationContext)context.getApplicationContext();
    appContext.dcContext.notificationCenter.removeAllNotifiations();
    appContext.dcContext.stopIo();
    appContext.dcContext.unref();
    appContext.dcContext = new ApplicationDcContext(context);
}
 
源代码7 项目: sctalk   文件: SpeekerToast.java
public static void show(Context context, CharSequence text, int duration) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    View view = inflater.inflate(R.layout.tt_speeker_layout, null);
    TextView title = (TextView) view.findViewById(R.id.top_tip);
    title.setText(text);
    Toast toast = new Toast(context.getApplicationContext());
    toast.setGravity(
            Gravity.FILL_HORIZONTAL | Gravity.TOP,
            0,
            (int) context.getResources().getDimension(
                    R.dimen.top_bar_default_height));
    toast.setDuration(duration);
    toast.setView(view);
    toast.show();
}
 
源代码8 项目: Music-Player   文件: MusicPlaybackQueueStore.java
/**
 * @param context The {@link Context} to use
 * @return A new instance of this class.
 */
@NonNull
public static synchronized MusicPlaybackQueueStore getInstance(@NonNull final Context context) {
    if (sInstance == null) {
        sInstance = new MusicPlaybackQueueStore(context.getApplicationContext());
    }
    return sInstance;
}
 
源代码9 项目: bcm-android   文件: DatabaseFactory.java
public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
    super(context, name, factory, version);
    this.context = context.getApplicationContext();
}
 
public static PixelActivityUnion with(Context context) {
	mPixelActivityUnion.mContext = context.getApplicationContext();
	return mPixelActivityUnion;
}
 
源代码11 项目: IdealMedia   文件: SmallWidgetProvider.java
@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    mContext = context;
    final App app = (App)context.getApplicationContext();
    final PlayerService service = app.getService();

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.notification);

            ComponentName componentName = new ComponentName(mContext, PlayerService.class);

            for (int currentAppWidgetId : appWidgetIds) {
                Intent intentNext = new Intent(PlayerService.NEXT);
                intentNext.setComponent(componentName);
                views.setOnClickPendingIntent(R.id.action_next, PendingIntent.getService(mContext, 0, intentNext, 0));

                Intent intentPrev = new Intent(PlayerService.PREV);
                intentPrev.setComponent(componentName);
                views.setOnClickPendingIntent(R.id.action_prev, PendingIntent.getService(mContext, 0, intentPrev, 0));

                Intent intentPlay = new Intent(PlayerService.PLAY);
                intentPlay.setComponent(componentName);
                views.setOnClickPendingIntent(R.id.action_play, PendingIntent.getService(mContext, 0, intentPlay, 0));

                Intent intentOpen = new Intent(context, NavigationActivity.class);
                PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intentOpen, 0);
                views.setOnClickPendingIntent(R.id.notifAlbum, pendingIntent);
                views.setOnClickPendingIntent(R.id.notifTitle, pendingIntent);
                views.setOnClickPendingIntent(R.id.notifArtist, pendingIntent);

                if (service != null) {
                    Track track = service.currentTrack;

                    views.setImageViewResource(R.id.action_play, service.isPlaying() ? R.drawable.ic_pause_normal : R.drawable.ic_play_normal);

                    if (track != null) {
                        views.setTextViewText(R.id.notifTitle, track.getTitle());
                        views.setTextViewText(R.id.notifArtist, track.getArtist());

                        Bitmap cover =  MediaUtils.getArtworkQuick(context, track, 180, 180);
                        if (cover != null)
                            views.setImageViewBitmap(R.id.notifAlbum, cover);
                        else
                            views.setImageViewResource(R.id.notifAlbum,  R.drawable.ic_launcher);
                    }
                } else {
                    views.setTextViewText(R.id.notifTitle, "-");
                    views.setTextViewText(R.id.notifArtist, "");
                    views.setImageViewResource(R.id.notifAlbum,  R.drawable.ic_launcher);
                    views.setImageViewResource(R.id.action_play, R.drawable.ic_play_normal);
                }

                try {
                    appWidgetManager.updateAppWidget(currentAppWidgetId, views);
                } catch (Exception ignored) { }
            }

            return null;
        }
    }.execute();
}
 
源代码12 项目: letv   文件: AdvertisingInfoProvider.java
public AdvertisingInfoProvider(Context context) {
    this.context = context.getApplicationContext();
    this.preferenceStore = new PreferenceStoreImpl(context, ADVERTISING_INFO_PREFERENCES);
}
 
源代码13 项目: opentasks   文件: SettingsSignal.java
public SettingsSignal(Context context)
{
    mContext = context.getApplicationContext();
}
 
源代码14 项目: TigerVideo   文件: VideoExoPlayer.java
public VideoExoPlayer(Context context) {

        mContext = context.getApplicationContext();
        initExoPlayer();
    }
 
源代码15 项目: BaseUIFrame   文件: DefaultCrashProcess.java
public DefaultCrashProcess(Context context) {
    mContext = context.getApplicationContext();
}
 
源代码16 项目: memetastic   文件: AssetUpdater.java
public LoadAssetsThread(Context context) {
    _context = context.getApplicationContext();
    _appSettings = AppSettings.get();
    _tagKeys = context.getResources().getStringArray(R.array.meme_tags__keys);
}
 
源代码17 项目: android-chromium   文件: NetworkChangeNotifier.java
private NetworkChangeNotifier(Context context) {
    mContext = context.getApplicationContext();
    mNativeChangeNotifiers = new ArrayList<Integer>();
    mConnectionTypeObservers = new ObserverList<ConnectionTypeObserver>();
}
 
源代码18 项目: ClassSchedule   文件: Preferences.java
public static void init(Context context) {
    Preferences.context = context.getApplicationContext();
    configFileName = context.getPackageName();
}
 
源代码19 项目: yubikit-android   文件: YubiKitManager.java
/**
 * Initialize instance of {@link YubiKitManager}
 * @param context application context
 * @param handler on which callbacks will be invoked (default is main thread)
 */
public YubiKitManager(Context context, @Nullable Handler handler) {
    this(handler != null ? handler : new Handler(Looper.getMainLooper()),
            new UsbDeviceManager(context.getApplicationContext()),
            new NfcDeviceManager(context.getApplicationContext()));
}
 
源代码20 项目: Paper   文件: Paper.java
/**
 * Lightweight method to init Paper instance. Should be executed in {@link Application#onCreate()}
 * or {@link android.app.Activity#onCreate(Bundle)}.
 * <p/>
 *
 * @param context context, used to get application context
 */
public static void init(Context context) {
    mContext = context.getApplicationContext();
}
 
 方法所在类
 同类方法