如何更新Android应用程序小部件?

如何更新Android应用程序小部件?,android,android-widget,Android,Android Widget,我是android编程新手。在我的android小部件中,我喜欢从名为get details的方法更新数据。我尝试了以下代码,但它也不起作用,所以请指出我的代码中有任何错误 Android清单xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="study.samples" andro

我是android编程新手。在我的android小部件中,我喜欢从名为get details的方法更新数据。我尝试了以下代码,但它也不起作用,所以请指出我的代码中有任何错误

Android清单xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="study.samples"
  android:versionCode="1"
  android:versionName="1.0" >

  <uses-sdk android:minSdkVersion="10" />
  <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <receiver android:name=".MyW" android:label="WatchWidget">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            <action android:name="android.appwidget.action.APPWIDGET_ENABLED"/>                
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_provider" />
    </receiver>
</application>
</manifest>

谢谢

看看这个问题:方法在哪里?还有其他部分?
public class MyW extends AppWidgetProvider {
public String deviceinfo = null;
public Context mContext = null;
public int asu = 0;

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    mContext = context;
    RemoteViews remoteViews;
    ComponentName watchWidget;
    remoteViews = new RemoteViews( context.getPackageName(), R.layout.main );
    watchWidget = new ComponentName( context, MyW.class );
    remoteViews.setTextViewText( R.id.widget_textview, "OK -> " + deviceinfo);
    appWidgetManager.updateAppWidget( watchWidget, remoteViews );
}

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;

    RemoteViews remoteViews;
    ComponentName watchWidget;
    remoteViews = new RemoteViews( context.getPackageName(), R.layout.main );
    watchWidget = new ComponentName( context, MyW.class );
    remoteViews.setTextViewText( R.id.widget_textview, "OK => " + deviceinfo);
    AppWidgetManager.getInstance(context).updateAppWidget( watchWidget, remoteViews );
}

@Override
public void onEnabled(Context context) {
    mContext = context;
    getDetails();
}

public void getDetails(){
       deviceinfo = "Hi friends";

       Intent i = new Intent(mContext, MyW.class);
       mContext.sendBroadcast(i);
}   
 }