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

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

问题描述

我有我对Android 2.1系统创建了一个小工具,一直很好,卖在市场上。

我有一个用户抱怨说,他买了它,它从未显示出了他的Andr​​oid 4.0设备上。

我装了4.0模拟器,从Eclipse中运行它,它报告了安装成功,事实上我可以看到它在窗口小部件preVIEW程序上市,我可以在它上面运行,它似乎不错,但它并没有在窗口小部件出现在任何地方 - 我不能真正找到它将其拖动到主屏幕!我想这是同样的事情,用户看到的。

任何想法是怎么回事? 为什么罚款2.1,但不会在4.0列表中显示出来,即使安装成功?

这是我的布局\ widget.xml文件,如果这是任何帮助:

 < RelativeLayout的机器人:ID =@ + ID / relativeLayout1机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT的xmlns:机器人=HTTP://模式.android.com / APK / RES / Android的>
    < TextView的Andr​​oid的:layout_width =WRAP_CONTENT机器人:ID =@ + ID / blankspot机器人:layout_height =5DP安卓重力=中心的Andr​​oid版本:shadowDy =1机器人:shadowDx =1机器人:layout_centerHorizo​​ntal =真正的>< / TextView的>
    < ImageButton的机器人:layout_below =@ + ID / blankspot机器人:layout_width =60dp机器人:layout_height =60dp机器人:ID =@ + ID / widgetIconButton机器人:layout_centerHorizo​​ntal =真正的机器人:scaleType = centerCrop机器人:SRC =@可绘制/ volumeprofilesplus机器人:背景=@空>< / ImageButton的>
    < ImageView的机器人:layout_width =60dp机器人:layout_height =20dp机器人:ID =@ + ID /覆盖机器人:layout_centerHorizo​​ntal =真正的机器人:layout_centerVertical =真正的机器人:scaleType =fitXY机器人:后台=@空机器人:SRC =@可绘制/ overredcaps机器人:知名度=隐形>< / ImageView的>
    < ImageButton的机器人:layout_below =@ + ID / widgetIconButton机器人:layout_width =70dp机器人:layout_height =30dp机器人:ID =@ + ID / widgetSettingsButton机器人:layout_centerHorizo​​ntal =真正的机器人:scaleType = fitXY机器人:SRC =@可绘制/设置机器人:背景=@空>< / ImageButton的>
< / RelativeLayout的>
 

和XML \ widget_provider.xml:

 < XML版本=1.0编码=UTF-8&GT?;
< appwidget提供商
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:=了minWidth72dip
    机器人:=了minHeight72dip
    机器人:updatePeriodMillis =0
    机器人:initialLayout =@布局/主>
< / appwidget提供者>
 

解决方案

因此​​,这里是我想出了解决办法:

您需要将出现在发射活动。所以首先我们有叶奥尔德部件接收,像这样:

 <接收机器人:VolumeProfilesWidget名称=机器人:标签=@字符串/ APP_NAME>
    <意向滤光器>
        <作用机器人:名称=android.appwidget.action.APPWIDGET_UPDATE/>
        <! - 广播接收器也将处理我们的自我创造的行动 - >
        <作用机器人:名称=net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_RECEIVER/>
    &所述; /意图滤光器>
    <元数据的android:NAME =android.appwidget.provider安卓资源=@ XML / volumeprofiles_widget_provider/>
< /接收器>
 

然后我们需要一些活动,主要和LAUNCHER集:

 <活动机器人:名称=。MainActivity
          机器人:标签=@字符串/ APP_NAME>
    <意向滤光器>
        <作用机器人:名称=android.intent.action.MAIN/>
        <类机器人:名称=android.intent.category.LAUNCHER/>
        <作用机器人:名称=net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_CONFIGURE/>
    &所述; /意图滤光器>
< /活性GT;
 

据我可以告诉你必须这样做,即使你的小部件正好应该是一个纯粹的小部件,没有相关活动。最起码,使该启动一个屏幕,上面写着一个虚拟活动你的小工具现在已经可以使用了!下部件寻找它并将其拖动到您的主屏幕!

在我的情况,我的小部件发起了一个活动,当你按下它,所以我做了该活动进入LAUNCHER /主,只是增加了一个一次性的弹出对话框,基本上说:你可以跑这是一个应用程序,但你可能要使用插件代替

请注意,在4.0模拟器,我从来没有让我的小窗口显示在第一次安装在此之前的变化。只要有一个活动设置为MAIN和LAUNCHER似乎足以让小部件显示出来。

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

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

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.

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?

This is my layout\widget.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>

And the xml\widget_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>

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>

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!"

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".

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.

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

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