2014-06-06 12 views
9

我的應用程序中有2個控件。兩者都具有完全相同的功能,但具有不同的佈局。 他們在每臺設備上都能正常工作,但看起來像是三星設備上存在問題。每次我發佈應用程序的新版本時,都會從用戶屏幕中刪除該小部件。看起來這是一個三星TouchWiz錯誤,但用戶告訴我其他應用程序沒有這個問題。 有什麼想法發生了什麼?每次在三星設備上更新應用程序時,控件都會消失

BTW我想了一下,我找到了一種方法來解決它在這個博客帖子:https://medium.com/the-wtf-files/the-mysterious-case-of-the-disappearing-widget-f4177a8e2c2b 但我沒有手動調用

updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); 

相反,我打電話

ComponentName cn = new ComponentName(context,clazz); AppWidgetManager.getInstance(context).updateAppWidget(cn,views);

爲了更新我的小部件

更多的我的代碼:

public static final int layout = R.layout.widget_large_layout; 
    public static final BitmapQualityEnum thumbnailQuality = BitmapQualityEnum.HIGH_RES; 
    public static final Class<?> clazz = LargeWidgetProvider.class; 

    @Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
     if (context != null && appWidgetIds != null && appWidgetIds.length > 0) { 
      // To prevent any ANR timeouts, we perform the update in a service 
      context.startService(new Intent(context, LargeWidgetProvider.UpdateService.class)); 
     } 
    } 


    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (context != null && intent != null) { 
      boolean doUpdate = true; 
      if ("android.appwidget.action.APPWIDGET_UPDATE".equals(intent.getAction())) { 
       final int[] widgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); 
       doUpdate = (widgetIds != null && widgetIds.length > 0); 
      } 

      if (doUpdate) { 
       WidgetProviderHelper.receive(context, intent, clazz, layout, thumbnailQuality); 
      } 
      super.onReceive(context, intent); 
     } 
    } 

public static class UpdateService extends Service { 

     private int serviceStartId = -1; 

     @Override 
     public boolean onUnbind(Intent intent) { 
      stopSelf(this.serviceStartId); 
      return true; 
     } 

     @Override 
     public int onStartCommand(Intent intent, int flags, int startId) { 
      this.serviceStartId = startId; 
      // Push update for this widget to the home screen 
      updateData(this); 
      return START_STICKY; 
     } 

     @Override 
     public void onConfigurationChanged(Configuration newConfig) { 
      super.onConfigurationChanged(newConfig); 
      //   int oldOrientation = this.getResources().getConfiguration().orientation; 
      //   if (newConfig.orientation != oldOrientation) { 
      // Update the widget) { 
      updateData(this); 
      //   } 
     } 


     @Override 
     public IBinder onBind(Intent intent) { 
      // We don't need to bind to this service 
      return null; 
     } 
    } 
+0

我有消失的小部件(和圖標)對三星設備的問題也和原來,啓用/在我的應用程序禁用組件編程(無關的部件本身的組件)搞砸了的TouchWiz。如果你發佈了更多的小部件代碼(比如onReceive/onUpdate,我可以檢查它是否存在潛在的問題) –

+0

我得到「你的應用程序有這個問題,但其他應用程序不」很多,反指令可能是「99.9我的數十萬用戶中有%沒有這個問題,所以你的設備出了什麼問題?「;-)。 如果有一個應用程序出於假設200有問題(0.5%),而具有該問題的100,000個安裝中的5個設備(0.005%)相比,那麼該設備出現問題的可能性顯然高於具有該問題的應用程序問題。當然,事實通常是介於兩者之間的因素,通常是多種因素的結合)。 –

+0

@Emanuel Moecklin只有少數用戶遇到問題並不重要。是的,也許有20個用戶報告了500K +以上的問題,但他們都有一個共同的三星設備。也大多數用戶沒有使用應用程序小部件,大多數用戶不會抱怨可能有的問題。 所以是的,我想解決這個問題;) – user1026605

回答

2

我終於成功地解決我的問題。 小工具提供者接收器需要導出!

<receiver 
     android:name=".widget.HorizontalWidgetProvider" 
     android:exported="true" > 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
      <action android:name="com.customEvent" /> 
     </intent-filter> 

     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_horizontal_provider" /> 
    </receiver> 
+3

根據此http://開發人員.android.com/guide/topics/manifest/receiver-element.html#如果接收者有一個意圖過濾器,導出導出標誌應該自動設置爲true,所以我想這是另一個TouchWiz錯誤。 –

相關問題