Android獲取應(yīng)用程序名稱(chēng)(ApplicationName)示例
package cn.testapplicationname;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
/**
* Demo描述:
* 獲取應(yīng)用程序名稱(chēng)(ApplicationName)
*/
public class MainActivity extends Activity {
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init() {
mTextView = (TextView) findViewById(R.id.textView);
String applicationName = getApplicationName();
mTextView.setText("該應(yīng)用名字:"+applicationName);
}
public String getApplicationName() {
PackageManager packageManager = null;
ApplicationInfo applicationInfo = null;
try {
packageManager = getApplicationContext().getPackageManager();
applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
applicationInfo = null;
}
String applicationName =
(String) packageManager.getApplicationLabel(applicationInfo);
return applicationName;
}
}
main.xml如下:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:layout_centerInParent="true"
/>
</RelativeLayout>
相關(guān)文章
基于Android-Skin-Loader實(shí)現(xiàn)換膚效果
這篇文章主要為大家詳細(xì)介紹了基于Android-Skin-Loader實(shí)現(xiàn)換膚效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03Android實(shí)現(xiàn)微信首頁(yè)左右滑動(dòng)切換效果
這篇文章主要介紹了Android實(shí)現(xiàn)微信首頁(yè)左右滑動(dòng)切換效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Android通過(guò)代碼控制ListView上下滾動(dòng)的方法
今天小編就為大家分享一篇關(guān)于Android通過(guò)代碼控制ListView上下滾動(dòng)的方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12Android-Zxing實(shí)現(xiàn)二維碼的掃描與生成
本文主要介紹了Android中Zxing實(shí)現(xiàn)二維碼的掃描與生成的方法,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02Java4Android開(kāi)發(fā)教程(五)java的基本數(shù)據(jù)類(lèi)型特征
這篇文章主要介紹了Java4Android開(kāi)發(fā)教程的第五篇文章java的基本數(shù)據(jù)類(lèi)型特征,需要的朋友可以參考下2014-10-10Android.permission.MODIFY_PHONE_STATE權(quán)限問(wèn)題解決辦法
這篇文章主要介紹了Android.permission.MODIFY_PHONE_STATE權(quán)限問(wèn)題解決辦法的相關(guān)資料,這里提供了幾種方法幫助大家解決這種問(wèn)題,需要的朋友可以參考下2016-12-12Android studio gradle環(huán)境變量配置教程
這篇文章主要為大家詳細(xì)介紹了Android studio gradle環(huán)境變量配置教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05Android利用Intent.ACTION_SEND進(jìn)行分享
這篇文章主要介紹了Android利用Intent.ACTION_SEND進(jìn)行分享,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05Android開(kāi)發(fā)筆記之:ListView刷新順序的問(wèn)題詳解
本篇文章是對(duì)Android中ListView刷新順序的問(wèn)題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05