2012-11-13 4 views
1

Android에서 내 자신의 실행 프로그램을 만들려고하는데 android sample Home을 사용했습니다.Android, 실행기 및 즐겨 찾는 응용 프로그램

샘플은 쉽지 않으며 거의 ​​설명서가 없으며 분명한 답변이없는 포럼에 대한 질문이 거의 없습니다.

내 런처에 자주 사용하는 응용 프로그램을 추가하려고했지만 응용 프로그램이 존재하지 않는 xml 파일 "etc/favorites.xml"을 검색하고 있습니다.

프로그래밍 방식으로이 파일을 만들어야합니까? 그리고이 파일은 어떻게 생겼습니까?

답변

1

해결책을 찾았습니다.

<?xml version="1.0" encoding="UTF-8"?> 

<favorites> 
    <favorite package="com.android.email" class="com.android.email.activity.Welcome"/> 
    <favorite package="com.android.browser" class="com.android.browser.BrowserActivity"/> 
</favorites> 

을 그리고 샘플 코드, 내가 방법 "bindFavorites을"편집 (내가 사용하는 XML 파일을로드 :

나는 "자산"을 작성 폴더에있는 파일 "favorites.xml"를 생성

/** 
* Refreshes the favorite applications stacked over the all apps button. 
* The number of favorites depends on the user. 
*/ 
private void bindFavorites(boolean isLaunching) { 
    if (!isLaunching || mFavorites == null) { 

     if (mFavorites == null) { 
      mFavorites = new LinkedList<ApplicationInfo>(); 
     } else { 
      mFavorites.clear(); 
     }   

     InputStream is = null; 
     try { 
      is = getAssets().open("favorites.xml"); 
     } catch (IOException e) { 
      Log.e(LOG_TAG, "Couldn't find or open favorites file "); 
      return; 
     } 

     final Intent intent = new Intent(Intent.ACTION_MAIN, null); 
     intent.addCategory(Intent.CATEGORY_LAUNCHER); 

     final PackageManager packageManager = getPackageManager(); 

     try { 
      final XmlPullParser parser = Xml.newPullParser(); 
      parser.setInput(is, "UTF-8"); 

      beginDocument(parser, TAG_FAVORITES); 

      ApplicationInfo application; 

      while (true) { 
       nextElement(parser); 
       String name = parser.getName(); 
       if (!TAG_FAVORITE.equals(name)) { 
        break; 
       } 

       final String favoritePackage = parser.getAttributeValue(null, TAG_PACKAGE); 
       final String favoriteClass = parser.getAttributeValue(null, TAG_CLASS); 

       final ComponentName cn = new ComponentName(favoritePackage, favoriteClass); 
       intent.setComponent(cn); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

       application = getApplicationInfo(packageManager, intent); 
       if (application != null) { 
        application.intent = intent; 
        mFavorites.addFirst(application); 
       } 
      } 
     } catch (XmlPullParserException e) { 
      Log.w(LOG_TAG, "Got exception parsing favorites.", e); 
     } catch (IOException e) { 
      Log.w(LOG_TAG, "Got exception parsing favorites.", e); 
     } 
    } 

    mApplicationsStack.setFavorites(mFavorites); 
} 

을 그리고 그것은 작동하지만 난 여전히 xml 파일에 우리는 클래스 값을 설정해야하고 내가이 정보를 찾을 수있는 곳 모르겠어, 도움이 필요 : 대신) FileReader와의의 InputStream. 보시다시피,이 값은 응용 프로그램에 따라 다릅니다. 여기에 몇 가지 값을 발견 : http://forum.xda-developers.com/showthread.php?t=836719 하지만 내 자신의 티타늄 애플 리케이션과 나는 어떤 클래스 값이 필요하지 모르겠다.

+0

다시 게시글을 잊어 버리고 원하는 모든 것을 찾았습니다. 이것이 자신의 응용 프로그램이라면 쉽습니다. 와 같이 packageName "com.example.yourApp"와 className "MainActivity"만 있으면됩니다. – Aximem

관련 문제