2012-10-02 27 views
0

這裏就是我想要實現: 小部件3個按鈕: 1.查看文件夾 2.添加項目 3.添加項目,並啓動相機中的照片附加到項目。Android小工具和兩個不同的PendingIntents

我希望通過使用額外的意圖,達到2 & 3,只需添加一個布爾額外的「照片」,如果被點擊3號鍵是成立的,這裏是我的代碼:

Intent intent = new Intent(Intent.ACTION_INSERT); 
     intent.setData(Uri.parse("content://" 
       + NoteProviderMetaData.AUTHORITY + "/folders/" 
       + folderId)); 
intent.putExtra("photo", false); 
intent.putExtra("kind", "NO PHOTO"); 
intent.setAction(Intent.ACTION_INSERT); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 
views.setOnClickPendingIntent(R.id.imageButton2, pendingIntent); 

Intent intentFolder = new Intent(Intent.ACTION_VIEW); 
     intentFolder.setData(Uri.parse("content://" 
       + NoteProviderMetaData.AUTHORITY + "/folders/" 
       + folderId + "/notes")); 
PendingIntent pendingIntentFolder = PendingIntent.getActivity(this, 0, intentFolder, 0); 
Intent intentPhoto = new Intent(Intent.ACTION_INSERT); 
intentPhoto.setData(Uri.parse("content://" 
     + NoteProviderMetaData.AUTHORITY + "/folders/" 
       + folderId)); 
intentPhoto.putExtra("photo", true); 
intentPhoto.putExtra("kind", "PHOTO"); 
intentPhoto.setAction(Intent.ACTION_INSERT); 
PendingIntent pendingIntentPhoto = PendingIntent.getActivity(this, 0, intentPhoto, 0); 
views.setOnClickPendingIntent(R.id.imageButton3, pendingIntentPhoto); 

問題是在創建pendingIntentPhoto之後立即生成的,我的pendingIntent附加項被新值覆蓋,並且我總是在我的活動中獲得truePHOTO值。 pendingFolder意圖的作品,所以我想它會很好,只是使用另一個意圖行動,但我想了解這個PendingIntent的事情是如何工作的。

回答

1

我能做到這一點使用這種方法的無證功能:

public static PendingIntent getActivity (Context context, int requestCode, Intent intent, int flags)

從文檔: requestCode Private request code for the sender (currently not used).

顯然,這個代碼目前以某種方式使用。爲這個方法調用提供不同的requestCodes允許我爲同一個小部件創建不同的PendingIntents

+0

是的,這也適用於我,謝謝你的提示。 – kcoppock