Android 应用程序小部件不显示

发布于 2024-09-13 03:39:15 字数 2025 浏览 4 评论 0原文

看起来我的#$#%$%#$接收器不是清单中的应用程序元素

嗨,

我刚刚创建了 helloworld appwidget 来看看它是如何工作的。我按照 adroid 开发网站上的开发示例进行操作。但由于某种原因,小部件不想显示在小部件列表中。

AndroidManifest.xml

 <receiver android:name="VoiceRIAWidget" android:label="Voice RIA">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/appwidget_info" />
    </receiver>

appwidget_info.xml

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="Voice RIA" android:minWidth="50dp" android:minHeight="50dp"
    android:updatePeriodMillis="86400000" android:initialLayout="@layout/appwidget">
</appwidget-provider>

VoiceRIAWidget

public class VoiceRIAWidget extends AppWidgetProvider
{

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

        final int N = appWidgetIds.length;

        for (int i = 0; i < N; i++)
        {
            int appWidgetId = appWidgetIds[i];

            CharSequence text = "Hello";

            RemoteViews views = new RemoteViews(context.getPackageName(),
                    R.layout.appwidget);

            views.setTextViewText(R.id.appwidget_text, text);

            appWidgetManager.updateAppWidget(appWidgetId, views);
        }

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }
}

appwidget.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/appwidget_text" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textColor="#ff000000" />

我看不到它运行时缺少什么,但列表中没有任何内容。

Looked like my #$#%$%#$ the receiver was not i application element in manifest

Hi

I just created the helloworld appwidget to see how its works. i followed the dev example on adroid dev site. But for some reason the widget does not want to show in the widget list.

AndroidManifest.xml

 <receiver android:name="VoiceRIAWidget" android:label="Voice RIA">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/appwidget_info" />
    </receiver>

appwidget_info.xml

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="Voice RIA" android:minWidth="50dp" android:minHeight="50dp"
    android:updatePeriodMillis="86400000" android:initialLayout="@layout/appwidget">
</appwidget-provider>

VoiceRIAWidget

public class VoiceRIAWidget extends AppWidgetProvider
{

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

        final int N = appWidgetIds.length;

        for (int i = 0; i < N; i++)
        {
            int appWidgetId = appWidgetIds[i];

            CharSequence text = "Hello";

            RemoteViews views = new RemoteViews(context.getPackageName(),
                    R.layout.appwidget);

            views.setTextViewText(R.id.appwidget_text, text);

            appWidgetManager.updateAppWidget(appWidgetId, views);
        }

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }
}

appwidget.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/appwidget_text" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textColor="#ff000000" />

I cant see what i am missing it runs but nothing in list.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荭秂 2024-09-20 03:39:15

我刚刚遇到了同样的问题。我的错误是,我将接收器标签放在清单标签内,而我应该将其放在应用程序标签内。
这是我不工作的 XML:

<manifest....>
  ....
  <receiver ...>
    ...
  </receiver>
  <application ...>
    ...
  </applciation>
</manifest>

这是我工作良好的 XML:

<manifest...>
  ....
  <application...>
    ...
    <receiver...>
      ...
    </receiver>
  </application>    
</manifest>

希望它对您有帮助!

I just had the same problem. My mistake was, that i put the receiver tag just inside my manifest tag, when i was supposed to put it inside my application-tag.
This was my not-working-XML:

<manifest....>
  ....
  <receiver ...>
    ...
  </receiver>
  <application ...>
    ...
  </applciation>
</manifest>

This is my well-working-XML:

<manifest...>
  ....
  <application...>
    ...
    <receiver...>
      ...
    </receiver>
  </application>    
</manifest>

Hope it helps you!

倥絔 2024-09-20 03:39:15

我刚刚遇到了同样的问题。我的错误是,我构建了一个应用程序小部件,作为安装在 SD 卡上的现有应用程序的补充。将应用程序移动到手机上修复了它。

I just had the same problem. My mistake was, that I building an app widget as addition to an existing app which was installed on sd-card. Moving the app to phone fixed it.

风为裳 2024-09-20 03:39:15

面临类似的问题。我将元数据放在接收器之外,您首先已经正确完成了这一操作。

faced the similar problem . I was putting meta data outside the receiver which you have already done correctly in first place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文