アプリのパッケージ名をプログラムから取得する
アプリのパッケージ名を取得したい
アプリのパッケージ名をプログラムから取得する場合は、android.content.Contextクラスの getPackageName() メソッドを使います。
abstract String getPackageName()
(Return the name of this application's package.)
Android Studioで、一つのプロジェクトから複数のアプリを作成する方法 - Android Studioでアプリ開発!で作ったアプリに TextView(textView3) を追加して表示してみたいと思います。パッケージ名は com.example.Switching.free です。
javaのソース
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); TextView textView = (TextView) findViewById(R.id.textView3); textView.setText(getPackageName()); }
実行結果
ちゃんとパッケージ名が表示されました。
Android StudioではじめるAndroidプログラミング入門
- 作者: 掌田津耶乃
- 出版社/メーカー: 秀和システム
- 発売日: 2014/04
- メディア: 単行本
- この商品を含むブログ (1件) を見る
- 作者: 柴田文彦,川口仁
- 出版社/メーカー: インプレス
- 発売日: 2014/01/16
- メディア: Kindle版
- この商品を含むブログ (1件) を見る