Java Code Examples for android.app.Activity#getApplicationContext()
The following examples show how to use
android.app.Activity#getApplicationContext() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: AgentWeb File: DefaultDownloadImpl.java License: Apache License 2.0 | 6 votes |
protected DefaultDownloadImpl(Activity activity, WebView webView, PermissionInterceptor permissionInterceptor) { this.mContext = activity.getApplicationContext(); this.mActivityWeakReference = new WeakReference<Activity>(activity); this.mPermissionListener = permissionInterceptor; this.mAgentWebUIController = new WeakReference<AbsAgentWebUIController>(AgentWebUtils.getAgentWebUIControllerByWebView(webView)); try { DownloadImpl.getInstance().with(this.mContext); isInstallDownloader = true; } catch (Throwable throwable) { LogUtils.e(TAG, "implementation 'com.download.library:Downloader:x.x.x'"); if (LogUtils.isDebug()) { throwable.printStackTrace(); } isInstallDownloader = false; } }
Example 2
Source Project: L.TileLayer.Cordova File: LocalFilesystem.java License: MIT License | 6 votes |
/** * Send broadcast of new file so files appear over MTP * * @param inputURL */ private void broadcastNewFile(LocalFilesystemURL inputURL) { File file = new File(this.filesystemPathForURL(inputURL)); if (file.exists()) { //Get the activity Activity activity = this.cordova.getActivity(); //Get the context Context context = activity.getApplicationContext(); //Create the URI Uri uri = Uri.fromFile(file); //Create the intent Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri); //Send broadcast of new file context.sendBroadcast(intent); } }
Example 3
Source Project: AndroidUSBCamera File: AbstractUVCCameraHandler.java License: Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public void handleUpdateMedia(final String path) { if (DEBUG) Log.v(TAG_THREAD, "handleUpdateMedia:path=" + path); final Activity parent = mWeakParent.get(); final boolean released = (mHandler == null) || mHandler.mReleased; if (parent != null && parent.getApplicationContext() != null) { try { if (DEBUG) Log.i(TAG, "MediaScannerConnection#scanFile"); MediaScannerConnection.scanFile(parent.getApplicationContext(), new String[]{path}, null, null); } catch (final Exception e) { Log.e(TAG, "handleUpdateMedia:", e); } if (released || parent.isDestroyed()) handleRelease(); } else { Log.w(TAG, "MainActivity already destroyed"); // give up to add this movie to MediaStore now. // Seeing this movie on Gallery app etc. will take a lot of time. handleRelease(); } }
Example 4
Source Project: reader File: FileUtils.java License: MIT License | 6 votes |
protected HashMap<String, String> getAvailableFileSystems(Activity activity) { Context context = activity.getApplicationContext(); HashMap<String, String> availableFileSystems = new HashMap<String,String>(); availableFileSystems.put("files", context.getFilesDir().getAbsolutePath()); availableFileSystems.put("documents", new File(context.getFilesDir(), "Documents").getAbsolutePath()); availableFileSystems.put("cache", context.getCacheDir().getAbsolutePath()); availableFileSystems.put("root", "/"); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { try { availableFileSystems.put("files-external", context.getExternalFilesDir(null).getAbsolutePath()); availableFileSystems.put("sdcard", Environment.getExternalStorageDirectory().getAbsolutePath()); availableFileSystems.put("cache-external", context.getExternalCacheDir().getAbsolutePath()); } catch(NullPointerException e) { Log.d(LOG_TAG, "External storage unavailable, check to see if USB Mass Storage Mode is on"); } } return availableFileSystems; }
Example 5
Source Project: incubator-weex-playground File: ScreenShot.java License: Apache License 2.0 | 5 votes |
private static Bitmap takeScreenShot(Activity activity) { Context ctx = activity.getApplicationContext(); String screenShotDir = getWeexScreenShotDir(ctx); View view = activity.getWindow().getDecorView(); rootView = view; firstScrollView = findFirstScrollerByRootView(rootView); firstListView = findFirstListByRootView(rootView); Bitmap snapBitmap = null; // 优先scroller ->list->root if(null !=firstScrollView ){ snapBitmap = doSanpForListOrScroller(firstScrollView); } else { Log.e("weex_test", "firstScrollView is " + firstScrollView); if (null != firstListView){ snapBitmap = doSanpForListOrScroller(firstListView); }else { Log.e("weex_test", "firstListView is " + firstListView); if(null != rootView){ // snapBitmap = doSanpForListOrScroller(rootView); } } } return snapBitmap; }
Example 6
Source Project: Trivia-Knowledge File: GameHelper.java License: Apache License 2.0 | 5 votes |
/** Call this method from your Activity's onStart(). */ public void onStart(Activity act) { mActivity = act; mAppContext = act.getApplicationContext(); debugLog("onStart"); assertConfigured("onStart"); if (mConnectOnStart) { if (mGoogleApiClient.isConnected()) { Log.w(TAG, "GameHelper: client was already connected on onStart()"); } else { debugLog("Connecting client."); mConnecting = true; mGoogleApiClient.connect(); } } else { debugLog("Not attempting to connect because mConnectOnStart=false"); debugLog("Instead, reporting a sign-in failure."); mHandler.postDelayed(new Runnable() { @Override public void run() { notifyListener(false); } }, 1000); } }
Example 7
Source Project: mobilecloud-15 File: AcronymOps.java License: Apache License 2.0 | 5 votes |
/** * Called after a runtime configuration change occurs to finish * the initialisation steps. */ public void onConfiguration(Activity activity, boolean firstTimeIn) { final String time = firstTimeIn ? "first time" : "second+ time"; Log.d(TAG, "onConfiguration() called the " + time + " with activity = " + activity); // (Re)set the mActivity WeakReference. mActivity = new WeakReference<>((AcronymActivity) activity); if (firstTimeIn) { // Initialize the TimeoutCache. mAcronymCache = new ContentProviderTimeoutCache (activity.getApplicationContext()); // Create a proxy to access the Acronym web service. TODO // -- you fill in here, replacing "null" with the // appropriate initialization of the proxy. mAcronymWebServiceProxy = null; } else // Update the results on the UI. updateResultsDisplay(); }
Example 8
Source Project: Saiy-PS File: FragmentSuperUser.java License: GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void onAttach(final Activity activity) { super.onAttach(activity); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { this.mContext = activity.getApplicationContext(); } }
Example 9
Source Project: cordova-google-play-games-services File: GameHelper.java License: MIT License | 5 votes |
/** Call this method from your Activity's onStart(). */ public void onStart(Activity act) { mActivity = act; mAppContext = act.getApplicationContext(); debugLog("onStart"); assertConfigured("onStart"); if (mConnectOnStart) { if (mGoogleApiClient.isConnected()) { Log.w(TAG, "GameHelper: client was already connected on onStart()"); } else { debugLog("Connecting client."); mConnecting = true; mGoogleApiClient.connect(); } } else { debugLog("Not attempting to connect becase mConnectOnStart=false"); debugLog("Instead, reporting a sign-in failure."); mHandler.postDelayed(new Runnable() { @Override public void run() { notifyListener(false); } }, 1000); } }
Example 10
Source Project: FixMath File: GameHelper.java License: Apache License 2.0 | 5 votes |
/** Call this method from your Activity's onStart(). */ public void onStart(Activity act) { mActivity = act; mAppContext = act.getApplicationContext(); debugLog("onStart"); assertConfigured("onStart"); if (mConnectOnStart) { if (mGoogleApiClient.isConnected()) { Log.w(TAG, "GameHelper: client was already connected on onStart()"); } else { debugLog("Connecting client."); mConnecting = true; mGoogleApiClient.connect(); } } else { debugLog("Not attempting to connect becase mConnectOnStart=false"); debugLog("Instead, reporting a sign-in failure."); mHandler.postDelayed(new Runnable() { @Override public void run() { notifyListener(false); } }, 1000); } }
Example 11
Source Project: dice-heroes File: GameHelper.java License: GNU General Public License v3.0 | 5 votes |
/** Call this method from your Activity's onStart(). */ public void onStart(Activity act) { mActivity = act; mAppContext = act.getApplicationContext(); debugLog("onStart"); assertConfigured("onStart"); if (mConnectOnStart) { if (mGoogleApiClient.isConnected()) { Log.w(TAG, "GameHelper: client was already connected on onStart()"); } else { debugLog("Connecting client."); mConnecting = true; mGoogleApiClient.connect(); } } else { debugLog("Not attempting to connect becase mConnectOnStart=false"); debugLog("Instead, reporting a sign-in failure."); mHandler.postDelayed(new Runnable() { @Override public void run() { notifyListener(false); } }, 1000); } }
Example 12
Source Project: base-module File: BlurConfig.java License: Apache License 2.0 | 5 votes |
public Builder(Activity activity) { checkNull(activity, "activity"); mBlurConfig = new BlurConfig(SOURCE_ACTIVITY); mBlurConfig.context = new WeakReference<Context>(activity.getApplicationContext()); mBlurConfig.source = new WeakReference<Object>(activity); View view = activity.getWindow().getDecorView().getRootView(); mBlurConfig.width = view.getMeasuredWidth(); mBlurConfig.height = view.getMeasuredHeight(); }
Example 13
Source Project: MultiLamp File: MultiLamp.java License: Apache License 2.0 | 5 votes |
public MultiLamp(Activity activity) { super(activity.getApplicationContext()); this.activity = activity; this.context = activity.getApplicationContext(); init(); }
Example 14
Source Project: react-native-update File: RCTUpdateMgr.java License: MIT License | 5 votes |
public RCTUpdateMgr(Activity activity) { this.activity = activity; this.context = activity.getApplicationContext(); documentFilePath = activity.getFilesDir().getAbsolutePath()+"/"; mainBundleFilePath = documentFilePath+MAIN_BUNDLE_FILE; PackageInfo pInfo = null; try { pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); appVersion = pInfo.versionName; buildVersion = pInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } settings = activity.getSharedPreferences(PREF_LOCAL_STORAGE, Activity.MODE_PRIVATE); String lastversionCode = settings.getString("APK_VERSION_CODE", "0"); if (!lastversionCode.equals("" + buildVersion)) { isRunFirstOnNewVersion = true; SharedPreferences.Editor edit = settings.edit(); edit.putString("APK_VERSION_CODE", "" + buildVersion); edit.putString("JS_VERSION_CLEAR", "yes"); edit.commit(); new Thread(new Runnable() { @Override public void run() { deleteDirectoryAtPath(documentFilePath + MAIN_BUNDLE_FOLDER); } }).start(); } }
Example 15
Source Project: sdscanner File: ScanFragment.java License: GNU General Public License v2.0 | 4 votes |
@Override public void onAttach(Activity activity) { super.onAttach(activity); mCallbacks = (ScanProgressCallbacks) activity; mApplicationContext = activity.getApplicationContext(); }
Example 16
Source Project: edslite File: ChangeEDSLocationPasswordBaseTask.java License: GNU General Public License v2.0 | 4 votes |
@Override public void initTask(Activity activity) { _context = activity.getApplicationContext(); _location = (EDSLocation) LocationsManager.getLocationsManager(_context).getFromBundle(getArguments(), null); }
Example 17
Source Project: AndroidChromium File: SingleTabModelSelector.java License: Apache License 2.0 | 4 votes |
public SingleTabModelSelector(Activity activity, boolean incognito, boolean blockNewWindows) { mApplicationContext = activity.getApplicationContext(); mTabModel = new SingleTabModel(activity, incognito, blockNewWindows); initialize(false, mTabModel); }
Example 18
Source Project: ui File: Simple3_frag.java License: Apache License 2.0 | 4 votes |
@Override public void onAttach(Activity activity) { super.onAttach(activity); myContext = activity.getApplicationContext(); Log.d(TAG,"onAttach"); }
Example 19
Source Project: io2014-codelabs File: GameHelper.java License: Apache License 2.0 | 3 votes |
/** * Construct a GameHelper object, initially tied to the given Activity. * After constructing this object, call @link{setup} from the onCreate() * method of your Activity. * * @param clientsToUse * the API clients to use (a combination of the CLIENT_* flags, * or CLIENT_ALL to mean all clients). */ public GameHelper(Activity activity, int clientsToUse) { mActivity = activity; mAppContext = activity.getApplicationContext(); mRequestedClients = clientsToUse; mHandler = new Handler(); }
Example 20
Source Project: youqu_master File: UiUtils.java License: Apache License 2.0 | 2 votes |
/** * 跳转界面 * * @param activity * @param homeActivityClass */ public static void startActivity(Activity activity, Class homeActivityClass) { Intent intent = new Intent(activity.getApplicationContext(), homeActivityClass); activity.startActivity(intent); }