Android widget not showing up on the list after developed

后端 未结 8 719
渐次进展
渐次进展 2021-01-01 12:41

I\'m upgrading my app with widget. It\'s not the first widget I\'ve done. I was always encountering weird issues, but the widget was shwoing up on the list eventually.

相关标签:
8条回答
  • 2021-01-01 12:57

    You need to register a BroadcastReceiver in the manifest file. For example:

    <receiver
       android:icon="@drawable/icon"
       android:label="Example Widget"
       android:name="MyWidgetProvider" >
       <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> 
    

    I borrowed this code from http://www.vogella.com/articles/AndroidWidgets/article.html

    See the link for a full tutorial

    0 讨论(0)
  • 2021-01-01 12:58

    Ran across similar issues and this is what happened for me. The below Widget never showed up in the Widget drawer till minResizeHeight was added. Weird, but may be that is required for resizable widget. Could have been more friendly.

    <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/pmt_schedule_scroll_widget"
    android:minHeight="146dip"
    android:minResizeHeight="73dp"
    android:minWidth="146dip"
    android:resizeMode="vertical"
    android:updatePeriodMillis="0" />
    
    0 讨论(0)
  • 2021-01-01 13:05

    I tried every possible solution and nothing worked for me... And finally I solved it.

    In my case the problem was overthinking: I believed that in meta-data tag we need to define a unique name for provider (eg: "com.example.myprovider") as well as link to the xml resource.

    Wrong:

    <meta-data
          android:name="com.example.myprovider"
          android:resource="@xml/widget_info" />
    

    Right:

    <meta-data
      android:name="android.appwidget.provider"
      android:resource="@xml/widget_info" />
    
    0 讨论(0)
  • 2021-01-01 13:09

    after hours of searching and failing to resolve, I decided to open a sample project of a widget that works and go comparing item by item to see what was wrong, in the end, I solve added the following lines on my res/xml/widget_info.xml:

    android:minHeight="XXXdp"
    android:minResizeHeight="XXXdp"
    android:minResizeWidth="XXXdp"
    android:minWidth="XXXdp"
    

    where XXX is some value.

    0 讨论(0)
  • 2021-01-01 13:10

    The problem was android:installLocation="preferExternal"

    It somehow causes problem with widget list if the app is installed on SD

    0 讨论(0)
  • In my case, it was the minWidth, it was too large, just put a smaller dp, it works also with a minHeight too height as well!

    0 讨论(0)
提交回复
热议问题