Android AppWidget 在重新启动之前不会显示在蜂窝菜单中

发布于 2024-11-07 19:00:10 字数 152 浏览 0 评论 0原文

我已经为 Honeycomb 创建了一个 AppWidget,它运行良好,但首次安装时,它不会显示在“Widgets”菜单中,因此无法将其添加到主屏幕。重新启动设备将使其显示,或者在开发过程中,从 Eclipse 发送两次将使其显示。

有什么想法吗?

谢谢!

I have created an AppWidget for Honeycomb which is working well, except that when first installed, it does not show up in the Widgets menu so it can not be added to a home screen. Rebooting the device will allow it to show up, or during development, sending it twice from Eclipse will cause it to show up.

Any ideas?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

国际总奸 2024-11-14 19:00:10

显然 EboMike 是对的,设置 android:installLocation="internalOnly" 确实解决了这个问题。如果没有指定安装位置,它应该默认为internalOnly,但似乎不适合我。也许蜂巢发生了一些变化?

另外,即使设置了internalOnly,从 Eclipse 安装时我仍然遇到问题(小部件直到第二次运行才会显示在选择菜单中),但从 android 市场安装时,它似乎工作正常,这是我的专业忧虑。

谢谢!

Appearently EboMike was right, setting android:installLocation="internalOnly" did fix the issue. Without specifying an install location, it should have defaulted to internalOnly, but did not seem to for me. Perhaps something changed in Honeycomb?

Also, even with internalOnly set, I was still seeing the issue when installing from Eclipse (widget would not show up in the selection menu until the second run) but when installing from the android market, it seems to be working fine which was my major concern.

Thanks!

娜些时光,永不杰束 2024-11-14 19:00:10

其原因实际上已描述此处,它是从 Android 3.1 开始设计的。默认情况下,installLocation 已设置为“internalOnly”,因此不应解决问题,也不应重新启动。

要解决此问题,需要在您的小部件中触发一个活动。这将激活它,然后它将出现在小部件列表中。

为此,您可以添加一个基本上不执行任何操作的活动:

1)在 AndroidManifest.xml 中,将其添加到“application”标签中:

<activity
    android:name=".DummyActivity"
    android:label="@string/app_name">
    <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 
        <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity>

2)然后在“src”中创建一个“DummyActivity.java”类,如下所示现在

package com.domain.app;
import android.app.Activity;
import android.os.Bundle;
public class DummyActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        finish();
    }
}

,当您将小部件部署到设备时,该活动将自动启动(您将在 Eclipse 控制台中看到一条消息“正在启动活动...”),并且它将立即“完成”,而不显示任何视觉内容在设备上。现在您的小部件将列在小部件列表中!

The reason for this is actually described here and it is by design as of Android 3.1. By default, the installLocation will already be set to "internalOnly" so that should not fix the problem and neither should a reboot.

To work around this, an activity needs to be triggered in your widget. This will activate it and it will then appear in the widget list.

To do this, you can add an activity that essentially does nothing like this:

1) In your AndroidManifest.xml, add this inside your "application" tag:

<activity
    android:name=".DummyActivity"
    android:label="@string/app_name">
    <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 
        <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity>

2) Then create a "DummyActivity.java" class in your "src" like this:

package com.domain.app;
import android.app.Activity;
import android.os.Bundle;
public class DummyActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        finish();
    }
}

Now, when you deploy the widget to your device, that activity will be launched automatically (you'll see a message in your Eclipse console saying "starting activity ...") and it will immediately "finish" without showing anything visual on the device. And now your widget will be listed in the widget list!

下雨或天晴 2024-11-14 19:00:10

诡异的是,

我做了这个 installLocation 修复,第一次就成功了。

但从那时起,每次我用 3.01 更新 Xoom 上的小部件时,我仍然需要重新启动才能在列表中看到它。

Spooky,

I did this installLocation fix and it worked first time.

But from then on I still have to reboot every time I update my widget on my Xoom with 3.01 to see it in the list.

神妖 2024-11-14 19:00:10

为了用我的小部件解决这个问题,我发送小部件更新广播,就像在我的 WidgetController.class 中一样:

Intent intent = new Intent();
intent.setClassName(context, context.getPackageName() + ".WidgetProvider");
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,
        getWidgetIds(context));
context.sendBroadcast(intent);

然后为了在系统中提供稳定的小部件初始化,我在应用程序或小部件启动时从应用程序对象发送此广播:

public class MyApp extends Application {

    @Override
    public void onCreate() {

        WidgetController.getInstance().updateWidget(getApplicationContext());
    }
}

!!!重要提示:当 AppWidget 托管在应用程序中时就足够了,但是当 AppWidget 与应用程序分离时,您应该使用本主题中上面@John 提出的方法。

To solve this problem with my widget I send widget update broadcast, like this in my WidgetController.class:

Intent intent = new Intent();
intent.setClassName(context, context.getPackageName() + ".WidgetProvider");
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,
        getWidgetIds(context));
context.sendBroadcast(intent);

then to provide stable widget initialization in the system I send this broadcast from Application object when application or widget start:

public class MyApp extends Application {

    @Override
    public void onCreate() {

        WidgetController.getInstance().updateWidget(getApplicationContext());
    }
}

!!! Important: when AppWidget hosts in application it's enough, but when AppWidget separated from it you should use way proposed by @John above in this topic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文