【问题标题】:Widget not showing in Android >= 4.2.2小部件未在 Android >= 4.2.2 中显示
【发布时间】:2014-02-16 06:31:56
【问题描述】:

我已经在 stackoverflow 上阅读了这个 thread 和其他一些内容,但我的问题似乎还没有解决。

下面是我的代码中的一个 sn-p:(清单文件.xml)

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

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

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".WidgetExampleActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

                <action android:name="com.eightbitcloud.example.widget.ACTION_WIDGET_CONFIGURE" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".ExampleAppWidgetProvider"
            android:label="@string/widget1name" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="com.eightbitcloud.example.widget.ACTION_WIDGET_RECEIVER" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/widget1_info" />
        </receiver>
    </application>

</manifest>

还有:MainActivity.java 作为 WidgetExampleActivity.java

public class WidgetExampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
        setContentView(R.layout.main);
    }
}

和/res/xml/widget_info.xml

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

问题是小部件出现在 android 版本 =4.2 上。我之所以知道这一点,是因为我在不同的设备上对其进行了测试。请问这个问题怎么解决。

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    您将 android OS 的上限设置为 api 级别 11.. 将其设置为 19 以将其余的 android OS 目标设置为 4.x

    【讨论】:

      猜你喜欢
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多