0

I am trying to create a widget for my application, I implemented widget using

File->New->widget->Appwidget

all the corresponding code was auto-generated, but when I run my app, the widget is not shown, can anyone help me on how do I show the widget on my home screen.

my manifest file

<?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>
Amrutha Saj
  • 1,408
  • 16
  • 35

2 Answers2

2

hi please check that code

<?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>

In your code there is one default launcher but when you create a widget no need to launcher

0

The code is working fine.

The thing that helped me was rebooting my phone, after that the widget started appearing in the widget list.

refer Widget not showing in widget list

refer this to get widget on the homescreen How to add a widget to the Android home screen from my app?

Amrutha Saj
  • 1,408
  • 16
  • 35