ウィジェットダイナミックに連絡先の画像を追加します。これは、この部分のために私のコードです:ウィジェット - 受信時にインテントが同じままになる
for (int x = 0; x < this.appWidgetIds.length; x++){
int id = this.appWidgetIds[x];
RemoteViews rv = new RemoteViews(this.context.getPackageName(), R.layout.widget);
for (int i = 0; i < maxCount; i++){
String lookupKey = sortedItems.get(i).getLookupKey();
Tools.ToLog("LOOKUPKEY=" + lookupKey);
Bitmap bmp = Contact.getContactPicture(this.context, lookupKey);
if (bmp != null){
Intent intent = new Intent(context, ContactsWidget.class);
intent.setAction(ACTION_WIDGET_RECEIVER);
intent.putExtra(ITENT_LOOKUPKEY, lookupKey);
Tools.ToLog("LOOKUPKEY - IDENT=" + intent.getStringExtra(ITENT_LOOKUPKEY));
RemoteViews itemView = new RemoteViews(this.context.getPackageName(), R.layout.widget_itemview);
itemView.setImageViewBitmap(R.id.widget_ImageView, bmp);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(this.context, 0, intent, 0);
itemView.setOnClickPendingIntent(R.id.widget_ImageView, actionPendingIntent);
rv.addView(R.id.widgetContainer, itemView);
}
}
appWidgetManager.updateAppWidget(id, rv);
}
(変数lookupKey == intent.getStringExtra(ITENT_LOOKUPKEY))私は、ログ上の意図からLookupkeyとlookupkeyをテストし、それがこちら側に動作します。連絡先の画像をクリックしたので、今私が意図を受け取ったとき、意図の余分な情報は常に同じです。私がクリックした連絡先の写真のどれに関係なく。これは受信コードです
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
String lookupKey = intent.getStringExtra(ITENT_LOOKUPKEY);
Toast.makeText(context, "Lookup Key: " + lookupKey, Toast.LENGTH_SHORT).show();
//Contact.openContact(this.context, lookupKey);
}
super.onReceive(context, intent);
}
これは常に最初に追加された連絡先のルックアップキーです。最初の機能で別の連絡先を追加する前に何らかの理由で意図をクリアする必要がありますか、または問題は何ですか?
ありがとうございました:) – hitzi