软件应用教程

AppWidgetManager类中文翻译 Android开发技术

AppWidgetManager类中文翻译 Android开发技术

  AppWidgetManager作为Android平台上最主要的Widgets管理类,提供了更新AppWidget状态,获取已经安装的Appwidget提供信息和其他的相关状态

下面列出一些常用的动作:

Constants
String ACTION_APPWIDGET_CONFIGURE Sent when it is time to configure your AppWidget while it is being added to a host.
String ACTION_APPWIDGET_DELETED Sent when an instance of an AppWidget is deleted from its host.
String ACTION_APPWIDGET_DISABLED Sent when an instance of an AppWidget is removed from the last host.
String ACTION_APPWIDGET_ENABLED Sent when an instance of an AppWidget is added to a host for the first time.
String ACTION_APPWIDGET_PICK Send this from your AppWidgetHost activity when you want to pick an AppWidget to display.
String ACTION_APPWIDGET_UPDATE Sent when it is time to update your AppWidget.
String EXTRA_APPWIDGET_ID An intent extra that contains one appWidgetId.
String EXTRA_APPWIDGET_IDS An intent extra that contains multiple appWidgetIds.
String EXTRA_CUSTOM_EXTRAS An intent extra to pass to the AppWidget picker containing a List of Bundle objects to mix in to the list of AppWidgets that are installed. It will be added to the extras object on the Intent that is returned from the picker activity.
String EXTRA_CUSTOM_INFO An intent extra to pass to the AppWidget picker containing a List of AppWidgetProviderInfo objects to mix in to the list of AppWidgets that are installed.
int INVALID_APPWIDGET_ID A sentiel value that the AppWidget manager will never return as a appWidgetId.
String META_DATA_APPWIDGET_PROVIDER Field for the manifest meta-data tag.

    AppWidgetManager提供的一些方法可以绑定你的Widget、通过provider名称获取对应的id,获取一个widget provider信息等,平时可能只使用getInstance获取一个实例,以及updateAppWidget这个方法,需要注意的是它提供了3种重载方法,可以更新一个widget组,或通过CompoentName来识别最终的对象,同时在Widget中一般界面的显示使用了RemoteViews这个类,以后我们会着重讲解下它有哪些特别之处。

Public Methods
void bindAppWidgetId(int appWidgetId, ComponentName provider)
Set the component for a given appWidgetId.
int[] getAppWidgetIds(ComponentName provider)
Get the list of appWidgetIds that have been bound to the given AppWidget provider.
AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId)
Get the available info about the AppWidget.
List<AppWidgetProviderInfo> getInstalledProviders()
Return a list of the AppWidget providers that are currently installed.
static AppWidgetManager getInstance(Context context)
Get the AppWidgetManager instance to use for the supplied Context object.
void updateAppWidget(int[] appWidgetIds, RemoteViews views)
Set the RemoteViews to use for the specified appWidgetIds.
void updateAppWidget(ComponentName provider, RemoteViews views)
Set the RemoteViews to use for all AppWidget instances for the supplied AppWidget provider.
void updateAppWidget(int appWidgetId, RemoteViews views)
Set the RemoteViews to use for the specified appWidgetId.

[Expand]
Inherited Methods
From class java.lang.Object

Object clone()
Creates and returns a copy of this Object.
boolean equals(Object o)
Compares this instance with the specified object and indicates if they are equal.
void finalize()
Is called before the object’s memory is being reclaimed by the VM.
final Class<? extends Object> getClass()
Returns the unique instance of Class which represents this object’s class.
int hashCode()
Returns an integer hash code for this object.
final void notify()
Causes a thread which is waiting on this object’s monitor (by means of calling one of the wait() methods) to be woken up.
final void notifyAll()
Causes all threads which are waiting on this object’s monitor (by means of calling one of the wait() methods) to be woken up.
String toString()
Returns a string containing a concise, human-readable description of this object.
final void wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.
final void wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.
final void wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

Constants

public static final String ACTION_APPWIDGET_CONFIGURE

Sent when it is time to configure your AppWidget while it is being added to a host. This action is not sent as a broadcast to the AppWidget provider, but as a startActivity to the activity specified in the AppWidgetProviderInfo meta-data.

The intent will contain the following extras:

EXTRA_APPWIDGET_ID The appWidgetId to configure.

If you return RESULT_OK using Activity.setResult(), the AppWidget will be added, and you will receive an ACTION_APPWIDGET_UPDATE broadcast for this AppWidget. If you return RESULT_CANCELED, the host will cancel the add and not display this AppWidget, and you will receive a ACTION_APPWIDGET_DELETED broadcast.

Constant Value: "android.appwidget.action.APPWIDGET_CONFIGURE"

public static final String ACTION_APPWIDGET_DELETED

Sent when an instance of an AppWidget is deleted from its host.

See Also
  • AppWidgetProvider.onDeleted(Context context, int[] appWidgetIds)

Constant Value: "android.appwidget.action.APPWIDGET_DELETED"

public static final String ACTION_APPWIDGET_DISABLED

Sent when an instance of an AppWidget is removed from the last host.

See Also
  • AppWidgetProvider.onEnabled(Context context)

Constant Value: "android.appwidget.action.APPWIDGET_DISABLED"

public static final String ACTION_APPWIDGET_ENABLED

Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider.

See Also
  • AppWidgetProvider.onEnabled(Context context)

Constant Value: "android.appwidget.action.APPWIDGET_ENABLED"

public static final String ACTION_APPWIDGET_PICK

Send this from your AppWidgetHost activity when you want to pick an AppWidget to display. The AppWidget picker activity will be launched.

You must supply the following extras:

EXTRA_APPWIDGET_ID A newly allocated appWidgetId, which will be bound to the AppWidget provider once the user has selected one.

The system will respond with an onActivityResult call with the following extras in the intent:

EXTRA_APPWIDGET_ID The appWidgetId that you supplied in the original intent.

When you receive the result from the AppWidget pick activity, if the resultCode is RESULT_OK, an AppWidget has been selected. You should then check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its configuration activity. If RESULT_CANCELED is returned, you should delete the appWidgetId.

See Also
  • ACTION_APPWIDGET_CONFIGURE

Constant Value: "android.appwidget.action.APPWIDGET_PICK"

public static final String ACTION_APPWIDGET_UPDATE

Sent when it is time to update your AppWidget.

This may be sent in response to a new instance for this AppWidget provider having been instantiated, the requested update interval having lapsed, or the system booting.

The intent will contain the following extras:

EXTRA_APPWIDGET_IDS The appWidgetIds to update. This may be all of the AppWidgets created for this provider, or just a subset. The system tries to send updates for as few AppWidget instances as possible.
See Also
  • AppWidgetProvider.onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)

Constant Value: "android.appwidget.action.APPWIDGET_UPDATE"

public static final String EXTRA_APPWIDGET_ID

An intent extra that contains one appWidgetId.

The value will be an int that can be retrieved like this:

Bundle extras = intent.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);

 

Constant Value: "appWidgetId"

public static final String EXTRA_APPWIDGET_IDS

An intent extra that contains multiple appWidgetIds.

The value will be an int array that can be retrieved like this:

Bundle extras = intent.getExtras();
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);

 

Constant Value: "appWidgetIds"

public static final String EXTRA_CUSTOM_EXTRAS

An intent extra to pass to the AppWidget picker containing a List of Bundle objects to mix in to the list of AppWidgets that are installed. It will be added to the extras object on the Intent that is returned from the picker activity.

 

Constant Value: "customExtras"

public static final String EXTRA_CUSTOM_INFO

An intent extra to pass to the AppWidget picker containing a List of AppWidgetProviderInfo objects to mix in to the list of AppWidgets that are installed. (This is how the launcher shows the search widget).

Constant Value: "customInfo"

public static final int INVALID_APPWIDGET_ID

A sentiel value that the AppWidget manager will never return as a appWidgetId.

Constant Value: 0 (0x00000000)

public static final String META_DATA_APPWIDGET_PROVIDER

Field for the manifest meta-data tag.

See Also
  • AppWidgetProviderInfo

Constant Value: "android.appwidget.provider"

Public Methods

public void bindAppWidgetId (int appWidgetId, ComponentName provider)

Set the component for a given appWidgetId.

You need the APPWIDGET_LIST permission. This method is to be used by the AppWidget picker.

Parameters
appWidgetId The AppWidget instance for which to set the RemoteViews.
provider The BroadcastReceiver that will be the AppWidget provider for this AppWidget.

public int[] getAppWidgetIds (ComponentName provider)

Get the list of appWidgetIds that have been bound to the given AppWidget provider.

Parameters
provider The BroadcastReceiver that is the AppWidget provider to find appWidgetIds for.

public AppWidgetProviderInfo getAppWidgetInfo (int appWidgetId)

Get the available info about the AppWidget.

Returns
  • A appWidgetId. If the appWidgetId has not been bound to a provider yet, or you don’t have access to that appWidgetId, null is returned.

public List<AppWidgetProviderInfo> getInstalledProviders ()

Return a list of the AppWidget providers that are currently installed.

public static AppWidgetManager getInstance (Context context)

Get the AppWidgetManager instance to use for the supplied Context object.

public void updateAppWidget (int[] appWidgetIds, RemoteViews views)

Set the RemoteViews to use for the specified appWidgetIds.

It is okay to call this method both inside an ACTION_APPWIDGET_UPDATE broadcast, and outside of the handler. This method will only work when called from the uid that owns the AppWidget provider.

Parameters
appWidgetIds The AppWidget instances for which to set the RemoteViews.
views The RemoteViews object to show.

public void updateAppWidget (ComponentName provider, RemoteViews views)

Set the RemoteViews to use for all AppWidget instances for the supplied AppWidget provider.

It is okay to call this method both inside an ACTION_APPWIDGET_UPDATE broadcast, and outside of the handler. This method will only work when called from the uid that owns the AppWidget provider.

Parameters
provider The ComponentName for the BroadcastReceiver provider for your AppWidget.
views The RemoteViews object to show.

public void updateAppWidget (int appWidgetId, RemoteViews views)

Set the RemoteViews to use for the specified appWidgetId.

It is okay to call this method both inside an ACTION_APPWIDGET_UPDATE broadcast, and outside of the handler. This method will only work when called from the uid that owns the AppWidget provider.

Parameters
appWidgetId The AppWidget instance for which to set the RemoteViews.
views The RemoteViews object to show.

软件应用教程

更多有关于 软件应用教程

如何利用火车采集软件采集58招聘信息_爬虫软件技术与爬虫软件网页数据采集器门户

什么是火车采集器 如何使用火车采集器软件_爬虫软件技术与爬虫软件网页数据采集器门户

如何使用火车采集器制作zencart数据包来进行批量导入商品_爬虫软件技术与爬虫软件网页数据采集器门户

火车头采集器的DedeCMS5.7文章免登陆发布接口_爬虫软件技术与爬虫软件网页数据采集器门户

火车头采集器如何把浏览器里面的cookie到火车头采集器里面_爬虫软件技术与爬虫软件网页数据采集器门户

火车头采集器教程之如何通过fiddler获取cookie简单教程_爬虫软件技术与爬虫软件网页数据采集器门户

火车头采集器FTP设置 图片下载上传的路径的设置_爬虫软件技术与爬虫软件网页数据采集器门户

火车头采集器文件图片下载路径设置简易说明_爬虫软件技术与爬虫软件网页数据采集器门户

火车采集器采集淘宝天猫商品采集多页获取宝贝详细教程_爬虫软件技术与爬虫软件网页数据采集器门户

本人擅长Ai、Fw、Fl、Br、Ae、Pr、Id、Ps等软件的安装与卸载,精通CSS、JavaScript、PHP、ASP、C、C++、C#、Java、Ruby、Perl、Lisp、Python、Objective-C、ActionScript、Pascal等单词的拼写,熟悉Windows、Linux、OS X、Android、iOS、WP8等系统的开关机。

通过下面的方式来联系我们:

电邮:138762189@qq.com

联系QQ:点击这里给我发消息

官方站:www.tadke.com

※ ※ 联系请加我的企鹅号 ※※

※ ※技术支持请微信联系站长 ※※

Copyright © 2016 Tadke.com. Powered by Wordpress.