当前位置: 首页>>代码示例>>Java>>正文


Java Application类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:30,代码来源:ApkHook.java

示例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());
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:27,代码来源:CondomProcessTest.java

示例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) {

    }
}
 
开发者ID:zzzkk2009,项目名称:react-native-leancloud-sdk,代码行数:17,代码来源:RNPushNotificationPublisher.java

示例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();
}
 
开发者ID:emartech,项目名称:android-mobile-engage-sdk,代码行数:20,代码来源:InAppMessageHandlerProviderTest.java

示例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());
}
 
开发者ID:emartech,项目名称:android-mobile-engage-sdk,代码行数:23,代码来源:RequestUtilsTest.java

示例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;
}
 
开发者ID:zyc945,项目名称:AppVisibilityDetector,代码行数:24,代码来源:AppVisibilityDetector.java

示例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;
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:27,代码来源:CrashUtils.java

示例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;
}
 
开发者ID:ruuvi,项目名称:com.ruuvi.station,代码行数:13,代码来源:Foreground.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:PresenterManagerTest.java

示例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!");
    }
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:18,代码来源:Util.java

示例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);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:10,代码来源:AccountHelper.java

示例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()
    );
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:11,代码来源:PhialCore.java

示例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());
        });
    }
}
 
开发者ID:dhbw-timetable,项目名称:dhbw-timetable-android,代码行数:11,代码来源:DeviceBootReceiver.java

示例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();
}
 
开发者ID:harrylefit,项目名称:EazyBaseMVP,代码行数:14,代码来源:ClientModule.java

示例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);
    }
}
 
开发者ID:TeamThresh,项目名称:Lantern-sdk,代码行数:8,代码来源:RYLA.java


注:本文中的android.app.Application类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。