【问题标题】:Widget not showing up android小部件不显示android
【发布时间】:2017-09-20 06:41:02
【问题描述】:

我正在尝试为我的应用程序创建一个小部件, 我使用

实现了小部件
File->New->widget->Appwidget

所有对应的代码都是自动生成的, 但是当我运行我的应用程序时,没有显示小部件,任何人都可以帮助我如何在我的主屏幕上显示小部件。

我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.work.income">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:installLocation="preferExternal"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".AddExpenseActivity" />
    <activity android:name=".AddIncomeActivity" />
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_login" />

    <receiver android:name=".NewAppWidget"
      >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

        <meta-data
            android:name="android.appwidget.provider"

            android:resource="@xml/new_app_widget_info" />
    </receiver>
</application>

</manifest>

【问题讨论】:

  • 您检查过您的主屏幕 -> 小部件吗?
  • @AndersKink 是的,我检查过了,没有显示

标签: android android-widget


【解决方案1】:

您好,请检查该代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.sairamkrishna.myapplication" >

   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
      <receiver android:name=".MainActivity">

      <intent-filter>
         <action android:name="android.appwidget.action.APPWIDGET_UPDATE"></action>
      </intent-filter>

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

      </receiver>

   </application>
</manifest>

在您的代码中有一个默认启动器,但是当您创建小部件时不需要启动器

【讨论】:

  • 我还是一头雾水,能否请教一下这个问题,我的启动器活动在“LoginActivity”中,我应该在哪里进行更改
  • 如何触发小部件以便在我的主屏幕上显示它
  • 我在这个话题和项目上完全可以帮助你,而且我的英语不好
  • 没关系。我只想解决我的问题,请帮助我
  • 你能解释一下你的项目的工作吗?我的意思是你的项目流程是什么
【解决方案2】:

代码运行良好。

帮助我的事情是重新启动手机,然后小部件开始出现在小部件列表中。

参考Widget not showing in widget list

参考这个来获取主屏幕上的小部件How to add a widget to the Android home screen from my app?

【讨论】:

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