2012-04-12 3 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

[이 하나]를 확인 했습니까? (http://stackoverflow.com/questions/6337431/android-create-shortcuts-on-the-home-screen) –

답변

2

설치 후 자동으로 실행되는 코드가 없으므로 설치 후 바로 가기를 자동으로 만들 수 없습니다.

+0

첫 출시 이후 가능합니까? – thecr0w

+1

그러면 Google Play 스토어의 앱에 대해 뭐라고 말하면 자동으로 바로 가기를 만듭니다. –

+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입니다 만들 수있는 경우가 여기에 패키지 이름 app 해당 당신이 통과 바로 가기를 만들 선택 모든 응용 프로그램입니다.

관련 문제