简体   繁体   中英

Widgets not showing in Android 4.0+

I have a basic clock widget here, it works just fine on versions of android below 4.0, you can long press, select widgets and its right there. But when i try to run it on 4.0 or later emulator or real device, it does not show up in widgets section only in Settings>Storage>Apps. I have tried adding a simple activity that just gives users directions on how to install the widget , that suggestion was given as an answer here: Android 4.0: widgets not appearing? . Unless i did it wrong the widget still does not show up in widget drawer.

Here is my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.widgetexample1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="14" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
       <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" />                
        </intent-filter>
    </activity>
        <receiver android:name=".ExampleAppWidgetProvider"
            android:label="8-bit cloud widget 1">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

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

</manifest>

add below in your manifest.xml. "android:exported="true". it might help. try it.

在小部件元数据xml文件中,选中标记<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:xmlns属性应以http://开头。

It looks like you are being hit by a security upgrade which I think happened in HoneyComb.

Basically, in newer versions of Android, you cannot have your widget working, without first launching an Activity .

So add an activity to the project, run it first, and I think your widgets will update.

A good example would be to use a Settings style activity, or perhaps and About box type of thing, to tell the user a bit about your widget. (I use settings in my widgets).


For more info:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM