當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。