Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;

public class Main {

    public static boolean hasShortcut(Context cx) {
        boolean result = false;
        String title = null;
        try {
            final PackageManager pm = cx.getPackageManager();
            title = pm.getApplicationLabel(pm.getApplicationInfo(cx.getPackageName(), PackageManager.GET_META_DATA))
                    .toString();
        } catch (Exception e) {
            e.printStackTrace();
        }

        final String AUTHORITY;
        if (android.os.Build.VERSION.SDK_INT < 8) {
            AUTHORITY = "com.android.launcher.settings";
        } else {
            AUTHORITY = "com.android.launcher2.settings";
        }
        final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
        final Cursor c = cx.getContentResolver().query(CONTENT_URI, null, "title=?", new String[] { title }, null);
        if (c != null && c.moveToFirst()) {
            c.close();
            result = true;
        }
        return result;
    }
}