List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:ir.aarani.bazaar.billing.BillingProcessor.java
public BillingProcessor(Context context, String licenseKey, String merchantId, IBillingHandler handler) { super(context); signatureBase64 = licenseKey;//from w w w . j ava2 s .com eventHandler = handler; contextPackageName = context.getApplicationContext().getPackageName(); cachedProducts = new BillingCache(context, MANAGED_PRODUCTS_CACHE_KEY); cachedSubscriptions = new BillingCache(context, SUBSCRIPTIONS_CACHE_KEY); developerMerchantId = merchantId; bindPlayServices(); }
From source file:com.owncloud.android.operations.RemoteOperation.java
/** * Asynchronously executes the remote operation * //from w w w.j a va 2s . c o m * This method should be used whenever an ownCloud account is available, instead of {@link #execute(WebdavClient)}. * * @param account ownCloud account in remote ownCloud server to reach during the execution of the operation. * @param context Android context for the component calling the method. * @param listener Listener to be notified about the execution of the operation. * @param listenerHandler Handler associated to the thread where the methods of the listener objects must be called. * @return Thread were the remote operation is executed. */ public final Thread execute(Account account, Context context, OnRemoteOperationListener listener, Handler listenerHandler, Activity callerActivity) { if (account == null) throw new IllegalArgumentException("Trying to execute a remote operation with a NULL Account"); if (context == null) throw new IllegalArgumentException("Trying to execute a remote operation with a NULL Context"); mAccount = account; mContext = context.getApplicationContext(); mCallerActivity = callerActivity; mClient = null; // the client instance will be created from mAccount and mContext in the runnerThread to create below if (listener == null) { throw new IllegalArgumentException( "Trying to execute a remote operation asynchronously without a listener to notiy the result"); } mListener = listener; if (listenerHandler == null) { throw new IllegalArgumentException( "Trying to execute a remote operation asynchronously without a handler to the listener's thread"); } mListenerHandler = listenerHandler; Thread runnerThread = new Thread(this); runnerThread.start(); return runnerThread; }
From source file:com.odoo.core.service.OSyncAdapter.java
private void init(Context context, Class<? extends OModel> model, OSyncService service) { mContext = context;//from ww w. j a v a 2s . c om mModelClass = model; mService = service; preferenceManager = new OPreferenceManager(mContext); app = (App) context.getApplicationContext(); }
From source file:com.appglu.android.AppGlu.java
private void doInitialize(Context context, AppGluSettings settings) { AppGluUtils.assertNotNull(context, "Context cannot be null"); AppGluUtils.assertNotNull(settings, "AppGluSettings cannot be null"); this.context = context.getApplicationContext(); this.settings = settings; this.deviceInstallation = new DeviceInstallation(this.context); this.appGluTemplate = settings.createAppGluTemplate(this.context); this.appGluTemplate.setAsyncExecutor(new AsyncTaskExecutor()); this.appGluTemplate.setDefaultHeaders(this.deviceInstallation.createDefaultHeaders(settings)); UserSessionPersistence userSessionPersistence = this.settings.getUserSessionPersistence(); if (userSessionPersistence == null) { userSessionPersistence = new SharedPreferencesUserSessionPersistence(this.context); }/* w ww .j a va 2 s.c o m*/ this.appGluTemplate.setUserSessionPersistence(userSessionPersistence); logger.info("AppGlu was initialized"); }
From source file:com.orange.ocara.model.ModelManagerImpl.java
/** * Constructor.//from ww w . j av a 2 s .co m * * @param context */ @Inject public ModelManagerImpl(Context context) { this.context = context.getApplicationContext(); }
From source file:org.openbmap.soapclient.ExportSessionTask.java
/** * * @param context//from www . java 2s . co m * @param listener * @param session * @param tempPath * @param user * @param password */ public ExportSessionTask(final Context context, final UploadTaskListener listener, final int session, final String tempPath, final String user, final String password, final boolean anonymous_upload) { mAppContext = context.getApplicationContext(); mSession = session; mTempPath = tempPath; mUser = user; mPassword = password; mListener = listener; mAnonymousUpload = anonymous_upload; mUploadedFiles = new ArrayList<>(); }
From source file:au.com.wallaceit.reddinator.Rservice.java
public ListRemoteViewsFactory(Context context, Intent intent) { this.mContext = context; appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); global = ((GlobalObjects) context.getApplicationContext()); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); //System.out.println("New view factory created for widget ID:"+appWidgetId); // Set thread network policy to prevent network on main thread exceptions. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);// w w w.ja v a 2s. c om // if this is a user request (apart from 'loadmore') or an auto update, do not attempt to load cache. // when a user clicks load more and a new view factory needs to be created we don't want to bypass cache, we want to load the cached items int loadType = global.getLoadType(); if (!global.getBypassCache() || loadType == GlobalObjects.LOADTYPE_LOADMORE) { // load cached data data = global.getFeed(mSharedPreferences, appWidgetId); if (data.length() != 0) { titleFontSize = mSharedPreferences.getString(context.getString(R.string.widget_theme_pref), "16"); try { lastItemId = data.getJSONObject(data.length() - 1).getJSONObject("data").getString("name"); } catch (JSONException e) { lastItemId = "0"; // Could not get last item ID; perform a reload next time and show error view :( e.printStackTrace(); } if (loadType == GlobalObjects.LOADTYPE_LOAD) { loadCached = true; // this isn't a loadmore request, the cache is loaded and we're done //System.out.println("Cache loaded, no user request received."); } } else { loadReddits(false); // No feed items; do a reload. } } else { data = new JSONArray(); // set empty data to prevent any NPE } }
From source file:com.ademsha.appnotifico.NotificationHubCommandReceiver.java
private void getActiveNotifications(Context context, Intent intent) { String[] keys = intent.getStringArrayExtra("data"); if (keys.length > 0) { JSONArray notifications = new JSONArray(); for (StatusBarNotification statusBarNotification : notificationHub.getActiveNotifications(keys)) { notifications.put(NotificationDataHelper.getStatusBarNotificationDataAsJSON(statusBarNotification)); }//from w w w . j a va 2 s . c o m Intent dataIntent = new Intent(NotificationHubConfig.NOTIFICATION_HUB_DATA_RECIEVER_INTENT); dataIntent.putExtra("command", "get-all"); dataIntent.putExtra("data", " " + notifications.toString() + "\n"); context.getApplicationContext().sendBroadcast(dataIntent); } }
From source file:com.facebook.SharedPreferencesTokenCache.java
/** * Creates a {@link SharedPreferencesTokenCache SharedPreferencesTokenCache} instance * that is distinct for the passed in cacheKey. * * @param context/* w w w. j ava2 s .c o m*/ * The Context object to use to get the SharedPreferences object. * * @param cacheKey * Identifies a distinct set of token information. * * @throws NullPointerException if the passed in Context is null */ public SharedPreferencesTokenCache(Context context, String cacheKey) { Validate.notNull(context, "context"); 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); }