Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Mozilla Public License 

import android.app.Activity;

import android.content.pm.ApplicationInfo;

import android.content.pm.PackageManager;

public class Main {
    /**
     * Get application name.
     *
     * @param activity
     *          current activity.
     * @return application name. This equals to the app title that appears in
     *         settings->application.
     * @throws android.content.pm.PackageManager.NameNotFoundException
     */
    public static String getAppName(Activity activity) throws PackageManager.NameNotFoundException {
        PackageManager pm = activity.getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(activity.getPackageName(), 0);
        return pm.getApplicationLabel(appInfo).toString();
    }
}