2016-10-17 7 views
0

私のAppNameを取得するサンプルコード。解像度の下AppNameをプログラマチックにAndroidで読むときに迷惑メールを取得する

public static String getApplicationName(Context mContext) { 
    String applicationName = mContext.getResources().getString(R.string.app_name); 
    if (applicationName != null) { 
     return applicationName; 
    } else { 
     return applicationName; 
    } 
} 

値フォルダ

<string name="app_name">Test App Name</string> 

注:いくつかの時間、私はAppNameは

例のためにジャンク文字を受け付けております:°は•をà¤à¤¬à¤¾à¤ ¥‹à¤¡å¤àà¥&#14

この問題を解決してください。
ありがとうございます。

+1

「if」ステートメントは無用です。 – Henry

答えて

0

あなたは以下のコードを試してみませんか?

int stringId = this.getApplicationInfo().labelRes; 
String appName = this.getString(stringId); 
Log.e(TAG, appName); 
関連する問題