本文整理汇总了Java中android.app.Application类的典型用法代码示例。如果您正苦于以下问题:Java Application类的具体用法?Java Application怎么用?Java Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Application类属于android.app包,在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hookPackageManager
import android.app.Application; //导入依赖的package包/类
/**
* hookPackageManager
*
* @param application application
*/
private static void hookPackageManager(Application application) {
try {
Object currentActivityThread = HookCurrentActivityThread.getCurrentActivityThread(application);
if (currentActivityThread != null) {
Field sPackageManagerField = currentActivityThread.getClass().getDeclaredField("sPackageManager");
sPackageManagerField.setAccessible(true);
Object sPackageManager = sPackageManagerField.get(currentActivityThread);
Class<?> iPackageManagerInterface = Class.forName("android.content.pm.IPackageManager");
Object proxy = Proxy.newProxyInstance(iPackageManagerInterface.getClassLoader(),
new Class<?>[]{iPackageManagerInterface},
new HookPackageManagerHandler(sPackageManager));
sPackageManagerField.set(currentActivityThread, proxy);
PackageManager pm = application.getPackageManager();
Field mPmField = pm.getClass().getDeclaredField("mPM");
mPmField.setAccessible(true);
mPmField.set(pm, proxy);
}
} catch (Exception e) {
ApkLogger.get().debug("hookPackageManager Exception", e);
}
}
示例2: checkInstallation
import android.app.Application; //导入依赖的package包/类
@BeforeClass public static void checkInstallation() throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException {
try {
CondomProcess.installExcept(((Application) InstrumentationRegistry.getTargetContext().getApplicationContext()),
new CondomOptions().addKit(new NullDeviceIdKit()), "");
fail("CondomKit is incompatible with CondomProcess");
} catch (final IllegalArgumentException ignored) {}
// Install in default process intentionally, since test cases cannot run in secondary process.
CondomProcess.installExcept(((Application) InstrumentationRegistry.getTargetContext().getApplicationContext()), new CondomOptions(), "");
// Check IActivityManager proxy
@SuppressLint("PrivateApi") final Object am_proxy = Class.forName("android.app.ActivityManagerNative").getMethod("getDefault").invoke(null);
assertTrue(Proxy.isProxyClass(am_proxy.getClass()));
sCondomProcessActivityManager = (CondomProcess.CondomProcessActivityManager) Proxy.getInvocationHandler(am_proxy);
assertEquals(CondomProcess.CondomProcessActivityManager.class, sCondomProcessActivityManager.getClass());
// Check IPackageManager proxy
final PackageManager pm = context().getPackageManager();
assertEquals("android.app.ApplicationPackageManager", pm.getClass().getName());
final Field ApplicationPackageManager_mPm = pm.getClass().getDeclaredField("mPM");
ApplicationPackageManager_mPm.setAccessible(true);
final Object pm_proxy = ApplicationPackageManager_mPm.get(pm);
assertTrue(Proxy.isProxyClass(pm_proxy.getClass()));
sCondomProcessPackageManager = (CondomProcess.CondomProcessPackageManager) Proxy.getInvocationHandler(pm_proxy);
assertEquals(CondomProcess.CondomProcessPackageManager.class, sCondomProcessPackageManager.getClass());
}
示例3: onReceive
import android.app.Application; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
try {
int id = intent.getIntExtra(NOTIFICATION_ID, 0);
long currentTime = System.currentTimeMillis();
Log.i(LOG_TAG, "NotificationPublisher: Prepare To Publish: " + id + ", Now Time: " + currentTime);
Application applicationContext = (Application) context.getApplicationContext();
new RNPushNotificationHelper(applicationContext)
.sendToNotificationCentre(intent.getExtras());
} catch (Exception e) {
}
}
示例4: setUp
import android.app.Application; //导入依赖的package包/类
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
Application application = (Application) InstrumentationRegistry.getTargetContext().getApplicationContext();
inAppMessageHandler = mock(InAppMessageHandler.class);
MobileEngageConfig config = new MobileEngageConfig.Builder()
.application(application)
.credentials("14C19-A121F", "PaNkfOD90AVpYimMBuZopCpm8OWCrREu")
.disableDefaultChannel()
.enableExperimentalFeatures(MobileEngageFeature.IN_APP_MESSAGING)
.setDefaultInAppMessageHandler(inAppMessageHandler)
.build();
Field configField = MobileEngage.class.getDeclaredField("config");
configField.setAccessible(true);
configField.set(null, config);
provider = new InAppMessageHandlerProvider();
}
示例5: setup
import android.app.Application; //导入依赖的package包/类
@Before
public void setup() {
config = new MobileEngageConfig.Builder()
.application((Application) InstrumentationRegistry.getTargetContext().getApplicationContext())
.credentials(APPLICATION_CODE, APPLICATION_PASSWORD)
.disableDefaultChannel()
.build();
debugConfig = new MobileEngageConfig.Builder()
.application(ApplicationTestUtils.applicationDebug())
.credentials(APPLICATION_CODE, APPLICATION_PASSWORD)
.disableDefaultChannel()
.build();
releaseConfig = new MobileEngageConfig.Builder()
.application(ApplicationTestUtils.applicationRelease())
.credentials(APPLICATION_CODE, APPLICATION_PASSWORD)
.disableDefaultChannel()
.build();
deviceInfo = new DeviceInfo(InstrumentationRegistry.getContext());
}
示例6: checkIsMainProcess
import android.app.Application; //导入依赖的package包/类
public static boolean checkIsMainProcess(Application app) {
ActivityManager activityManager = (ActivityManager) app.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcessInfoList = activityManager.getRunningAppProcesses();
if (null == runningAppProcessInfoList) {
return false;
}
String currProcessName = null;
int currPid = android.os.Process.myPid();
//find the process name
for (RunningAppProcessInfo processInfo : runningAppProcessInfoList) {
if (null != processInfo && processInfo.pid == currPid) {
currProcessName = processInfo.processName;
}
}
//is current process the main process
if (!TextUtils.equals(currProcessName, app.getPackageName())) {
return false;
}
return true;
}
示例7: init
import android.app.Application; //导入依赖的package包/类
/**
* initialization
* <p>Need to add permission {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
*
* @param crashDir Crash file storage directory
* @return {@code true}: Initialized successfully<br>{@code false}: initialization failed
*/
public static boolean init(Application application, final String crashDir) {
if (mApplication == null)
mApplication = new WeakReference<>(application);
if (isSpace(crashDir)) {
dir = null;
} else {
dir = crashDir.endsWith(FILE_SEP) ? dir : dir + FILE_SEP;
}
if (mInitialized)
return true;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
&& mApplication.get().getExternalCacheDir() != null) {
defaultDir = mApplication.get().getExternalCacheDir() + FILE_SEP + "crash" + FILE_SEP;
} else {
defaultDir = mApplication.get().getCacheDir() + FILE_SEP + "crash" + FILE_SEP;
}
Thread.setDefaultUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
return mInitialized = true;
}
示例8: get
import android.app.Application; //导入依赖的package包/类
public static Foreground get(Context ctx){
if (instance == null) {
Context appCtx = ctx.getApplicationContext();
if (appCtx instanceof Application) {
init((Application)appCtx);
}
throw new IllegalStateException(
"Foreground is not initialised and " +
"cannot obtain the Application object");
}
return instance;
}
示例9: getActivityScopeReturnsExistingOne
import android.app.Application; //导入依赖的package包/类
@Test public void getActivityScopeReturnsExistingOne() {
Activity activity = Mockito.mock(Activity.class);
Application application = Mockito.mock(Application.class);
Mockito.when(activity.getApplication()).thenReturn(application);
ActivityScopedCache scope1 =
PresenterManager.getOrCreateActivityScopedCache(activity);
Assert.assertNotNull(scope1);
Assert.assertEquals(scope1, PresenterManager.getActivityScope(activity));
}
示例10: getContext
import android.app.Application; //导入依赖的package包/类
/**
* Gets the contexts of an activity without calling from an Activity class
*
* @return the main Application (as a Context)
*/
public static Context getContext() {
try {
final Class<?> activityThreadClass =
Class.forName("android.app.ActivityThread");
//find and load the main activity method
final Method method = activityThreadClass.getMethod("currentApplication");
return (Application) method.invoke(null, (Object[]) null);
} catch (final java.lang.Throwable e) {
// handle exception
throw new IllegalArgumentException("No context could be retrieved!");
}
}
示例11: init
import android.app.Application; //导入依赖的package包/类
public static void init(Application application) {
if (instances == null)
instances = new AccountHelper(application);
else {
// reload from source
instances.user = SharedPreferencesHelper.loadFormSource(instances.application, User.class);
TLog.d(TAG, "init reload:" + instances.user);
}
}
示例12: createShareView
import android.app.Application; //导入依赖的package包/类
@NonNull
private static Page createShareView(Application application, ShareManager shareManager, AttachmentManager attachmentManager) {
return new Page(
SHARE_PAGE_KEY,
R.drawable.ic_share,
application.getString(R.string.share_page_title),
new ShareViewFactory(shareManager, attachmentManager),
Collections.<TargetScreen>emptySet()
);
}
示例13: onReceive
import android.app.Application; //导入依赖的package包/类
@Override
public void onReceive(final Context context, final Intent intent) {
if (intent.getAction() != null && intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Log.i("BOOT", "Boot completed. Loading offline globals and resetup alarms");
TimetableManager.getInstance().loadOfflineGlobals((Application) context.getApplicationContext(), () -> {
AlarmSupervisor.getInstance().initialize();
AlarmSupervisor.getInstance().rescheduleAllAlarms(context.getApplicationContext());
});
}
}
示例14: provideRetrofit
import android.app.Application; //导入依赖的package包/类
@Provides
@Singleton
public Retrofit provideRetrofit(Application application, OkHttpClient okHttpClient, Retrofit.Builder builder, HttpUrl httpUrl, @Nullable RetrofitConfiguration configuration) {
builder.baseUrl(httpUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient);
if (configuration != null) {
configuration.configRetrofit(application, builder);
}
return builder.build();
}
示例15: setContext
import android.app.Application; //导入依赖的package包/类
public RYLA setContext(String projectKey, Application application, String buildType) {
if (buildType.equals("debug")) {
return setContext(projectKey, application, true);
} else {
return setContext(projectKey, application, false);
}
}