意向在Espresso测试APK中解决了不同的过程(无源代码)

时间:2019-04-17 06:56:17

标签: android android-espresso

我正在尝试通过检测对象启动(另一个APK)活动。 我能够在classToInvestigate对象中拉出该APK的类,但是无法通过启动活动

instrumentation.startActivitySync(startIntent2);

下面是通过检测对象启动活动的完整代码。

private Object xyz(String packageName, String className){
        Object plugin = null;
        try {
            PackageManager packageManager = context.getPackageManager();
            ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
            DexFile df = new DexFile(appInfo.sourceDir);
            ClassLoader cl = context.getClassLoader();
            Class classToInvestigate = df.loadClass(className, cl);

            Intent startIntent2 = new Intent(Intent.ACTION_MAIN);
            startIntent2.setClassName(packageName, classToInvestigate.getName());
            startIntent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            instrumentation.startActivitySync(startIntent2);
            instrumentation.waitForIdleSync();


            plugin = classToInvestigate.newInstance();


        } catch (Exception e) {
            System.out.println("EXCEPTION");
        }
        finally{
            return plugin;
        }
    }

特别是在instrumentation.startActivitySync(startIntent2);行,Android Studio会引发错误

java.lang.RuntimeException: Intent in process com.main.apk resolved to different process com.abc.xyz Intent

0 个答案:

没有答案