Android 应用程序小部件不显示
看起来我的#$#%$%#$接收器不是清单中的应用程序元素
嗨,
我刚刚创建了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚遇到了同样的问题。我的错误是,我将接收器标签放在清单标签内,而我应该将其放在应用程序标签内。
这是我不工作的 XML:
这是我工作良好的 XML:
希望它对您有帮助!
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:
This is my well-working-XML:
Hope it helps you!
我刚刚遇到了同样的问题。我的错误是,我构建了一个应用程序小部件,作为安装在 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.
面临类似的问题。我将元数据放在接收器之外,您首先已经正确完成了这一操作。
faced the similar problem . I was putting meta data outside the receiver which you have already done correctly in first place.