Is it possible to find the launch class name programmatically? For example, if the manifest is as below:

    <activity android:name=".MyActivity">
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

The output will be MyActivity.class.

1 Answer 1


You can use xml.el to handle XML data. The following function should provide you with the class names you are looking for:

(require 'xml)
(require 'seq)

(defun activity-from-manifest (manifest)
  (seq-filter 'identity
              (mapcar (lambda (node)
                        (let ((name (xml-get-attribute-or-nil node 'android:name)))
                          (and name (substring (concat name ".class") 1))))
                      (xml-get-children (car manifest) 'activity))))

You can obtain the parsed XML data to pass into the function either from an XML file or from the region of a buffer as follows:

(activity-from-manifest (xml-parse-file "AndroidManifest.xml"))
(activity-from-manifest (xml-parse-region))

Note that this code works for the XML structure you have shown. If your data is wrapped inside a manifest element like in typical manifest files then you would need to use

 (car (xml-get-children (car manifest) 'application))

instead of (xml-get-children (car manifest) 'activity).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.