在设备上的小部件列表中发现查找小部件

时间:2013-10-05 22:52:40

标签: android android-widget

我创建了一个我试图在真实设备上运行的Android小部件。我的Android Manifest是这样的:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<receiver android:name=".AFBWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidet.action.APPWIDGET_UPDATE"/>
</intent-filter>

<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_stuff"/>

</receiver>

<activity android:name=".WidgetConfig" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>     
</intent-filter>

</activity>   

</application>

</manifest>

我最初得到的错误是没有找到启动器活动所以我在运行配置中设置启动操作以启动我的WidgetConfig活动。这解决了问题,但应用程序会意外停止。

在不更改我的启动操作(启动默认活动)的情况下,我当然会得到原始的no launcher found错误。然后,我的应用程序小部件将安装到设备上。

这是另一个问题:当我长时间点击主屏幕时窗口小部件没有显示在窗口小部件列表中,但我知道它在设备上,因为它显示在应用程序管理器列表中。

另外,我试图在清单中添加Launcher活动,但我被告知我不需要它。如果我真的需要它可以有人请告诉我把它放在我的Manifest中的哪个位置?

问题是什么?

增加:

将小部件添加到主屏幕时出现Logcat错误:

10-05 21:26:54.380: D/AndroidRuntime(18023): Shutting down VM
10-05 21:26:54.380: W/dalvikvm(18023): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
10-05 21:26:54.390: E/AndroidRuntime(18023): FATAL EXCEPTION: main
10-05 21:26:54.390: E/AndroidRuntime(18023): java.lang.RuntimeException: Unable to instantiate receiver com.example.awesomefilebuilderwidget.AFBWidget: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.AFBWidget in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-05 21:26:54.390: E/AndroidRuntime(18023):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2012)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at android.app.ActivityThread.access$2400(ActivityThread.java:135)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1101)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at android.os.Looper.loop(Looper.java:150)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at android.app.ActivityThread.main(ActivityThread.java:4333)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at java.lang.reflect.Method.invokeNative(Native Method)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at java.lang.reflect.Method.invoke(Method.java:507)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at dalvik.system.NativeStart.main(Native Method)
10-05 21:26:54.390: E/AndroidRuntime(18023): Caused by: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.AFBWidget in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-05 21:26:54.390: E/AndroidRuntime(18023):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-05 21:26:54.390: E/AndroidRuntime(18023):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2003)
10-05 21:26:54.390: E/AndroidRuntime(18023):    ... 10 more

添加后添加更新的错误日志

<activity android:name=".AFBWidget" android:label="@string/app_name"/>

to Manifest:

10-05 21:51:45.485: D/AndroidRuntime(3557): Shutting down VM
10-05 21:51:45.485: W/dalvikvm(3557): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
10-05 21:51:45.505: E/AndroidRuntime(3557): FATAL EXCEPTION: main
10-05 21:51:45.505: E/AndroidRuntime(3557): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.awesomefilebuilderwidget/com.example.awesomefilebuilderwidget.WidgetConfig}: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.WidgetConfig in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1746)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1854)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.app.ActivityThread.access$1500(ActivityThread.java:135)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1041)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.os.Looper.loop(Looper.java:150)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.app.ActivityThread.main(ActivityThread.java:4333)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at java.lang.reflect.Method.invokeNative(Native Method)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at java.lang.reflect.Method.invoke(Method.java:507)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at dalvik.system.NativeStart.main(Native Method)
10-05 21:51:45.505: E/AndroidRuntime(3557): Caused by: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.WidgetConfig in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-05 21:51:45.505: E/AndroidRuntime(3557):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
10-05 21:51:45.505: E/AndroidRuntime(3557):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1738)
10-05 21:51:45.505: E/AndroidRuntime(3557):     ... 11 more

1 个答案:

答案 0 :(得分:1)

<receiver> ...</receiver>

中的拼写错误

**** 您忘记在appwidget中添加g

 <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>

尝试并让我知道;)

对于Launcher错误

尝试添加<category android:name="android.intent.category.LAUNCHER" />

<activity><intent-filter>...</intent-filter></activity>