本文整理汇总了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();
}