Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.*;
import android.content.pm.*;

public class Main {
    public static int getAppIconResId(Context app) {
        PackageManager pm = app.getPackageManager();
        String packageName = app.getPackageName();
        try {
            ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
            return ai.icon;
        } catch (Exception e) {
            e.printStackTrace();
            try {
                return app.getResources().getIdentifier("sym_def_app_icon", "mipmap", "android");
            } catch (Exception e1) {
                e1.printStackTrace();
                return 0;
            }
        }
    }
}