Skip to content Skip to sidebar Skip to footer

Android: How To Get The App Name Into Our Textview

I have a DialogBox with a TextView,suppose my app is MyFriendsSecrets..I am sending a post from my app, how to get my Application name into the TextView ( example: from above pic:

Solution 1:

Run an FQL query targeting the application table. Since you working on your own App and will have access to it's App ID, constructing this query will be very easy.

Try this piece of code:

String queryApp = "SELECT display_name, namespace  FROM application WHERE app_id=284752504943219";
Bundle paramsApp = newBundle();
paramsApp.putString("method", "fql.query");
paramsApp.putString("query", queryApp);
String resultApp = Utility.mFacebook.request(paramsApp);
Log.e("APP RESULT", resultApp);

JSONArrayJAApp = newJSONArray(resultApp);

for (int i = 0; i < JAApp.length(); i++) {
    JSONObjectJOApp = JAApp.getJSONObject(i);

    String getDisplayName = JOApp.getString("display_name");
    Log.e("DISPLAY NAME", getDisplayName);
}

The display_name field in the query will return the name of the App as is shown on Facebook when posting via the App (as shown in the picture attached to the OP). Parse the result and set it to your TextView.

Since this queries the Facebook API directly, you will not have to worry about manually changing strings if you were to change the name of the App via the Facebook Developer Console.

Solution 2:

Perhaps you can find some relief w/android.content.pm.PackageManager? This will give you access to information declared within the manifest.

Solution 3:

its very simple just paste this code in string.xml

<string name="app_name">youAppName</string>

then in your javacode do like this

StringappName=this.getString(R.string.app_name);

TextViewappTextView= (TextView)findViewById(R.id.appTextView);
appTextView.setText(appName);

cheers!!!!!

Solution 4:

If you define your app name in the androidmanifest like

<application...android:label="@string/app_name"></application>

you can directly enter your app name getString(R.string.app_name) and only have 1 location, where your app name is defined

That's the name of your app... On an android device, on yourdropbox,... I assume, facebook uses the this real app name as well

Post a Comment for "Android: How To Get The App Name Into Our Textview"