简体   繁体   English

如何在主屏幕上创建和删除应用程序快捷方式?

[英]How to create and remove application shortcut into home screen?

I am creating a application shortcut. 我正在创建一个应用程序快捷方式。 It's working fine. 一切正常。 But i can't remove this shortcut. 但是我无法删除此快捷方式。 How to remove my application shortcut. 如何删除我的应用程序快捷方式。 In my home screen contains lot of application shortcut. 在我的主屏幕中包含很多应用程序快捷方式。 How to remove that.. 如何删除该..
If it is possible please send information for how to remove application shortcut. 如果可能的话,请发送有关如何删除应用程序快捷方式的信息。 Otherwise if it is not possible send Reason. 否则,如果无法发送,请发送原因。 Please reply your answers and comments are valuable me. 请回复您的答案和评论对我很有价值。 Thanks. 谢谢。
My sample code is here... 我的示例代码在这里...

    Button btnShortcut = (Button) findViewById(R.id.btnCreateShortcut);
    btnShortcut.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View arg0) 
        {
            Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
            shortcutintent.putExtra("duplicate", false);
            shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
            Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
            shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
            shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , MyActivity.class));
            sendBroadcast(shortcutintent);
        }
    });

My Android Manifest.xml code is here... 我的Android Manifest.xml代码在这里...

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>

Here you go 干得好

private void deleteShortCut(Context context) {

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra("someParameter", "HelloWorld");

    Intent removeIntent = new Intent();
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName");
    removeIntent.putExtra("duplicate", false);

    removeIntent
            .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");       
    context.sendBroadcast(removeIntent);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM