微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.app.Application的实例源码

项目:android-apkBox    文件ApkHook.java   
/**
 * 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);
    }
}
项目:MiPushFramework    文件CondomProcesstest.java   
@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());
}
项目:react-native-leancloud-sdk    文件RNPushNotificationPublisher.java   
@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) {

    }
}
项目:android-mobile-engage-sdk    文件InAppMessageHandlerProviderTest.java   
@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();
}
项目:android-mobile-engage-sdk    文件RequestUtilsTest.java   
@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());
}
项目:AppVisibilityDetector    文件AppVisibilityDetector.java   
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;
}
项目:GmarchMvvm    文件CrashUtils.java   
/**
 * 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;
}
项目:com.ruuvi.station    文件Foreground.java   
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;
}
项目:GitHub    文件PresenterManagerTest.java   
@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));
}
项目:FTC2016    文件Util.java   
/**
 * 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!");
    }
}
项目:OSchina_resources_android    文件AccountHelper.java   
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);
    }
}
项目:Phial    文件PhialCore.java   
@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()
    );
}
项目:dhbw-tiMetable-android    文件DeviceBootReceiver.java   
@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());
        });
    }
}
项目:EazyBaseMVP    文件ClientModule.java   
@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();
}
项目:Lantern-sdk    文件RYLA.java   
public RYLA setContext(String projectKey,Application application,String buildType) {
    if (buildType.equals("debug")) {
        return setContext(projectKey,application,true);
    } else {
        return setContext(projectKey,false);
    }
}
项目:Android-skin-support    文件SkinActivityLifecycle.java   
public static SkinActivityLifecycle init(Application application) {
    if (sInstance == null) {
        synchronized (SkinActivityLifecycle.class) {
            if (sInstance == null) {
                sInstance = new SkinActivityLifecycle(application);
            }
        }
    }
    return sInstance;
}
项目:PicShow-zhaipin    文件VideoPresenter.java   
@Inject
public VideoPresenter(VideoContract.Model model,VideoContract.View rootView,RxErrorHandler handler,ImageLoader imageLoader,AppManager appManager) {
    super(model,rootView);
    this.mErrorHandler = handler;
    this.mApplication = application;
    this.mImageLoader = imageLoader;
    this.mAppManager = appManager;
}
项目:springreplugin    文件ActivityController.java   
public static final void install(Application application) {
    if (Build.VERSION.SDK_INT < 14) {
        if (LOG) {
            LogDebug.d(MAIN_TAG,"install activity watcher");
        }
        install2x();
        return;
    }

    if (LOG) {
        LogDebug.d(MAIN_TAG,"install activity lifecycle callbacks");
    }
    install4x(application);
}
项目:aurora    文件CategoryPresenter.java   
@Inject
public CategoryPresenter(CategoryContract.Model model,CategoryContract.View rootView,rootView);
    this.mErrorHandler = handler;
    this.mApplication = application;
    this.mImageLoader = imageLoader;
    this.mAppManager = appManager;
}
项目:GitHub    文件PresenterManagerTest.java   
@Test
public void getPresenterReturnsNull(){
  Activity activity = Mockito.mock(Activity.class);
  Application application = Mockito.mock(Application.class);
  Mockito.when(activity.getApplication()).thenReturn(application);

  Assert.assertNull(PresenterManager.getPresenter(activity,"viewId123"));
}
项目:GSoC-Info-Android    文件Organizationviewmodel.java   
public Organizationviewmodel(Application application) {
    super(application);
    organizations = GSoCApp.getorgDao().getAllOrganizations()
            .create(null,new PagedList.Config.Builder()
                    .setPageSize(30)
                    .setPrefetchdistance(10)
                    .build());
}
项目:EpubReaderAndroid    文件MainActivity.java   
Single<Epub> loadEpub() {
    if (epubSingle == null) {
        Application application = getApplication();
        epubSingle = Single.fromCallable(() -> Epub.fromUri(application,"file:///android_asset/The Silver Chair.epub"))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .cache();
    }
    return epubSingle;
}
项目:Android-Router    文件RemoteModule.java   
@RouterPath("/openRemoteActivity")
public void openRemoteActivity(Application context,String scheme,VPromise promise) {
    Intent intent = new Intent(context,RemoteActivity.class);
    intent.putExtra("tag",promise.getTag());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
项目:condom    文件CondomProcess.java   
/**
 * Install the condom protection for current process if it is not the default process.
 *
 * <p>This method must be called in {@link Application#onCreate()} to eliminate potential leakage.
 */
public static void installExceptDefaultProcess(final Application app,final CondomOptions options) {
    validateCondomOptions(options);
    final String current_process_name = getProcessName(app);
    if (current_process_name == null) return;
    final String default_process_name = app.getApplicationInfo().processName;
    if (! current_process_name.equals(default_process_name)) install(app,current_process_name,options);
}
项目:chromium-for-android-56-debug-video    文件ExternalPrerenderHandler.java   
/**
 * Provides an estimate of the contents size.
 *
 * The estimate is likely to be incorrect. This is not a problem,as the aim
 * is to avoid getting a different layout and resources than needed at
 * render time.
 * @param application The application to use for getting resources.
 * @param convertToDp Whether the value should be converted to dp from pixels.
 * @return The estimated prerender size in pixels or dp.
 */
public static Rect estimateContentSize(Application application,boolean convertToDp) {
    // The size is estimated as:
    // X = screenSizeX
    // Y = screenSizeY - top bar - bottom bar - custom tabs bar
    // The bounds rectangle includes the bottom bar and the custom tabs bar as well.
    Rect screenBounds = new Rect();
    Point screenSize = new Point();
    WindowManager wm = (WindowManager) application.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultdisplay().getSize(screenSize);
    Resources resources = application.getResources();
    int statusBarId = resources.getIdentifier("status_bar_height","dimen","android");
    try {
        screenSize.y -= resources.getDimensionPixelSize(statusBarId);
    } catch (Resources.NotFoundException e) {
        // nothing,this is just a best effort estimate.
    }
    screenBounds.set(0,resources.getDimensionPixelSize(R.dimen.custom_tabs_control_container_height),screenSize.x,screenSize.y);

    if (convertToDp) {
        float density = resources.getdisplayMetrics().density;
        screenBounds.top = (int) Math.ceil(screenBounds.top / density);
        screenBounds.left = (int) Math.ceil(screenBounds.left / density);
        screenBounds.right = (int) Math.ceil(screenBounds.right / density);
        screenBounds.bottom = (int) Math.ceil(screenBounds.bottom / density);
    }
    return screenBounds;
}
项目:PictureShow    文件TimeLinePageDataLoader.java   
public TimeLinePageDataLoader(Application context,LoadListener l) {
    mContext = (PictureShowApplication)context;
    mListener = l;
    notifier = new ChangeNotify(this,new Uri[] {
            MediaSetUtils.VIDEO_URI,MediaSetUtils.IMAGE_URI
    },mContext);
}
项目:support-application    文件EnvironmentCompat.java   
/**
 * application onCreate最前面调用
 *
 * @param application Application
 * @param defaultEnv  认环境
 */
public void onApplicationCreate(Application application,Env defaultEnv) {
    try {
        SharedPreferences sharedPreferences = application.getSharedPreferences(KEY,Context.MODE_PRIVATE);
        String persistEnv = sharedPreferences.getString(KEY,defaultEnv.name());
        this.env = Env.valueOf(persistEnv);
    } catch (Exception e) {
        e.printstacktrace();
        this.env = Env.RELEASE;
    }
}
项目:BuildingDebugFeatures    文件DebugNetworkModule.java   
@Override
OkHttpClient.Builder okHttpClientBuilder(Application application) {
    OkHttpClient.Builder builder = super.okHttpClientBuilder(application)
            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor(new StethoInterceptor());

    if (new DebugPreferences(application).isChuckEnabled()) {
        builder.addInterceptor(new ChuckInterceptor(application));
    }
    return builder;
}
项目:aurora    文件HistoryPresenter.java   
@Inject
public HistoryPresenter(HistoryContract.Model model,HistoryContract.View rootView,rootView);
    this.mErrorHandler = handler;
    this.mApplication = application;
    this.mImageLoader = imageLoader;
    this.mAppManager = appManager;
}
项目:weex-3d-map    文件WxsdkEngine.java   
/**
 * Deprecated. Use {@link #initialize(Application,InitConfig)} instead.
 */
@Deprecated
public static void init(Application application,IWXUserTrackAdapter utAdapter,String framework) {
  initialize(application,new InitConfig.Builder()
      .setUtAdapter(utAdapter)
      .build()
  );
}
项目:LQRBiliBlili    文件VideoDetailPresenter.java   
@Inject
public VideoDetailPresenter(VideoDetailContract.Model model,VideoDetailContract.View rootView,rootView);
    this.mErrorHandler = handler;
    this.mApplication = application;
    this.mImageLoader = imageLoader;
    this.mAppManager = appManager;
    RetrofitUrlManager.getInstance().putDomain("video_detail_summary",Api.VIDEO_DETAIL_SUMMARY_BASE_URL);
    RetrofitUrlManager.getInstance().putDomain("video_detail_reply",Api.VIDEO_DETAIL_REPLY_BASE_URL);
}
项目:GmarchMvvm    文件AppManager.java   
@Inject
public AppManager(Application application) {
    this.mApplication = application;
    EventBus.getDefault().register(this);
}
项目:APIJSON-Android-RxJava    文件ApplicationTest.java   
public Applicationtest() {
    super(Application.class);
}
项目:MVVMFrames    文件LoginPresenter.java   
@Inject
public LoginPresenter(Application application,LoginContract.Model model,LoginContract.View view) {
    super(model,view);
    this.application = (MVPApplication) application;
}
项目:com.ruuvi.station    文件Foreground.java   
public static Foreground get(Application application){
    if (instance == null) {
        init(application);
    }
    return instance;
}
项目:MoligyMvpArms    文件AppManager.java   
@Inject
public AppManager(Application application) {
    this.mApplication = application;
    EventBus.getDefault().register(this);
}
项目:GitHub    文件ApplicationTest.java   
public Applicationtest() {
    super(Application.class);
}
项目:XYSeekBar    文件ApplicationTest.java   
public Applicationtest() {
    super(Application.class);
}
项目:AndroidSnooper    文件AndroidSnooper.java   
public static AndroidSnooper init(Application application) {
  if (androidSnooper == null) {
    androidSnooper = new AndroidSnooper();
  }
  return androidSnooper;
}
项目:Bailan    文件RxRetrofitApp.java   
private static void setApplication(Application application) {
    RxRetrofitApp.application = application;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。