Android獲取應(yī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)用程序名稱(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)文章
Flutter開發(fā)setState能否在build中直接調(diào)用詳解
這篇文章主要為大家介紹了Flutter開發(fā)setState能否在build中直接調(diào)用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Android使用自定義PageTransformer實(shí)現(xiàn)個(gè)性的ViewPager動(dòng)畫切換效果
這篇文章主要介紹了Android使用自定義PageTransformer實(shí)現(xiàn)個(gè)性的ViewPager切換動(dòng)畫,具有很好的參考價(jià)值,一起跟隨小編過來看看吧2018-05-05
簡(jiǎn)單實(shí)現(xiàn)Android數(shù)獨(dú)游戲
這篇文章主要教大家如何簡(jiǎn)單實(shí)現(xiàn)Android數(shù)獨(dú)游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android自定義控件實(shí)現(xiàn)九宮格解鎖功能
這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)九宮格解鎖功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
Android如何獲取子View的位置及坐標(biāo)詳解
這篇文章主要給大家介紹了關(guān)于Android如何獲取子View的位置及坐標(biāo)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Android Intent 用法全面總結(jié)及實(shí)例代碼
這篇文章主要介紹了Android Intent 用法全面總結(jié)的相關(guān)資料,并附實(shí)例代碼,需要的朋友可以參考下2016-09-09
淺談Android onTouchEvent 與 onInterceptTouchEvent的區(qū)別詳解
本篇文章小編為大家介紹,Android onTouchEvent 與 onInterceptTouchEvent的區(qū)別詳解。需要的朋友參考下2013-04-04
android開發(fā)中獲取手機(jī)分辨率大小的方法
不管是在我們的布局還是在實(shí)現(xiàn)代碼中進(jìn)行操控,我們的靈活性都不是局限于一個(gè)固定的數(shù)值,而是面對(duì)不同的手機(jī)對(duì)象都有一個(gè)適應(yīng)的數(shù)值。2013-04-04
Android基于Intent實(shí)現(xiàn)Activity之間數(shù)據(jù)傳遞的方法
這篇文章主要介紹了Android基于Intent實(shí)現(xiàn)Activity之間數(shù)據(jù)傳遞的方法,結(jié)合實(shí)例形式分析了Activity之間數(shù)據(jù)傳遞操作的相關(guān)技巧,代碼備有較為詳盡的注釋,需要的朋友可以參考下2016-11-11

