0

From my Junit test code, how do I access the value of android:targetPackage in Manifest within the Junit test app?

I am trying to extract "com.mycompany.mytestapp".

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.mycompany.mytestapp" />
...  
</manifest>
4

2 回答 2

0

首先PackageManager.getPackageInfo(String packageName, int flags)与 flag 一起 使用GET_INSTRUMENTATION

这将为您提供一个PackageInfo对象,该对象具有一个名为instrumentation There 您将找到任何 <instrumentation> 标记信息的字段,包括targetPackage

于 2013-09-12T20:15:30.803 回答
0

现在工作。做了以下。谢谢!

PackageInfo packageInfo = inst.getContext().getPackageManager().getPackageInfo(inst.getContext().getPackageName(), PackageManager.GET_INSTRUMENTATION); 字符串 targetPackageName = packageInfo.instrumentation[0].targetPackage;

于 2013-09-12T22:23:55.327 回答