本文整理匯總了Java中android.content.Context.getApplicationContext方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getApplicationContext方法的具體用法?Java Context.getApplicationContext怎麽用?Java Context.getApplicationContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Context
的用法示例。
在下文中一共展示了Context.getApplicationContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: DownloadHandler
import android.content.Context; //導入方法依賴的package包/類
/**
* @param context 上下文
* @param fileDownloadTask 下載任務描述數據模型
* @param absDownloadDir 一個帶有自定義規則的下載目錄(如:目錄是否會自動清理,目錄下的文件命名規範等)
* @param baseDownloadNotifier 下載狀態監聽觀察者管理器
* @param iFileAvailableChecker 任務下載完成後的檢查器,主要用於檢查下載完成的文件是否有效
* @param isSupportMultiProcessDownload 是否支持多進程下載
*/
public DownloadHandler(Context context, FileDownloadTask fileDownloadTask, AbsDownloadDir absDownloadDir,
DownloadPublisher baseDownloadNotifier, IFileAvailableChecker iFileAvailableChecker,
boolean isSupportMultiProcessDownload) {
mApplicationContext = context.getApplicationContext();
mFileDownloadTask = fileDownloadTask;
mAbsDownloadDir = absDownloadDir;
mFileDownloadTask.setTempFile(mAbsDownloadDir.newDownloadTempFile(mFileDownloadTask));
mFileDownloadTask.setStoreFile(mAbsDownloadDir.newDownloadStoreFile(mFileDownloadTask));
mBaseDownloadNotifier = baseDownloadNotifier;
mIFileAvailableChecker = iFileAvailableChecker;
mIsSupportMultiProcessDownload = isSupportMultiProcessDownload;
// 實質下載器
mIDownloader = new AutoRetryDownloader(mApplicationContext, mFileDownloadTask);
}
示例2: testComponentCallbacksForTargetContext
import android.content.Context; //導入方法依賴的package包/類
@SmallTest
public void testComponentCallbacksForTargetContext() {
Context targetContext = getInstrumentation().getTargetContext();
Application targetApplication = (Application) targetContext.getApplicationContext();
AdvancedMockContext context = new AdvancedMockContext(targetContext);
Callback1 callback1 = new Callback1();
Callback2 callback2 = new Callback2();
context.registerComponentCallbacks(callback1);
context.registerComponentCallbacks(callback2);
targetApplication.onLowMemory();
assertTrue("onLowMemory should have been called.", callback1.mOnLowMemoryCalled);
assertTrue("onLowMemory should have been called.", callback2.mOnLowMemoryCalled);
Configuration configuration = new Configuration();
targetApplication.onConfigurationChanged(configuration);
assertEquals("onConfigurationChanged should have been called.", configuration,
callback1.mConfiguration);
assertEquals("onConfigurationChanged should have been called.", configuration,
callback2.mConfiguration);
targetApplication.onTrimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE);
assertEquals("onTrimMemory should have been called.", ComponentCallbacks2
.TRIM_MEMORY_MODERATE, callback2.mLevel);
}
示例3: DrawerMenuAdapter
import android.content.Context; //導入方法依賴的package包/類
public DrawerMenuAdapter(Context context, int textViewResourceId, List<NavDrawerItem> objects) {
super(context, textViewResourceId, objects);
inflater = LayoutInflater.from(context);
appContext = context.getApplicationContext();
mInfoButtonListener = new View.OnClickListener() {
@Override
public void onClick(View pView) {
pView.startAnimation(mBounceHelpButtonAnimation);
if (pView.getTag() != null && pView.getTag() instanceof Integer) {
showHelpToast((Integer) pView.getTag());
}
}
};
mBounceHelpButtonAnimation = AnimationUtils.loadAnimation(appContext, R.anim.action_button_help);
}
示例4: initVideoView
import android.content.Context; //導入方法依賴的package包/類
private void initVideoView(Context context) {
mAppContext = context.getApplicationContext();
mSettings = new Settings(mAppContext);
initBackground();
initRenders();
mVideoWidth = 0;
mVideoHeight = 0;
// REMOVED: getHolder().addCallback(mSHCallback);
// REMOVED: getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
// REMOVED: mPendingSubtitleTracks = new Vector<Pair<InputStream, MediaFormat>>();
mCurrentState = STATE_IDLE;
mTargetState = STATE_IDLE;
subtitleDisplay = new TextView(context);
subtitleDisplay.setTextSize(24);
subtitleDisplay.setGravity(Gravity.CENTER);
LayoutParams layoutParams_txt = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM);
addView(subtitleDisplay, layoutParams_txt);
}
示例5: onAttach
import android.content.Context; //導入方法依賴的package包/類
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof TaskCallbacks) {
mCallbacks = (TaskCallbacks) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement TaskCallbacks");
}
mApplicationContext = context.getApplicationContext();
}
示例6: GoogleServicesManager
import android.content.Context; //導入方法依賴的package包/類
private GoogleServicesManager(Context context) {
try {
TraceEvent.begin("GoogleServicesManager.GoogleServicesManager");
ThreadUtils.assertOnUiThread();
// We should store the application context, as we outlive any activity which may create
// us.
mContext = context.getApplicationContext();
mChromeSigninController = ChromeSigninController.get(mContext);
mSigninHelper = SigninHelper.get(mContext);
// The sign out flow starts by clearing the signed in user in the ChromeSigninController
// on the Java side, and then performs a sign out on the native side. If there is a
// crash on the native side then the signin state may get out of sync. Make sure that
// the native side is signed out if the Java side doesn't have a currently signed in
// user.
SigninManager signinManager = SigninManager.get(mContext);
if (!mChromeSigninController.isSignedIn() && signinManager.isSignedInOnNative()) {
Log.w(TAG, "Signed in state got out of sync, forcing native sign out");
signinManager.signOut();
}
// Initialize sync.
SyncController.get(context);
ApplicationStatus.registerApplicationStateListener(this);
} finally {
TraceEvent.end("GoogleServicesManager.GoogleServicesManager");
}
}
示例7: create
import android.content.Context; //導入方法依賴的package包/類
/**
* 創建finalbitmap
*
* @param ctx
* @return
*/
public static FinalBitmap create(Context ctx) {
if (mFinalBitmap == null) {
mFinalBitmap = new FinalBitmap(ctx.getApplicationContext());
mFinalBitmap.init();
}
return mFinalBitmap;
}
示例8: setEnabled
import android.content.Context; //導入方法依賴的package包/類
public static void setEnabled(Context context, final Class<?> componentClass, final boolean
enabled) {
final Context appContext = context.getApplicationContext();
executeOnFileIoThread(new Runnable() {
public void run() {
appContext.getPackageManager().setComponentEnabledSetting(new ComponentName
(appContext, componentClass), enabled ? 1 : 2, 1);
}
});
}
示例9: EncryptedFileDataSourceFactory
import android.content.Context; //導入方法依賴的package包/類
/**
* Instantiates a new Encrypted file data source factory.
*
* @param context the context
* @param cipher the cipher
* @param secretKeySpec the secret key spec
* @param ivParameterSpec the iv parameter spec
* @param listener the listener
*/
public EncryptedFileDataSourceFactory(Context context, Cipher cipher, SecretKeySpec secretKeySpec, IvParameterSpec ivParameterSpec, TransferListener<? super DataSource> listener) {
mCipher = cipher;
mSecretKeySpec = secretKeySpec;
mIvParameterSpec = ivParameterSpec;
mTransferListener = listener;
String userAgent = Util.getUserAgent(context, context.getPackageName());
this.context = context.getApplicationContext();
this.baseDataSourceFactory = new DefaultDataSourceFactory(context, userAgent);
}
示例10: b
import android.content.Context; //導入方法依賴的package包/類
private b(Context context) {
if (context == null) {
c.a("create db fail, context is null!");
} else {
this.a = new a(context.getApplicationContext(), "mwsdk_analytics.db");
}
}
示例11: init
import android.content.Context; //導入方法依賴的package包/類
public void init(Context context) {
//獲取係統默認的異常處理器
mDefaultCrashHandler = Thread.getDefaultUncaughtExceptionHandler();
//將當前實例設為係統默認的異常處理器
Thread.setDefaultUncaughtExceptionHandler(this);
//獲取Context,方便內部使用
mContext = context.getApplicationContext();
}
示例12: init
import android.content.Context; //導入方法依賴的package包/類
public void init(Context context) {
mContext = context.getApplicationContext();
PATH = Environment.getExternalStorageDirectory().getPath()
+ "/"
+ mContext.getResources().getString(R.string.app_name)
+ "/log/";
mDefaultCrashHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
}
示例13: CpuMonitor
import android.content.Context; //導入方法依賴的package包/類
public CpuMonitor(Context context) {
Log.d(TAG, "CpuMonitor ctor.");
appContext = context.getApplicationContext();
userCpuUsage = new MovingAverage(MOVING_AVERAGE_SAMPLES);
systemCpuUsage = new MovingAverage(MOVING_AVERAGE_SAMPLES);
totalCpuUsage = new MovingAverage(MOVING_AVERAGE_SAMPLES);
frequencyScale = new MovingAverage(MOVING_AVERAGE_SAMPLES);
lastStatLogTimeMs = SystemClock.elapsedRealtime();
scheduleCpuUtilizationTask();
}
示例14: getInstance
import android.content.Context; //導入方法依賴的package包/類
public synchronized static DeviceManager getInstance(Context context) {
if (sharedInstance == null) {
sharedInstance = new DeviceManager(context.getApplicationContext());
}
return sharedInstance;
}
示例15: OpenConfig
import android.content.Context; //導入方法依賴的package包/類
private OpenConfig(Context context, String str) {
this.c = context.getApplicationContext();
this.d = str;
a();
b();
}