2014-02-22 4 views
0

이것은 내 홈 화면에 바로 가기를 만드는 코드입니다. 아무 것도 잘 작동하지만 홈 화면에서 바로 가기를 클릭하면 "설치되지 않은 앱"이 표시됩니다. 나는 그것을 수리하고 싶다.앱이 설치되지 않았습니다.

코드

appPref = getSharedPreferences("isFirstTime", 0); 
isFirstTime = appPref.getBoolean("isFirstTime", true); 

if (isFirstTime) { 
    // Create explicit intent which will be used to call Our application 
    // when some one clicked on short cut 
    Intent shortcutIntent = new Intent(getApplicationContext(), 
      MainActivity.class); 
    shortcutIntent.setAction(Intent.ACTION_MAIN); 
    Intent intent = new Intent(); 

    // Create Implicit intent and assign Shortcut Application Name, Icon 
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Get Quote"); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 
      Intent.ShortcutIconResource.fromContext(
        getApplicationContext(), R.drawable.ic_launcher)); 
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    getApplicationContext().sendBroadcast(intent); 

    // Set preference to inform that we have created shortcut on 
    // Homescreen 
    SharedPreferences.Editor editor = appPref.edit(); 
    editor.putBoolean("isFirstTime", false); 
    editor.commit(); 

} 

}

답변

0

당신은 this (활동)을 사용하여,의 ApplicationContext를 사용하지 않아도 괜찮을 것

나는이 이론을 테스트,하지만하지 않은 귀하의 문제가 Intent intent = new Intent(); 일 것 같아서 대신 PendingIntent를 사용해보십시오

귀하의 shortc 또한 utIntent는 앱 (또는 스키마 유형) 또는 열려고하는 클래스와 관련된 작업을 수행해야합니다. 제공하신 작업은 일반적이며 문제를 유발할 수 있습니다 (의도를 만들 때 전달한 작업을 무시하는 설정은 여기에서 필요하지 않습니다).

이 기능을 사용하지 않고도 바로 가기를 만드는 것은 좋지 않습니다. 사용자가 악성 코드로 제거 할만큼 충분히 성가 시게 할 수 있습니다.

관련 문제