国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android獲取應用程序名稱(ApplicationName)示例

2020-04-11 12:06:25
字體:
來源:轉載
供稿:網友
MainActivity如下:
復制代碼 代碼如下:

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描述:
* 獲取應用程序名稱(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("該應用名字:"+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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 綦江县| 成都市| 杭州市| 柞水县| 方山县| 双峰县| 乌海市| 如东县| 樟树市| 巴楚县| 霸州市| 富阳市| 丰原市| 繁峙县| 北辰区| 刚察县| 曲靖市| 东丰县| 裕民县| 新竹市| 临安市| 兴安县| 无锡市| 吴旗县| 保靖县| 德保县| 丰原市| 新宾| 陈巴尔虎旗| 安丘市| 德阳市| 华蓥市| 隆昌县| 麟游县| 南溪县| 长宁区| 太和县| 陇西县| 南阳市| 丹寨县| 乳源|