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.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.lang.reflect.Field;

public class Main {
    public static Bitmap getAppIcon(Context context) {
        try {
            Class<?> drawableClass = Class.forName(context.getPackageName() + ".R$drawable");
            Field f = drawableClass.getField("ic_launcher");
            return BitmapFactory.decodeResource(context.getResources(), f.getInt(null));
        } catch (Exception e) {
            return null;
        }
    }
}