編輯:關於Android編程
First, declare the AppWidgetProvider
class in yourapplication'sAndroidManifest.xml
file. For example:
The AppWidgetProviderInfo
defines the essential qualities of an App Widget, such as its minimum layout dimensions, its initiallayout resource,how often to update the App Widget, and (optionally) a configuration Activity tolaunch at create-time.Define the AppWidgetProviderInfo object in an XML resource using a single element and save it in the project's
res/xml/
folder.
For example:
The updatePeriodMillis
attribute defines how often the AppWidget framework should request an update from theAppWidgetProvider
by calling theonUpdate()
callback method. The actual updateis not guaranteed to occur exactly on time with this value and we suggestupdating as infrequently as possible—perhaps no more than once an hour toconserve the battery. You might also allow the user to adjust the frequency in aconfiguration—some people might want a stock ticker to update every 15minutes, or maybe only four times a day.
Note: If the device is asleep when itis time for an update (as defined byupdatePeriodMillis
), then the device willwake up in order to perform the update. If you don't update more than once per hour, thisprobably won't cause significant problems for the battery life.If, however, you needto update more frequently and/or you do not need to update while the device is asleep,then you can instead perform updates based on an alarm that will not wake the device. To doso, set an alarm with an Intent that your AppWidgetProvider receives, using theAlarmManager
. Set the alarm type to eitherELAPSED_REALTIME
orRTC
, which will only deliver the alarm when the device is awake. Then setupdatePeriodMillis
to zero (0
).
You must define an initial layout for your App Widget in XML and save it inthe project'sres/layout/
directory. You can design your App Widget using theView objects listedbelow, but before you begin designing your App Widget, please read andunderstand theApp WidgetDesign Guidelines.
minWidth
or minHeight
)
You must declare your AppWidgetProvider class implementation as abroadcast receiver using the
element in the AndroidManifest (see Declaring an App Widget in the Manifest above).
The AppWidgetProvider
class extendsBroadcastReceiver as a convenienceclass to handle the App Widget broadcasts. The AppWidgetProvider receives onlythe event broadcasts thatare relevant to the App Widget, such as when the App Widget is updated, deleted,enabled, and disabled.When these broadcast events occur, the AppWidgetProvider receives the followingmethod calls:
onUpdate()
This is called to update the App Widget at intervals defined by theupdatePeriodMillis
attribute in the AppWidgetProviderInfo (seeAdding the AppWidgetProviderInfo Metadata above). This method is also called when the user adds the App Widget, so it should perform the essential setup, such as define event handlers for Views and start a temporaryService
, if necessary. However, if you have declared aconfiguration Activity,this method is not called when the user adds theApp Widget, but is called for the subsequent updates. It is the responsibility of the configuration Activity to perform the first update when configuration isdone. (SeeCreating an App Widget ConfigurationActivity below.)
如果你做過多媒體應用,一定會苦惱過,怎樣獲取sd卡中的多媒體文件。android還是很強大的,如果你知道怎麼調用android的api,萬事就ok了。 當手機或模擬器開機
前言:RecyclerView出現已經有一段時間了,我們肯定不陌生了,可以通過導入support-v7對其進行使用。根據官方的文檔,該控件用於在有限的窗口中展示大量數據集
學習Android到現在估計應該還不到一個月的時間,我很激動能夠在自己的努力還有奮斗下開發一個自己想要的App,雖然這個App的功能還不夠完善,界面很丑陋,Bug很存在很
主要講解Android Studio中生成aar文件以及本地方式使用aar文件的方法。 在Android Studio中對一個自己庫進行生成操作時將會同時生成*.jar與