2012-03-19 29 views
0

ショートカットを作成中に "ショートカットが作成されました"のようなトーストを受け、その後 "ショートカットはすでに存在します"。今私の疑問はアンドロイドのショートカットが既に存在するかどうかを知る方法

  1. ショートカットがすでに存在するかどうかを検出できます。

  2. 「ショートカットが作成されました」「ショートカットが既に存在します」などのトーストメッセージを無効にするにはどうすればよいですか。トーストを表示するLauncherModel(com.android)apiを確認しましたが、WhatsAppのようなアプリはトーストを表示しません。

+0

[ホームスクリーンのショートカットが存在するかどうかを判断する方法](http://stackoverflow.com/questions/9322165/how-to-determine-if-a-home-screen-shortcut-exists) –

答えて

5

ショートカットを作成するときに、あなたが

このようなaddIntent.putExtra(、 "重複" true)を追加することができます。

(作成するときに、その後、でもそれが存在する重複したショートカットを作成)

ex. 

public void createShortcut(String url,,String classname,String shortcutName , String type) 
    {   
     Intent shortcutIntent = new Intent();  
     shortcutIntent.setAction(Intent.ACTION_VIEW); 

     if(type.equalsIgnoreCase("web")) { 

      Uri uri = Uri.parse(url); 
      shortcutIntent.setData(uri); 
     } 
     else if (type.equalsIgnoreCase("app")) { 


      shortcutIntent.setClassName(url,classname); 
     } 

     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, shortcutName); 
     addIntent.putExtra("duplicate", true); 

     addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.ic_launcher); 

     addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
     sendBroadcast(addIntent); 
//  Toast mToast = Toast.makeText(this, "shortcut created", Toast.LENGTH_SHORT); 
//  mToast.show(); 

    } 
+0

これは役に立たない。ショートカットがすでに存在する場合は、「ショートカットはすでに存在します」というトーストが表示されます。 –

+1

しかし、「ショートカットは既に存在しています」というたびに、 –

0

私はまた、uのように同じ問題を抱えている、私はショートカットを削除nはそれを再度作成したいが、それが出てくる続けてきました「ショートカットxxxはすでに存在しています」というメッセージが表示されます。

連絡先の名前を変更しようとしましたが動作します。

1

あなたのアドオンのショートカット法の物乞いでは(サーバDBから例のショートカット名やidに)あなたのショートカットに

をuniqie IDを使用する必要があります。

if (loadBoolean(context, String.valueOf(shortcutid))) return; 

sendbroadcast方法の後に呼び出す必要があります。

をセーブとロード方法の
saveBoolean(context, true, String.valueOf(shortcutid)); 

コード:

protected static boolean saveBoolean(Context context, boolean value, String tag) { 
     try { 
      PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(tag, value).apply(); 
     } catch (Exception e) { 
      return false; 
     } 
     return true; 
    } 

    protected static boolean loadBoolean(Context context, String tag) { 
     boolean value = false; 
     try { 
      value = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(tag, false); 
     } catch (Exception ignored) {} 
     return value; 
    } 
関連する問題