DroidOS
DroidOS

Reputation: 8890

MainActivity for Cordova app

How does one go about establishing the class name for the MainActivity in a Cordova/Phonegap hybrid app? I have tried

PackageManager pm = context.getPackageManager();
ActivityInfo[] activities = pm.getPackageInfo(context.getPackageName(),PackageManager.GET_ACTIVITIES).activities;

and then attempted to retrieve the main activity name as activities[0].name which simply returns MainActivity but then latter Class.forName() with this name throws an exception

Upvotes: 0

Views: 539

Answers (1)

Gandhi
Gandhi

Reputation: 11935

I think you can make use of getLaunchIntentForPackage to get this info. The sample code is as follows:

String packageName = context.getPackageName();
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
String className = launchIntent.getComponent().getClassName();

Hope it helps.

Upvotes: 2

Related Questions