2011-07-04 4 views
1

ウィジェットダイナミックに連絡先の画像を追加します。これは、この部分のために私のコードです:ウィジェット - 受信時にインテントが同じままになる

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); 
} 

これは常に最初に追加された連絡先のルックアップキーです。最初の機能で別の連絡先を追加する前に何らかの理由で意図をクリアする必要がありますか、または問題は何ですか?

答えて

2

あなたは1つだけPendingIntentを持っています。

ドキュメント引用:作成アプリケーションが後でPendingIntentの同じ種類(同じ操作、同じインテントアクション、データ、カテゴリ、コンポーネント、同じフラグ)を再取得した場合

を、それが受信しますあなたは同じ操作(getActivity())と同じIntentルーティング枚毎時間を持っているので、それはまだ

有効であれば、同じトークンを表すPendingIntentは、一つだけPendingIntentあります。

アクションをACTION_WIDGET_RECEIVERに設定するのではなく、ループ内で作成しているそれぞれに固有のものにします。

+0

ありがとうございました:) – hitzi

関連する問題