Android 4.0:小部件没有出现? [英] Android 4.0: widgets not appearing?

查看:27
本文介绍了Android 4.0:小部件没有出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个针对 Android 2.1 创建的小部件,效果很好并且在市场上销售.

I have a widget I created against Android 2.1 that's been fine and selling on the market.

我有一个用户抱怨他买了它,但它从来没有出现在他的 Android 4.0 设备上.

I had a user complain that he bought it and it never showed up on his Android 4.0 device.

我加载了 4.0 模拟器,从 Eclipse 运行它,它报告安装成功,事实上我可以看到它列在Widget Preview"应用程序中,我可以在那里运行它,看起来很好,但它没有不会出现在小部件"下的任何地方——我实际上找不到将它拖到主屏幕的地方!我认为这与用户看到的相同.

I loaded up the 4.0 emulator, ran it from Eclipse, it reported a successful installation and in fact I can see it listed in the "Widget Preview" app, and I can run it there and it seems fine, but it doesn't show up anywhere under "Widgets" -- I can't actually find it to drag it to the home screen! I assume this is the same thing the user is seeing.

知道这里发生了什么吗?为什么它在 2.1 中很好,但在 4.0 的列表中没有显示,即使在成功安装后?

Any idea what's going on here? Why is it fine in 2.1 but doesn't show up in the list on 4.0, even after a successful install?

这是我的 layoutwidget.xml 文件,如果有帮助的话:

This is my layoutwidget.xml file, if that's any help:

<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:layout_width="wrap_content" android:id="@+id/blankspot" android:layout_height="5dp" android:gravity="center" android:shadowDy="1" android:shadowDx="1" android:layout_centerHorizontal="true"></TextView> 
    <ImageButton android:layout_below="@+id/blankspot" android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/widgetIconButton" android:layout_centerHorizontal="true" android:scaleType="centerCrop" android:src="@drawable/volumeprofilesplus" android:background="@null"></ImageButton>
    <ImageView android:layout_width="60dp" android:layout_height="20dp" android:id="@+id/override" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:scaleType="fitXY" android:background="@null" android:src="@drawable/overredcaps" android:visibility="invisible"></ImageView>
    <ImageButton android:layout_below="@+id/widgetIconButton" android:layout_width="70dp" android:layout_height="30dp" android:id="@+id/widgetSettingsButton" android:layout_centerHorizontal="true" android:scaleType="fitXY" android:src="@drawable/settings" android:background="@null"></ImageButton>
</RelativeLayout>

还有 xmlwidget_provider.xml:

And the xmlwidget_provider.xml:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="72dip"
    android:minHeight="72dip"
    android:updatePeriodMillis="0"
    android:initialLayout="@layout/main" >    
</appwidget-provider>

推荐答案

所以这是我想出的解决方案:

So here's the solution I came up with:

您需要一个会出现在启动器上的活动.所以首先我们有你旧的小部件接收器,就像这样:

You need an activity that will appear on the launcher. So first we have ye olde widget receiver, like so:

<receiver android:name=".VolumeProfilesWidget" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />                
        <!-- Broadcast Receiver that will also process our self created action -->
        <action android:name="net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_RECEIVER"/>               
    </intent-filter>
    <meta-data android:name="android.appwidget.provider" android:resource="@xml/volumeprofiles_widget_provider" />
</receiver>

然后我们需要一些活动,设置 MAIN 和 LAUNCHER:

And then we need some activity, with the MAIN and LAUNCHER set:

<activity android:name=".MainActivity"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />                
        <action android:name="net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_CONFIGURE"/>
    </intent-filter>
</activity>

据我所知,即使您的小部件只是一个没有关联活动的纯小部件,也必须这样做.至少,创建一个虚拟 Activity 来启动一个屏幕,上面写着您的小部件现在可以使用了!在小部件下寻找它并将其拖到您的主屏幕上!"

As far as I can tell you MUST do this even if your widget is just supposed to be a pure widget with no associated activities. At the very least, make one dummy activity that launches a screen that says "Your widget is now ready for use! Look for it under widgets and drag it to your home screen!"

就我而言,我的小部件在您推送它时启动了一个活动,因此我将该活动设置为 LAUNCHER/MAIN 并添加了一个一次性弹出对话框,基本上说您可以将其作为应用程序运行,但您可能想要改为使用小部件".

In my case, my widget launched an activity when you pushed it, so I made that activity into LAUNCHER/MAIN and just added a one-time popup dialog that basically says "you can run this as an application but you may want to use the widget instead".

请注意,在 4.0 模拟器上,在此更改之前,我从未让我的小部件在第一次安装时显示.只需将活动设置为 MAIN 和 LAUNCHER 似乎就足以让小部件显示出来.

Note that on the 4.0 emulator, I was never getting my widget to show up on a first time install prior to this change. Simply having an activity set to MAIN and LAUNCHER seemed to be enough to make the widget show up.

这篇关于Android 4.0:小部件没有出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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