WEB开发网
开发学院手机开发Android 开发 让自己的Android应用支持appwidget 阅读

让自己的Android应用支持appwidget

 2010-12-18 08:04:06 来源:WEB开发网   
核心提示:new ArrayList();AppWidgetProviderInfo info = new AppWidgetProviderInfo();info.provider = new ComponentName(getPackageName(), "XXX.YYY");info.label = &

new ArrayList();

AppWidgetProviderInfo info = new AppWidgetProviderInfo();

info.provider = new ComponentName(getPackageName(), "XXX.YYY");

info.label = "Search";

info.icon = R.drawable.ic_search_widget;

customInfo.add(info);

pickIntent.putParcelableArrayListExtra(

AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);

ArrayList customExtras = new ArrayList();

Bundle b = new Bundle();

b.putString(EXTRA_CUSTOM_WIDGET, "search_widget");

customExtras.add(b);

pickIntent.putParcelableArrayListExtra(

AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);

// start the pick activity

startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);

}

/**

* 添加widget

* @param data

*/

private void completeAddAppWidget(Intent data) {

Bundle extras = data.getExtras();

int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

d("completeAddAppWidget", "dumping extras content="+extras.toString());

d("completeAddAppWidget", "appWidgetId:"+ appWidgetId);

AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);

View hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);

layout.addInScreen(hostView, appWidgetInfo.minWidth, appWidgetInfo.minHeight);

}

}

package chroya.demo.widget;

import static android.util.Log.d;

import java.util.ArrayList;

import android.app.Activity;

import android.appwidget.AppWidgetHost;

import android.appwidget.AppWidgetManager;

import android.appwidget.AppWidgetProviderInfo;

import android.content.ComponentName;

import android.content.Intent;


  点击下载:php?id=1365" rel="nofollow">附件下载

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:自己 Android 应用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接