Java Code Examples for android.app.Activity#setIntent()

The following examples show how to use android.app.Activity#setIntent() . 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: HookedInstrumentation.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
public Activity newActivity(ClassLoader cl, String className, Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    if (Constants.DEBUG) Log.e(TAG, "newActivity");

    if (mPluginManager.hookToPluginActivity(intent)) {
        String targetClassName = intent.getComponent().getClassName();
        PluginApp pluginApp = mPluginManager.getLoadedPluginApk();
        Activity activity = mBase.newActivity(pluginApp.mClassLoader, targetClassName, intent);
        activity.setIntent(intent);
        ReflectUtil.setField(ContextThemeWrapper.class, activity, Constants.FIELD_RESOURCES, pluginApp.mResources);
        return activity;
    }

    if (Constants.DEBUG) Log.e(TAG, "super.newActivity(...)");
    return super.newActivity(cl, className, intent);
}
 
Example 2
Source File: NeptuneInstrument.java    From Neptune with Apache License 2.0 5 votes vote down vote up
@Override
public Activity newActivity(ClassLoader cl, String className, Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    if (className.startsWith(ComponentFinder.DEFAULT_ACTIVITY_PROXY_PREFIX)) {
        // 插件代理Activity,替换回插件真实的Activity
        String[] result = IntentUtils.parsePkgAndClsFromIntent(intent);
        String packageName = result[0];
        String targetClass = result[1];

        PluginDebugLog.runtimeLog(TAG, "newActivity: " + className + ", targetClass: " + targetClass);
        if (!TextUtils.isEmpty(packageName)) {
            PluginLoadedApk loadedApk = PluginManager.getPluginLoadedApkByPkgName(packageName);
            tryInitPluginApplication(loadedApk);
            if (loadedApk != null && !TextUtils.isEmpty(targetClass)) {
                Activity activity = mHostInstr.newActivity(loadedApk.getPluginClassLoader(), targetClass, intent);
                activity.setIntent(intent);

                if (!dispatchToBaseActivity(activity)) {
                    // 这里需要替换Resources,是因为ContextThemeWrapper会缓存一个Resource对象,而在Activity#attach()和
                    // Activity#onCreate()之间,系统会调用Activity#setTheme()初始化主题,Android 4.1+
                    ReflectionUtils.on(activity).setNoException("mResources", loadedApk.getPluginResource());
                }

                return activity;
            } else if (loadedApk == null && enableRecoveryMode(packageName)) {
                // loadedApk为空,可能是正在恢复进程,当前插件配置支持进程恢复,则跳转到 RecoveryActivity
                // 否则还是跳转InstrActivityProxy1
                return mHostInstr.newActivity(cl, mRecoveryHelper.selectRecoveryActivity(className), intent);
            }
        }
    }
    return mHostInstr.newActivity(cl, className, intent);
}
 
Example 3
Source File: VAInstrumentation.java    From VirtualAPK with Apache License 2.0 5 votes vote down vote up
protected void injectActivity(Activity activity) {
    final Intent intent = activity.getIntent();
    if (PluginUtil.isIntentFromPlugin(intent)) {
        Context base = activity.getBaseContext();
        try {
            LoadedPlugin plugin = this.mPluginManager.getLoadedPlugin(intent);
            Reflector.with(base).field("mResources").set(plugin.getResources());
            Reflector reflector = Reflector.with(activity);
            reflector.field("mBase").set(plugin.createPluginContext(activity.getBaseContext()));
            reflector.field("mApplication").set(plugin.getApplication());

            // set screenOrientation
            ActivityInfo activityInfo = plugin.getActivityInfo(PluginUtil.getComponent(intent));
            if (activityInfo.screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
                activity.setRequestedOrientation(activityInfo.screenOrientation);
            }

            // for native activity
            ComponentName component = PluginUtil.getComponent(intent);
            Intent wrapperIntent = new Intent(intent);
            wrapperIntent.setClassName(component.getPackageName(), component.getClassName());
            activity.setIntent(wrapperIntent);
            
        } catch (Exception e) {
            Log.w(TAG, e);
        }
    }
}
 
Example 4
Source File: VAInstrumentation.java    From VirtualAPK with Apache License 2.0 4 votes vote down vote up
@Override
public Activity newActivity(ClassLoader cl, String className, Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    try {
        cl.loadClass(className);
        Log.i(TAG, String.format("newActivity[%s]", className));
        
    } catch (ClassNotFoundException e) {
        ComponentName component = PluginUtil.getComponent(intent);
        
        if (component == null) {
            return newActivity(mBase.newActivity(cl, className, intent));
        }

        String targetClassName = component.getClassName();
        Log.i(TAG, String.format("newActivity[%s : %s/%s]", className, component.getPackageName(), targetClassName));

        LoadedPlugin plugin = this.mPluginManager.getLoadedPlugin(component);

        if (plugin == null) {
            // Not found then goto stub activity.
            boolean debuggable = false;
            try {
                Context context = this.mPluginManager.getHostContext();
                debuggable = (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
            } catch (Throwable ex) {
    
            }

            if (debuggable) {
                throw new ActivityNotFoundException("error intent: " + intent.toURI());
            }
            
            Log.i(TAG, "Not found. starting the stub activity: " + StubActivity.class);
            return newActivity(mBase.newActivity(cl, StubActivity.class.getName(), intent));
        }
        
        Activity activity = mBase.newActivity(plugin.getClassLoader(), targetClassName, intent);
        activity.setIntent(intent);

        // for 4.1+
        Reflector.QuietReflector.with(activity).field("mResources").set(plugin.getResources());

        return newActivity(activity);
    }

    return newActivity(mBase.newActivity(cl, className, intent));
}