If App has ShortCut - Android android.content

Android examples for android.content:ContentResolver

Description

If App has ShortCut

Demo Code

import android.app.Application;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

public class Main {

  private static Application sApp;

  /**/*from  w ww  .  j av a  2s .  c  o  m*/
   * see if the short cut already exists
   * 
   * @param shortCutName
   *          the application name
   * @return true if exists
   */
  public static boolean hasShortCut(String shortCutName) {
    String url = "content://com.android.launcher.settings/favorites?notify=true";
    ContentResolver resolver = sApp.getContentResolver();
    Cursor cursor = resolver.query(Uri.parse(url), null, "title=? and iconPackage=?",
        new String[] { shortCutName, sApp.getPackageName() }, null);

    if (null == cursor || !cursor.moveToFirst()) {
      url = "content://com.android.launcher2.settings/favorites?notify=true";
      cursor = resolver.query(Uri.parse(url), null, "title=? and iconPackage=?",
          new String[] { shortCutName, sApp.getPackageName() }, null);
    }

    if (cursor != null) {
      boolean has = cursor.moveToFirst();
      cursor.close();
      return has;
    }
    return false;
  }

  /**
   * get package name, for example, "com.google.map"
   * 
   * @return packageName the package name
   */
  public static String getPackageName() {
    return sApp.getPackageName();
  }

}

Related Tutorials