我可以将多个接收者添加到我的清单中吗?
好的,我正在制作一组小部件,按下时它们会简单地打开一个特定的应用程序。我在开发方面相当新手,所以我的问题是我是否可以继续为每个单独的小部件添加一个新的接收器到清单中?我尝试了一下,它确实有效,但后来我添加的所有新接收器都会在我应用它们时给我一个 FC,DDMS 会说“无法实例化接收器”。我在下面提供了一份清单副本(带有 3 个接收器),如果有更好的方法来解决此问题,请告诉我。谢谢。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.natehoch96.widgets.Template"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Test1" android:label="@string/widget_test1">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/test1_provider" />
</receiver>
<receiver android:name=".Test2" android:label="@string/widget_test2">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/test2_provider" />
</receiver>
<receiver android:name=".Test3" android:label="@string/widget_test3">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/test3_provider" />
</receiver>
Ok so I am making a set of widgets that will simply open up a specific app when pressed. I am fairly new at developing, so my question is if I can just keep adding a new receiver to the Manifest for each individual widget? I tried it and it was working but it then got to a point where all the new receivers I added would give me an FC when I went to apply them, the DDMS would say "unable to instantiate receiver." I provided a copy of my manifest below (with 3 receivers), also if there is a better way to go about this then please let me know. Thanks.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.natehoch96.widgets.Template"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Test1" android:label="@string/widget_test1">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/test1_provider" />
</receiver>
<receiver android:name=".Test2" android:label="@string/widget_test2">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/test2_provider" />
</receiver>
<receiver android:name=".Test3" android:label="@string/widget_test3">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/test3_provider" />
</receiver>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用接收器的完整路径。您可以拥有的接收器数量没有限制。
android:name=".Test3"
-->android:name="com.yourpackage.Test3"
Try using the full path to your receiver. There is no limit to how many receivers you can have.
android:name=".Test3"
-->android:name="com.yourpackage.Test3"