我想创建快捷方式 [英] I want create shortcut

查看:116
本文介绍了我想创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建快捷方式打开应用程序时,但问题是,创建一个快捷方式总是开放的应用程序,如果我打开然后应用程序20时创建的快捷方式20

我需要的只是创建一个快捷方式,首开不

 保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    ShortcutIcon();

   }




私人无效ShortcutIcon(){

    意图shortcutIntent =新的意图(getApplicationContext(),Main.class);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    意图addIntent =新意图();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,WhatsApp的Imagenes);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.icono));
    addIntent.setAction(com.android.launcher.action.INSTALL_SHORTCUT);
    。getApplicationContext()sendBroadcast(addIntent);
}
 

解决方案

在pre-JB的Andr​​oid版本,你可以试试这个:

  addIntent.putExtra(重复,假);
 

另外,你可以卸载并重新安装快捷方式:

  intent.setAction(com.android.launcher.action.UNINSTALL_SHORTCUT);
。getApplicationContext()sendBroadcast(意向);

intent.setAction(com.android.launcher.action.INSTALL_SHORTCUT);
。getApplicationContext()sendBroadcast(意向);
 

更多信息<一个href="http://codinggeekorg.word$p$pss.com/2011/01/31/android-home-screen-shortcuts-part-iii-remove-shortcuts/">here.

I create shortcut when open the app but the problem is that create a shortcut always that open the app if I open the app 20 time then creates 20 shortcuts

I need that only create one shortcut the first open not more

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ShortcutIcon();

   }




private void ShortcutIcon(){

    Intent shortcutIntent = new Intent(getApplicationContext(), Main.class);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Whatsapp Imagenes");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icono));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);
}

解决方案

On pre-JB android versions, you can try this:

addIntent.putExtra("duplicate", false);

Otherwise, you can just uninstall and reinstall the shortcut:

intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);

intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);

More info here.

这篇关于我想创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆