【问题标题】:Embed widget in android activity - not responding在android活动中嵌入小部件 - 没有响应
【发布时间】:2011-07-23 22:56:35
【问题描述】:

我正在尝试制作主屏幕。我有要显示的小部件,但我需要向它发送某种通知,以便它启动。也许我在AndroidManifest.xml 中遗漏了什么?

AndroidManifest.xml:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.Fredrik" android:versionCode="1" android:versionName="1.0">
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HomeScreen" android:label="@string/app_name"
            android:launchMode="singleInstance" android:stateNotNeeded="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>
</manifest>

HomeScreen.java:

public class HomeScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final AppWidgetManager widgets = AppWidgetManager
            .getInstance(getApplicationContext());
    List<AppWidgetProviderInfo> installedProviders = widgets
            .getInstalledProviders();
    for (AppWidgetProviderInfo ws : installedProviders) {
        if (ws.label.startsWith("Music (Large)")) {
            AppWidgetHost h = new AppWidgetHost(getApplicationContext(), 10);
            int id = h.allocateAppWidgetId();
            AppWidgetHostView  v= h.createView(this, id, ws);
            setContentView(v);
            h.startListening();
            break;
        }
    }
}

}

有人知道吗?

【问题讨论】:

    标签: android android-activity android-widget


    【解决方案1】:

    根据这篇文章,你不能自己编程小部件插入:http://groups.google.com/group/android-developers/browse_thread/thread/e4a5b4a87afcf707?pli=1

    你必须调用一个让用户能够选择的意图。

    听到你设法让它显示,我仍然感到惊讶......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多