1

ウィジェットのボタンがタッチされたときにトースト メッセージを表示するシンプルなアプリ ウィジェットを作成しています。私が抱えている問題は、ボタンをクリックしてもトーストが表示されないことです。実際、ボタンがタッチされたときに onReceive イベントが発生することはありません。問題はマニフェストに関係していると思われますが、問題ないようです。

私のマニフェストの関連部分は次のとおりです。

<receiver android:name=".GPSWidget" android:label="GPS Receiver">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            <action android:name="luke.app.steal.GPSWidget.ACTION_WIDGET_RECEIVER"/>
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_provider" />
</receiver>

ボタンをイベント リスナーに「接続」するコードと、GPSReceiver というクラスにある onReceive イベントを次に示します。

public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";


@Override
public void onReceive(Context context, Intent intent) {
    if(intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
        Toast.makeText(context, "Button hit", Toast.LENGTH_SHORT).show();
    }
    super.onReceive(context, intent);
}

@Override
public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
{
        RemoteViews remoteViews;

        remoteViews = new RemoteViews( context.getPackageName(), R.layout.gpswidget );
        remoteViews.setTextViewText( R.id.widgetTexts, "Click Me!");

        Intent inte = new Intent(context, lukeService.class);
        inte.setAction(ACTION_WIDGET_RECEIVER);

        PendingIntent configPendingIntent = PendingIntent.getBroadcast(context, 0, inte, 0);

        remoteViews.setOnClickPendingIntent(R.id.widgetTexts, configPendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews );
}

widgetTexts はトーストを起動するボタンですが、ボタンを押しても何も起こらないと言ったように。マニフェスト内の自分のパス luke.app.steal が間違っていると思っていましたが、同じパスは他のすべてのアクティビティで問題なく機能します。

誰でもアイデアはありますか?またはより多くの情報が必要ですか?

4

0 に答える 0