Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.content.Intent;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;

public class Main {
    private static Drawable getShortcutIcon(Context context, Intent shortcutIntent) {
        if (!shortcutIntent.hasExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)) {
            return null;
        }
        try {
            Intent.ShortcutIconResource iconRes = shortcutIntent
                    .getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            Resources appRes = context.getPackageManager().getResourcesForApplication(iconRes.packageName);
            int resId = appRes.getIdentifier(iconRes.resourceName, null, null);
            return appRes.getDrawable(resId);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}