package com.backfire.doudizhu.lobby;
import net.yeeyo.doudizhu.feiyu.R;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
import android.database.Cursor;
import android.net.Uri;

public class ShortCut {
	public static boolean hasShortcut(Context context)
	{
        boolean isInstallShortcut = false;
        final ContentResolver cr = context.getContentResolver();
        final String AUTHORITY ="com.android.launcher.settings";
        final Uri CONTENT_URI = Uri.parse("content://" +AUTHORITY + "/favorites?notify=true");
        Cursor c = cr.query(CONTENT_URI,new String[] {"title","iconResource" },"title=?",
        new String[] {context.getString(R.string.app_name).trim()}, null);
        if(c!=null && c.getCount()>0){
            isInstallShortcut = true ;
        }
        return isInstallShortcut ;
    }
	public static void addShortcut(Context context){  
        Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");  
               
        //快捷方式的名称  
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));  
        shortcut.putExtra("duplicate", false); //不允许重复创建  
        Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
        shortcutIntent.setClassName(context, context.getClass().getName());
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
//        shortcut.setAction("android.intent.action.MAIN");  
//        shortcut.addCategory("android.intent.category.LAUNCHER");  
 
        //快捷方式的图标  
        ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(context, R.drawable.icon);  
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);  
               
        context.sendBroadcast(shortcut);  
    }
}
