Java Code Examples for android.app.Application#getPackageName()

The following examples show how to use android.app.Application#getPackageName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Atlas.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Init the framework
 * 
 * @param application
 * @return
 * @throws Exception
 */
public void init(Application application,boolean reset) throws AssertionArrayException, Exception {
    if(application==null){
        throw new RuntimeException("application is null,atlas init failed!");
    }
    ApplicationInfo app_info = application.getApplicationInfo();
    sAPKSource = app_info.sourceDir;
    RuntimeVariables.androidApplication = application;
    RuntimeVariables.delegateResources  = application.getResources();
    Framework.containerVersion = RuntimeVariables.sInstalledVersionName;
    ClassLoader cl = Atlas.class.getClassLoader();
    Framework.systemClassLoader = cl;
    // defineAndVerify
    String packageName = application.getPackageName();

    RuntimeVariables.delegateClassLoader = Atlas.class.getClassLoader();

    frameworkLifecycleHandler = new FrameworkLifecycleHandler();
    Framework.frameworkListeners.add(frameworkLifecycleHandler);

}
 
Example 2
Source File: RemoteConnection.java    From CC with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前设备上安装的可供跨app调用组件的App列表
 * @return 包名集合
 */
public static List<String> scanComponentApps() {
    Application application = CC.getApplication();
    String curPkg = application.getPackageName();
    PackageManager pm = application.getPackageManager();
    // 查询所有已经安装的应用程序
    Intent intent = new Intent("action.com.billy.cc.connection");
    List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
    List<String> packageNames = new ArrayList<>();
    for (ResolveInfo info : list) {
        ActivityInfo activityInfo = info.activityInfo;
        String packageName = activityInfo.packageName;
        if (curPkg.equals(packageName)) {
            continue;
        }
        if (tryWakeup(packageName)) {
            packageNames.add(packageName);
        }
    }
    return packageNames;
}
 
Example 3
Source File: OpenAtlas.java    From ACDD with MIT License 6 votes vote down vote up
public void init(Application application)
        throws Exception {
    String packageName = application.getPackageName();
    OpenAtlasHacks.defineAndVerify();
    ClassLoader classLoader = OpenAtlas.class.getClassLoader();
    DelegateClassLoader delegateClassLoader = new DelegateClassLoader(classLoader);
    Framework.systemClassLoader = classLoader;
    RuntimeVariables.delegateClassLoader = delegateClassLoader;
    RuntimeVariables.delegateResources = initResources(application);
    RuntimeVariables.androidApplication = application;
    AndroidHack.injectClassLoader(packageName, delegateClassLoader);
    AndroidHack.injectInstrumentationHook(new InstrumentationHook(AndroidHack
                    .getInstrumentation(), application.getBaseContext()));
    injectApplication(application, packageName);
    this.bundleLifecycleHandler = new BundleLifecycleHandler();
    Framework.syncBundleListeners.add(this.bundleLifecycleHandler);
    this.frameworkLifecycleHandler = new FrameworkLifecycleHandler();
    Framework.frameworkListeners.add(this.frameworkLifecycleHandler);
    AndroidHack.hackH();
    // Framework.initialize(properties);
}
 
Example 4
Source File: Ln.java    From fogger with Apache License 2.0 6 votes vote down vote up
@Inject
protected BaseConfig(Application application) {
    try {
        packageName = application != null  ? application.getPackageName(): "";
        final int flags = application.getPackageManager().getApplicationInfo(packageName, 0).flags;
        minimumLogLevel = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 ? Log.VERBOSE : Log.INFO;
        scope = packageName.toUpperCase();

        Log.i(packageName, "Configuring Logging, minimum log level is " +  logLevelToString(minimumLogLevel));

    } catch (Exception e) {
        try {
            Log.e(packageName, "Error configuring logger", e);
        } catch (RuntimeException f) {
            // HACK ignore Stub! errors in mock objects during testing
        }
    }
}
 
Example 5
Source File: NotifyDeveloperHandler.java    From slf4android with MIT License 6 votes vote down vote up
NotifyDeveloperHandler(Application context, Iterable<String> emailAddress, LogLevel minLevel, final ActivityStateListener stateListener) {
    this.context = context;
    this.emailAddress = Lists.newArrayList(emailAddress);
    this.filter = new AtLeastFilter(minLevel);
    this.activityState = new WeakReference<>(stateListener);
    this.attachmentClassList = new ArrayList<>();
    this.shakeDetector = new ShakeDetector(new ShakeDetector.Listener() {
        @Override
        public void hearShake() {
            ActivityStateListener listener = activityState.get();
            if (listener != null) {
                if (listener.isAppInForeground()) {
                    beginPublishOnMainThread(new LogRecord(Level.INFO, "Report a problem with app"));
                } else {
                    Log.i(TAG, "Ignore shake event - the app appears to be in background");
                }
            } else {
                Log.i(TAG, "Ignore shake event - can't detect if app is in foreground (API < 14)");
            }
        }
    });
    this.emailSubject = context.getString(R.string.slf4android_email_subject) + context.getPackageName();
    this.emailBody = context.getString(R.string.slf4android_email_extra_text);
}
 
Example 6
Source File: ManifestValidator.java    From clevertap-android-sdk with MIT License 6 votes vote down vote up
@SuppressWarnings("SameParameterValue")
private static void validateActivityInManifest(Application application, Class activityClass) throws PackageManager.NameNotFoundException {
    PackageManager pm = application.getPackageManager();
    String packageName = application.getPackageName();

    PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
    ActivityInfo[] activities = packageInfo.activities;
    String activityClassName = activityClass.getName();
    for (ActivityInfo activityInfo : activities) {
        if (activityInfo.name.equals(activityClassName)) {
            Logger.i(activityClassName.replaceFirst("com.clevertap.android.sdk.", "") + " is present");
            return;
        }
    }
    Logger.i(activityClassName.replaceFirst("com.clevertap.android.sdk.", "") + " not present");
}
 
Example 7
Source File: Atlas.java    From AtlasForAndroid with MIT License 6 votes vote down vote up
public void init(Application application, Properties properties) throws AssertionArrayException, Exception {
    String packageName = application.getPackageName();
    AtlasHacks.defineAndVerify();
    ClassLoader classLoader = Atlas.class.getClassLoader();
    ClassLoader delegateClassLoader = new DelegateClassLoader(classLoader);
    Framework.systemClassLoader = classLoader;
    RuntimeVariables.delegateClassLoader = delegateClassLoader;
    RuntimeVariables.delegateResources = application.getResources();
    RuntimeVariables.androidApplication = application;
    AndroidHack.injectClassLoader(packageName, delegateClassLoader);
    AndroidHack.injectInstrumentationHook(new InstrumentationHook(AndroidHack.getInstrumentation(), application.getBaseContext()));
    injectApplication(application, packageName);
    this.bundleLifecycleHandler = new BundleLifecycleHandler();
    Framework.syncBundleListeners.add(this.bundleLifecycleHandler);
    this.frameworkLifecycleHandler = new FrameworkLifecycleHandler();
    Framework.frameworkListeners.add(this.frameworkLifecycleHandler);
    AndroidHack.hackH();
    Framework.initialize(properties);
}
 
Example 8
Source File: DataObjectRepositry.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
public static void init(Application application) {
    String PREF_NAME = application.getPackageName();
    if (dataObjectRepositry == null) {
          dataObjectRepositry = new DataObjectRepositry(application);

    } else {
        throw new RuntimeException("DataObjectRepository not initialized");
    }
}
 
Example 9
Source File: GPTInstrumentation.java    From GPT with Apache License 2.0 5 votes vote down vote up
/**
 * onCallApplicationOnCreate
 *
 * @param app Application
 */
private void onCallApplicationOnCreate(Application app) {
    String packageName = app.getPackageName();
    boolean isPlugin = isPlugin(packageName);

    if (!isPlugin) {
        return;
    }

    // Begin:【FixBug】解决在中兴手机上找不到资源的问题,中兴部分手机的ROM上自己继承ContextImpl实现了一个AppContextImpl,
    // 里面做一些BaseContext的复用,导致插件获取Resources时可能会取到宿主的。
    try {
        Class<?> clsCtxImpl = Class.forName("android.app.ContextImpl");
        Object base = app.getBaseContext();
        if (base.getClass() != clsCtxImpl) {
            Constructor<?> cst = clsCtxImpl.getConstructor(clsCtxImpl);
            Object impl = cst.newInstance(base);
            JavaCalls.setField(app, "mBase", impl);
        }
    } catch (Exception e) {

        if (DEBUG) {
            e.printStackTrace();
        }
        if (ProxyEnvironment.hasInstance(app.getPackageName())) {
            ReportManger.getInstance().onException(
                    ProxyEnvironment.getInstance(app.getPackageName()).getApplicationProxy(), packageName,
                    Util.getCallStack(e), ExceptionConstants.TJ_78730010);
        }
    }

    replacePluginPackageName2Host(app);
    replaceSystemServices(app);
    replaceExternalDirs(app);

    ProxyUtil.replaceSystemServices(app);
}
 
Example 10
Source File: ApiClientMgr.java    From GcmForMojo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 初始化
 * @param app 应用程序
 */
public void init(Application app) {

    HMSAgentLog.d("init");

    // 保存应用程序context
    context = app.getApplicationContext();

    // 取得应用程序包名
    curAppPackageName = app.getPackageName();

    // 注册activity onResume回调
    ActivityMgr.INST.unRegisterActivitResumeEvent(this);
    ActivityMgr.INST.registerActivitResumeEvent(this);
}
 
Example 11
Source File: CrashHelper.java    From AndroidCrashHelper with MIT License 5 votes vote down vote up
/**
 * Installs this crash tool on the application using the default error activity.
 *
 * @param context Application to use for obtaining the ApplicationContext. Must not be null.
 * @see Application
 */
public static void install(Context context, Class<? extends Activity> clazz) {
    try {
        if (context == null) {
            Log.e(TAG, "Install failed: context is null!");
            return;
        }
        application = (Application) context.getApplicationContext();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            Log.w(TAG, "Crash tool will be installed, but may not be reliable in API lower than 14");
        }

        //INSTALL!
        Thread.UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler();

        String pkgName = application.getPackageName();
        Log.d(TAG, "current application package name is " + pkgName);
        if (oldHandler != null && oldHandler.getClass().getName().startsWith(pkgName)) {
            Log.e(TAG, "You have already installed crash tool, doing nothing!");
            return;
        }
        if (oldHandler != null && !oldHandler.getClass().getName().startsWith("com.android.internal.os")) {
            Log.e(TAG, "IMPORTANT WARNING! You already have an UncaughtExceptionHandler, are you sure this is correct? If you use ACRA, Crashlytics or similar libraries, you must initialize them AFTER this crash tool! Installing anyway, but your original handler will not be called.");
        }

        //We define a default exception handler that does what we want so it can be called from Crashlytics/ACRA
        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            application.registerActivityLifecycleCallbacks(new MyActivityLifecycleCallbacks());
        }

        Log.i(TAG, "Crash tool has been installed.");
    } catch (Throwable t) {
        Log.e(TAG, "An unknown error occurred while installing crash tool, it may not have been properly initialized. Please report this as a bug if needed.", t);
    }

    if (clazz != null) {
        setCrashActivityClass(clazz);
    }
}
 
Example 12
Source File: CrashHelper.java    From AndroidCrashHelper with MIT License 5 votes vote down vote up
/**
 * Installs this crash tool on the application using the default error activity.
 *
 * @param context Application to use for obtaining the ApplicationContext. Must not be null.
 * @see Application
 */
public static void install(Context context, Class<? extends Activity> clazz) {
    try {
        if (context == null) {
            Log.e(TAG, "Install failed: context is null!");
            return;
        }
        application = (Application) context.getApplicationContext();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            Log.w(TAG, "Crash tool will be installed, but may not be reliable in API lower than 14");
        }

        //INSTALL!
        Thread.UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler();

        String pkgName = application.getPackageName();
        Log.d(TAG, "current application package name is " + pkgName);
        if (oldHandler != null && oldHandler.getClass().getName().startsWith(pkgName)) {
            Log.e(TAG, "You have already installed crash tool, doing nothing!");
            return;
        }
        if (oldHandler != null && !oldHandler.getClass().getName().startsWith("com.android.internal.os")) {
            Log.e(TAG, "IMPORTANT WARNING! You already have an UncaughtExceptionHandler, are you sure this is correct? If you use ACRA, Crashlytics or similar libraries, you must initialize them AFTER this crash tool! Installing anyway, but your original handler will not be called.");
        }

        //We define a default exception handler that does what we want so it can be called from Crashlytics/ACRA
        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            application.registerActivityLifecycleCallbacks(new MyActivityLifecycleCallbacks());
        }

        Log.i(TAG, "Crash tool has been installed.");
    } catch (Throwable t) {
        Log.e(TAG, "An unknown error occurred while installing crash tool, it may not have been properly initialized. Please report this as a bug if needed.", t);
    }

    if (clazz != null) {
        setCrashActivityClass(clazz);
    }
}
 
Example 13
Source File: ManifestValidator.java    From clevertap-android-sdk with MIT License 5 votes vote down vote up
private static void validateReceiverInManifest(Application application, String receiverClassName) throws PackageManager.NameNotFoundException {
    PackageManager pm = application.getPackageManager();
    String packageName = application.getPackageName();

    PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_RECEIVERS);
    ActivityInfo[] receivers = packageInfo.receivers;

    for (ActivityInfo activityInfo : receivers) {
        if (activityInfo.name.equals(receiverClassName)) {
            Logger.i(receiverClassName.replaceFirst("com.clevertap.android.sdk.", "") + " is present");
            return;
        }
    }
    Logger.i(receiverClassName.replaceFirst("com.clevertap.android.sdk.", "") + " not present");
}
 
Example 14
Source File: ManifestValidator.java    From clevertap-android-sdk with MIT License 5 votes vote down vote up
private static void validateServiceInManifest(Application application, String serviceClassName) throws PackageManager.NameNotFoundException {
    PackageManager pm = application.getPackageManager();
    String packageName = application.getPackageName();

    PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SERVICES);
    ServiceInfo[] services = packageInfo.services;
    for (ServiceInfo serviceInfo : services) {
        if (serviceInfo.name.equals(serviceClassName)) {
            Logger.i(serviceClassName.replaceFirst("com.clevertap.android.sdk.", "") + " is present");
            return;
        }
    }
    Logger.i(serviceClassName.replaceFirst("com.clevertap.android.sdk.", "") + " not present");
}
 
Example 15
Source File: PreferencesNameProvider.java    From callerid-for-android with GNU General Public License v3.0 4 votes vote down vote up
@Inject
public PreferencesNameProvider(Application application) {
	this.preferencesName = application.getPackageName() + "_preferences";
}
 
Example 16
Source File: AppliverySdk.java    From applivery-android-sdk with Apache License 2.0 4 votes vote down vote up
private static String composeFileProviderAuthority(Application application) {
  return application.getPackageName() + ".provider";
}
 
Example 17
Source File: ToastHelper.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
ToastHelper(Toast toast, Application application) {
    super(Looper.getMainLooper());
    mToast = toast;
    mPackageName = application.getPackageName();
    mWindowHelper = WindowHelper.register(this, application);
}