我有一个小部件,其中包含一个我只想在调用{此接收器不是为小部件实现的接收器}方法TextView
时才更新的小部件。Onreceive()
我不想定期更新小部件,但只有在Onreceive()
调用 my 时才更新。
恢复.java
public class Recver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Widgetd.updatewid(context);
}
}
}}
小部件.java
public class Widgetd extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onDeleted(context, appWidgetIds);
}
static void updatewid(Context context){
RemoteViews rv = new RemoteViews(context.getPackageName(),
R.layout.widgetlay);
rv.setTextViewText(R.id.widgetUpdateTv, "1");
}
}
清单.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="delete.detailduplicate"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="delete.detailduplicate.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Newmain"></activity>
<receiver android:name="Recver">
<intent-filter android:priority="9999999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
<receiver android:name="Widgetd">
<intent-filter >
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widgetsetter" />
</receiver>
</application>
</manifest>
小部件设置器.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widgetlay"
android:minHeight="300dp"
android:minWidth="72dp"
android:updatePeriodMillis="0" >
</appwidget-provider>