要做個常駐程式的步驟:
1. 在 Manifest.xml 宣告常駐程式。
2. 實做常駐程式資訊檔案:res/xml/appwidget_info.xml
3. 實做一個layout檔來顯示: res/layout/layout_sample.xml
4. 實做一個AppWidgetProvider (也就是main.java),在此例裡App_WidgetActivityProvider.java
*標示圖:74的倍數-2, e.g. 72, (74*4)-2 = 294
****************************************
public class App_WidgetActivityProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
****************************************
App_Widget.manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cq.lin.app.widget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/widget"
android:label="@string/app_name" >
<receiver android:name="App_Widget"
android:label="CQ's Simple Widget"
android:icon="@drawable/widget">
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/appwidget_info"/>
</receiver>
</application>
</manifest>
****************************************
res/xml/appwidget_info.xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="72dp"
android:minHeight="72dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/layout_sample" >
</appwidget-provider>
***************************************
res/layout/layout_sample.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/appwidget_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff000000"
android:background="#ffffff"
android:text="Hello, Life is tough! (by Widget)" />
</LinearLayout>
沒有留言:
張貼留言