2017-05-10 73 views
0

我創建了一個應用程序,該應用程序應該打開android小部件屏幕並選擇特定的小部件。 我設法打開窗口小部件的屏幕,但不能從顯示的列表中選擇一個特定的部件,這是我使用的代碼:打開android小部件

public void sendMessage(View view){ 
    Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); 
    pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 1); 
    startActivityForResult(pickIntent, 0); 

反正有沒有做到這一點?

回答

0
AppWidgetHost host = new AppWidgetHost(this, HOST_CODE); 
host.startListening(); 
int nextId = host.allocateAppWidgetId(); 

Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); 
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, nextId); 
startActivityForResult(pickIntent, 1);