2012-04-12 15 views
0

インストール後に自動的にショートカットを作成する方法は?以下のコードは機能しません!インストール後に自動的にショートカットを作成する方法

private void createShortCut() { 
    Intent intent = new Intent(ACTION_INSTALL_SHORTCUT); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); 
    intent.putExtra("duplicate", false); 
    Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//icon 
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , MainActivity.class)); 

    setResult(RESULT_OK, intent); 
    sendBroadcast(intent); 
} 
+0

あなたは[この1つ]をチェックしましたか?(http://stackoverflow.com/questions/6337431/android-create-shortcuts-on-the-home-screen) –

答えて

2

インストール後にコードが自動的に実行されることはないため、インストール後に自動的にショートカットを作成することはできません。

+0

初回起動後は可能ですか? – thecr0w

+1

次に、Googleプレイストアのアプリについて言うと、自動的にショートカットが作成されます。 –

+0

@JayVyas:Playストアアプリのインストーラーがアプリをインストールするのではなく、インストールしています。 – CommonsWare

0

はい、アプリやサードパーティのアプリやシステムアプリであれば、ショートカットを作成することは非常に可能です。このサンプルコードに従ってください。

try 
     { 
      for (int i = 0; i < packageNameArray.length; i++) 
      { 
       Intent shortcutIntent = Util.makeIntent(MyPreference.getAction(context), MyPreference.getCategory(context), packageNameArray[i], ActivityNameArray[i]); 
       Bitmap shortcutIcon2 = Util.confleteBitmap((UtilityClass.StringToBitMap(IconArray[i])), BitmapFactory.decodeResource(context.getResources(), R.drawable.shortcut_mark)); 
       data.putExtra("android.intent.extra.shortcut.INTENT", shortcutIntent); 
       data.putExtra("android.intent.extra.shortcut.ICON", shortcutIcon2); 
       data.putExtra("android.intent.extra.shortcut.NAME", AppNameArray[i]); 
       //uninstalling shortcut to remove duplicacy 
       Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); 
       intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
       intent.putExtra("duplicate", false); 
       intent.putExtras(data); 
       context.sendBroadcast(intent); 
      } 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 

ここpackagenamearrayはあなただけでアプリのショートカットが activitynamearrayが選択されたアプリのactivitynameで作成する必要がある場合は、ここでパッケージ名をアプリあなたが合格ショートカットを作成することを選択するすべてのアプリケーションです。

関連する問題