2014-04-04 5 views
0
package com.appointext.widget; 

    import com.bmsce.appointext.R; 
//import com.appointext.frontend.*; 

import android.app.PendingIntent; 
import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.Context; 
import android.content.Intent; 
import android.widget.RemoteViews; 

public class Widget extends AppWidgetProvider { 

    //DateFormat df = new SimpleDateFormat("hh:mm:ss"); 

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
    final int N = appWidgetIds.length; 

    // Perform this loop procedure for each App Widget that belongs to this 
    // provider 
    for (int i = 0; i < N; i++) { 
    int appWidgetId = appWidgetIds[i]; 

    // Create an Intent to launch ExampleActivity 
    Intent intent = new Intent(context, com.appointext.frontend.AppoinTextActivity.class); 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 

    // Get the layout for the App Widget and attach an on-click listener 
    // to the button 
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main); 
    views.setOnClickPendingIntent(R.id.button, pendingIntent); 

    // To update a label 
    //views.setTextViewText(R.id.widget1label, "AppoinText"); 

    // Tell the AppWidgetManager to perform an update on the current app 
    // widget 
    appWidgetManager.updateAppWidget(appWidgetId, views); 
    } 
} 
} 

이것은 내 주요 자바 클래스이며 프론트 엔드의 약속 시간 클래스를 호출하려고합니다. 홈 화면의 위젯은 "위젯을로드 할 수 없습니다"라고 말하고 있습니다. 제발 누군가 내 실수라고 말해주십시오.안드로이드 위젯이 작동하지 않습니다.

답변

0
위젯을 추가 할 때 귀하의 onUpdate()가 호출되지

, 당신은

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 

이 또한 매니페스트는 다음과 같이되어 있는지 만드는의 onUpdate() 메소드를 오버라이드 (override) 할 필요가

<receiver android:name="com.example.app.Widget" > 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 

     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_info" /> 
</receiver> 
관련 문제