簡體   English   中英

如何在主屏幕中檢測快捷方式

[英]How to detect shortcut in Home screen

我有一個應用程序,允許您在主屏幕中創建“快捷方式”。 但我可以檢測到“快捷方式”是否已經存在,我不必再次創建它。 謝謝。

我遇到了同樣的問題。 我不認為它可能會告訴你它是否存在,但我認為我使用的也適合你。

只需在添加快捷方式之前卸載快捷方式!

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

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

只需確保將以下內容添加到清單文件中即可。

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

我不知道是否可以檢測到快捷方式,但是不是卸載然后安裝,而是可以使用Extra字段作為

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
...
intent.putExtra("duplicate", false);
...
sendBroadcast(intent);

我想我找到了一個很好的方法來確保快捷方式不會多次添加,並且Toast消息也會消失。 創建一個int或boolean(我用了一個int)並將以下內容放在onResume中:

if(shortcut != 1) //or shortcut == true
{
    ...(shortcut code)...
    shortcut = 1;
    savePref("shortcut", shortcut); //overriding method to save int's or booleans
}

如果用戶刪除用戶數據,那么它將添加另一個快捷方式到主屏幕,但我可以忍受,因為大多數用戶無論如何都不刪除那種東西,除非他們正在卸載應用程序。 希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM