Get ActivityInfo for an Activity Instance

I have an Activity instance in a helper class, and I'm trying to get attributes from its entry in a file AndroidManifest.xml.

I can get a list of all instances ActivityInfo, but how do I target a specific application?

The activity instance is not in the same package as the helper class and is not defined in the same manifest (the helper class is a library included in the activity application project).

What I still have:

Activity activity = //the instance
String applicationPackage = activity.getApplicationInfo().packageName;
PackageInfo info = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
for (ActivityInfo activityInfo : info.activities) {
    if (/* activityInfo applies to our activity instance */) {
        return activityInfo.someProperty;
    }
}
+3
source share
2 answers

My understanding of your question: you need to get information about a specific Activity in your application.

getPackageInfo , , . getActivityInfo, Activity ComponentName, ex: com.example.myapp/com.example.myapp.myactivity

PackageManager Docs

+4

ActivityInfo info = getPackageManager(). getActivityInfo (getComponentName(), 0);

0

All Articles