Android アプリ開発「MATRIX」

Androidアプリの開発に役立つサンプル集

ウィジェットが複数の場合のマニフェストファイルについて

複数ウィジェットマニフェストファイル

通常アプリのマニフェストファイルと、ウィジェットマニフェストファイルは中身が少し違っていますが、これは、Android Studioのプロジェクト作成機能を利用すれば自動で生成されます。

ウィジェットマニフェストファイル基本>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample.test">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<receiver android:name=".sample_widget"> //ウィジェットの場合レシーバーの設定が必要になる
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
</receiver>

</application>
</manifest>

 

複数のウィジェットをもつアプリの場合は、ウィジェットの数だけレシーバーを追加します。※マニフェストファイルは以下のようになります。

<複数ウィジェットマニフェストファイル>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample.test">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

//ウィジェット
<receiver android:name=".sample_widget1">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/mb_info1" />
</receiver>

//ウィジェット
<receiver android:name=".sample_widget2">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/mb_info2" />
</receiver>

</application>
</manifest>

 

END