vendredi 1 juillet 2016

My appwidget-provider doesn't work in xml folder but works in layout folder

I'm having a problem... I've started to learn android development through Xamarin.

I'm trying to build my first widget, called HelloWorldWidget.

My problem is, my appwidget-provider xml isn't recognized inside the xml folder and I'm receiving this error:

No resource found that matches the given name (at 'resource' with value '@xml/HelloWorldWidgetProvider').   HelloWidget.Droid   C:UserspauloSourceReposPocsHelloWidgetHelloWidgetHelloWidget.DroidobjDebugandroidmanifestAndroidManifest.xml   17  

When I copy the file to layout resource and change my resource path to @layout/, everything works fine.

Here are my files:

resources/xml/HelloWorldWidgetProvider.xml

<?xml version="1.0" encoding="UTF-8" ?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="40dp"
    android:minHeight="40dp"
    android:updatePeriodMillis="86400000"
    android:initialLayout="@layout/HelloWorldWidget"
    android:resizeMode="horizontal|vertical"
    android:widgetCategory="home_screen">
</appwidget-provider>

resources/layout/HelloWorldWidget.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/HelloWorldWidgetText"
        android:text="Hello World!"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

HelloWordWidget.cs

[BroadcastReceiver(Label = "@string/HelloWorldWidgetLabel")]
[IntentFilter(new string[] { "android.appwidget.action.APPWIDGET_UPDATE" })]
[MetaData("android.appwidget.provider", Resource = "@xml/HelloWorldWidgetProvider")]
public class HelloWorldWidget : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
    }
}

Any clues?

Aucun commentaire:

Enregistrer un commentaire