에서 사용자 의도를 수신하지안드로이드 IntentReceiver는 (이것은 내 첫 번째 SE의 질문은 지금까지이지만, 내가 자바와 안드로이드 학습 주위 bumbled 것 같은 환상적인 커뮤니티의를 위해이 사이트에 크게 의존했습니다!) WidgetProvider
I을 (잠시 동안) 양면 주사위로 작동하는 버튼이 하나 뿐인 Android 위젯을 만들 수 있습니다. 결국이 위젯은 모든 주요 RPG 주사위 크기 (d6, d8, d20 등)를 지원하지만 지금은 의도/수신 시스템을 작동 시키려고합니다.
현재 위젯의 d2 버튼을 눌렀을 때 아무런 변화가 없습니다. 지금까지 사용자 정의 인 텐트를 디버깅하여 알 수있는 것처럼, IntentReceiver의 onReceive는 절대로이를 포착하지 않습니다. 당신이 제공 할 수있는 모든 도움을 많이 주시면 감사하겠습니다! 여기
내 WidgetProvider입니다 :public class MyWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
remoteViews.setOnClickPendingIntent(R.id.btnReset, buildButtonPendingIntent(context));
Log.e(null, "Setup remote views & Onclick");
Toast.makeText(context, "Test", Toast.LENGTH_SHORT).show();
pushWidgetUpdate(context, remoteViews);
}
public static PendingIntent buildButtonPendingIntent(Context context) {
Intent intent = new Intent();
intent.setAction("ca.sulli.rpgdicewidget.intent.action.D2");
Log.e(null, "Setting new ButtonPendingIntent");
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
public static void pushWidgetUpdate(Context context, RemoteViews remoteViews) {
Log.e(null, "Updating widget!");
ComponentName myWidget = new ComponentName(context, MyWidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(myWidget, remoteViews);
}
}
그리고 여기 내 수신기 :
public class MyWidgetIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(null,"Checking intent by receiver");
if(intent.getAction().equals("ca.sulli.rpgdicewidget.intent.action.D2")){
Log.e(null,"Correct intent received!");
updateWidgetPictureAndButtonListener(context);
}
}
private void updateWidgetPictureAndButtonListener(Context context) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
Log.e(null,"Updating text since the intent was received!");
remoteViews.setTextViewText(R.id.txtResult, "Intent Received! ");
remoteViews.setOnClickPendingIntent(R.id.btnD2, MyWidgetProvider.buildButtonPendingIntent(context));
MyWidgetProvider.pushWidgetUpdate(context.getApplicationContext(), remoteViews);
}
}
그리고 완성 '을 위해
, 내 매니페스트 :<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.sulli.rpgdicewidget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="MyWidgetProvider" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="ca.sulli.rpgdicewidget.intent.action.D2" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
</receiver>
</application>
</manifest>
그리고 appwidget-제공 :
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="200dp" android:minHeight="70dp" android:initialLayout="@layout/main" android:updatePeriodMillis="30000">
</appwidget-provider>
많은 도움을 주신 데 대해 감사 드리며이 커뮤니티가 이미 많은 도움을 주신 데 대해 감사드립니다.
답장을 보내 주셔서 감사합니다. 나는 그것을 고려하지 않았다. 그래서 나는 그것을 시험해 볼 것이다. –