I am trying to make a simple widget
but when I want to put it in the screen it just disappear.
I tried this on Api : 23,26 and 30 ,it's all give me the same result.
Manifest.xml
<receiver android:name=".mAppWidgetProvider">
<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>
widget_info.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:configure="com.app24.test.mAppWidgetProvider"
android:initialLayout="@layout/my_widget"
android:minWidth="250dp"
android:minHeight="70dp"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="10000"
android:widgetCategory="home_screen">
</appwidget-provider>
mAppWidgetProvider
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
public class mAppWidgetProvider extends AppWidgetProvider {
}
my_widget (the layout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@color/white"
android:padding="8dp">
<TextView
android:text="Hello world"
android:textSize="24sp"
android:layout_weight="1"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="Click me!"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="Click me!"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
and I have tried the other solutions but no thing.
check out logcat and look for some Exception
. App widgets are crashing "silently" without any dialog, just doesn't appear. But you should be able to find cause of problem in logs
in your code I see one wrong line:
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
...
android:configure="com.app24.test.mAppWidgetProvider"
...
android:configure
should point on some Activity
, which will be started when your widget will be added to home screen. your line points wrongly on your custom AppWidgetProvider
, which isn't an Acticity
- system probably tries to start this class as Activity
or maybe checks instanceof
and as this class isn't Activity
then crash occurs. try to remove this line for start (or point on proper class)