Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class Main {
    public static String GetAppName(Activity act) {
        final PackageManager pm = act.getApplicationContext().getPackageManager();

        ApplicationInfo ai;
        try {
            ai = pm.getApplicationInfo(act.getPackageName(), 0);
        } catch (final NameNotFoundException e) {
            ai = null;
        }
        final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "unknown");
        return applicationName;
    }
}