Android小工具没有显示在4.3 [英] Android widget not showing on 4.3

查看:95
本文介绍了Android小工具没有显示在4.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小部件不小部件列表展示
也有类似的问题,还有很多其他的问题在哪里,答案基本上是:重新启动,启动应用程序,等等,等等。

Widget not showing in widget list had a similar question, and there are many other questions where the answer is basically: reboot, start app, wait, etc.

应用程序安装后,它显示了Android 2.3的设备上的小部件。因此,code是罚款。
但是,一直没有出现一个4.3的设备上。所以4.3寻找的东西是不存在的。

After the app install, it shows the widget on a Android 2.3 device. So the code is fine. But it never shows up on a 4.3 device. So 4.3 is looking for something that is not there.

有没有人有任何其他建议吗?

Does anyone have any additional tips?

的Andr​​oidManifest.xml

    <receiver
        android:name=".WidgetProvider"
        android:label="@string/widget_name">
        <intent-filter>
           <action
               android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data 
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_info" />
    </receiver>

widget_info.xml

   <?xml version="1.0" encoding="utf-8"?>
   <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" >
    android:minWidth="208dp"
    android:minHeight="56dp"
    android:minResizeHeight="48dp"
    android:minResizeWidth="48dp"
    android:updatePeriodMillis="86400000"
    android:previewImage="@drawable/ic_launcher"
    android:resizeMode="horizontal|vertical"
    android:widgetCategory="home_screen"
    android:configure=""
    android:initialLayout="@layout/widget_layout"
  </appwidget-provider>

WidgetProvider.java

public class WidgetProviderextends AppWidgetProvider {
   DateFormat df = new SimpleDateFormat("hh:mm:ss");

   public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
     final int N = appWidgetIds.length;

     Log.i("ExampleWidget",  "Updating widgets " + Arrays.asList(appWidgetIds));

     // Perform this loop procedure for each App Widget that belongs to this
     // provider
     for (int i = 0; i < N; i++) {
       int appWidgetId = appWidgetIds[i];

       // Create an Intent to launch ExampleActivity
       Intent intent = new Intent(context, ExampleActivity.class);
       PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

       // Get the layout for the App Widget and attach an on-click listener
       // to the button
       RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
       views.setOnClickPendingIntent(R.id.new_post, pendingIntent);

       // To update a label
       views.setTextViewText(R.id.blogname, df.format(new Date()));

       // Tell the AppWidgetManager to perform an update on the current app
       // widget
       appWidgetManager.updateAppWidget(appWidgetId, views);
     }
   }

以上所有code是大多例如code进行测试,并能正常工作在Android 2.3不只是对4.3 ... ...有运行中的logcat输出的调试版本时都没有错误。

All the code above is mostly example code for testing, and it works fine on Android 2.3 just not on 4.3... There are no errors when running the debug build in the logcat output.

推荐答案

哎呀!
最后重做了整个事情,现在的工作 - 有在原来的code单个字符错字。
在widget_info.xml的>字符被错误地放置。它应放置的之后的所有属性,而不是之前。这是没有报告为在Eclipse中,也不在构建应用程序,也没有在运行的应用程序有问题。而在Android 4.2,默认设置必须是这样,它允许安装构件进行,而在4.3中,默认禁用可能安装。

Argh! Finally redid the whole thing, and it now works - there was a single character typo in the original code. The > character in widget_info.xml was wrongly placed. It should be placed after all the attributes, not before. This was not reported as a problem in eclipse, nor in building the app, nor in running the app. And on Android 4.2, the defaults must be such that it allows widget install to proceed, while on 4.3, the defaults probably disable the install.

在上面张贴一个小小的线索 - 堆栈溢出突出在AndroidManifest.xml每个XML属性,而不是在原来的职位显示的widget_info.xml。固定>字符修复了高亮的日食了。

One small clue in the posting above - Stack Overflow highlights each XML attribute in AndroidManifest.xml but not in the widget_info.xml shown in the original post. Fixing the > character fixes the highlighting in eclipse too.

widget_info.xml

   <?xml version="1.0" encoding="utf-8"?>
   <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="208dp"
    android:minHeight="56dp"
    android:minResizeHeight="48dp"
    android:minResizeWidth="48dp"
    android:updatePeriodMillis="86400000"
    android:previewImage="@drawable/ic_launcher"
    android:resizeMode="horizontal|vertical"
    android:widgetCategory="home_screen"
    android:configure=""
    android:initialLayout="@layout/widget_layout" >
  </appwidget-provider>

这篇关于Android小工具没有显示在4.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆