Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.ContentResolver;
import android.content.Context;

import android.database.Cursor;

import android.net.Uri;

public class Main {
    public static boolean checkShortCut(Context context, String appName) {
        boolean hasShortCut = false;
        try {
            ContentResolver cr = context.getContentResolver();
            final String AUTHORITY1 = "com.android.launcher.settings";
            final String AUTHORITY2 = "com.android.launcher2.settings";
            String contentUri = "";
            if (android.os.Build.VERSION.SDK_INT < 8) {
                contentUri = "content://" + AUTHORITY1 + "/favorites?notify=true";
            } else {
                contentUri = "content://" + AUTHORITY2 + "/favorites?notify=true";
            }
            final Uri CONTENT_URI = Uri.parse(contentUri);
            Cursor c = cr.query(CONTENT_URI, new String[] { "title", "iconResource" }, "title=?",
                    new String[] { appName }, null);
            if (c != null && c.getCount() > 0) {
                hasShortCut = true;
            }
        } catch (Exception e) {
        }
        return hasShortCut;
    }
}