小部件窗口小部件列表不显示 [英] Widget not showing in widget list

查看:342
本文介绍了小部件窗口小部件列表不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,并已决定将一个小部件添加到它,我已经照着所有为它的官方文档,但是当我在我的Galaxy Nexus的安装应用程序,小部件不会出现在应用程序/小工具名单。

I have an app and have decided to add a widget to it, I've followed all the official documentation for it, but when I install the app on my Galaxy Nexus, the widget doesn't appear in the app/widget list.

的Andr​​oidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dysign.livetubecountdown"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="16" />

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

    <activity
        android:name="com.dysign.livetubecountdown.MainActivity"
        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="com.dysign.livetubecountdown.Widget" android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <intent-filter>
            <action android:name="android.appwidget,action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_provider" />
    </receiver>

</application>

widget_provider.xml

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

widget_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Large Text"
            android:id="@+id/widgetTextView"/>
</FrameLayout>

Widget.java

package com.dysign.livetubecountdown;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.widget.RemoteViews;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

public class Widget extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerClass(context, appWidgetManager), 1, 1000);
    }

    private class TimerClass extends TimerTask {
        RemoteViews remoteViews;
        AppWidgetManager appWidgetManager;
        ComponentName thisWidget;
        DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());

        public TimerClass(Context context, AppWidgetManager appWidgetManager) {
            this.appWidgetManager = appWidgetManager;
            remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_main);
            thisWidget = new ComponentName(context, Widget.class);
        }

        @Override
        public void run() {
            remoteViews.setTextViewText(R.id.widgetTextView, "TIME = " +format.format(new Date()));
            appWidgetManager.updateAppWidget(thisWidget, remoteViews);
        }
    }
}

我一直在寻找所有网站上,试图解决这个问题,但每一个建议我尝试是行不通的。还有一些在LogCat中没有任何错误或任何提及任何相关的部件。

I've been looking all over the web to try to fix this, but every suggestion I try just doesn't work. Also there are no errors in LogCat or any mention of anything widget related.

任何帮助很多AP preciated,谢谢!

Any help is much appreciated, thanks!

推荐答案

原来,这个问题是在表现一个错字。

The problem turned out to be a typo in the manifest.

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

应在已

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

注意android.appwidget后面的逗号。

Notice the comma after android.appwidget.

这篇关于小部件窗口小部件列表不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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