简体   繁体   English

小部件未在Android 4.0+中显示

[英]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. 我在这里有一个基本的时钟小部件,它在4.0以下的android版本上可以正常工作,您可以长按,选择小部件及其右侧。 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. 但是,当我尝试在4.0或更高版本的模拟器或真实设备上运行它时,它不会仅在“设置”>“存储”>“应用”中的“小部件”部分中显示。 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? 我尝试添加一个简单的活动,该活动仅向用户提供有关如何安装小部件的指导,该建议在此处给出了答案: Android 4.0:小部件未出现? . 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. 在您的manifest.xml中添加以下内容。 "android:exported="true". it might help. try it. “ android:exported =” true“。可能会有所帮助。尝试一下。

在小部件元数据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. 看来您受到安全升级的打击,我认为这是在HoneyComb中发生的。

Basically, in newer versions of Android, you cannot have your widget working, without first launching an Activity . 基本上,在较新的Android版本中,您必须先启动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: 有关更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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