2015-01-01 47 views
0

我額外添加到意圖,像這樣:如何從RemoteViewsService中的意圖訪問額外內容?

Intent adapterIntent = new Intent(context, MyRemoteViewService.class); 
adapterIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, currentWidgetID); 
adapterIntent.setData(Uri.parse(adapterIntent.toUri(Intent.URI_INTENT_SCHEME))); 
views.setRemoteAdapter(R.someLV, adapterIntent); 

在MyRemoteViewService.java,我試圖讓像小部件ID,以便:

@Override public RemoteViewsFactory onGetViewFactory(Intent intent) { 
    String currWidgetID = intent.getData().getPath(); 

我用的getData()而不是getExtras()因爲它總是返回null。

回答

0

我覺得你的意圖是將「WIDGET_ID」在widgetProvider並獲得在RemoteViewsService類一次嘗試這個

Intent.putExtra(name, value) //set the data 
intent.getIntExtra(name, defaultValue)//get data