3

I tried to create clickable widget on android. I was looking for solution on this site and I found it, but finally this widget is working only on the emulator - not on real phone. This is my code:

AppWidgetProvider:

public static String WIDGET_BUTTON = "apps.test.widget.WIDGET_BUTTON";

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    RemoteViews views = new RemoteViews(context.getPackageName(),
            R.layout.main);

    Intent clickIntent = new Intent(WIDGET_BUTTON);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
            clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.imageView1, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetIds, views);
}

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    if (WIDGET_BUTTON.equals(intent.getAction())) {
        Toast.makeText(context, "asdfsdgdasfg", Toast.LENGTH_SHORT).show();

    }
}

Manifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/image"
    android:label="@string/app_name" >
    <receiver
        android:name=".Widget"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            <action android:name="apps.test.widget.WIDGET_BUTTON"/>
        </intent-filter>

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

Toast is showing up on the emulator but not on phone.

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
03Lonnger
  • 31
  • 2

2 Answers2

0

Ok, nevermind. I had to reset the phone to factory settings. I don't know what was wrong.

03Lonnger
  • 31
  • 2
0

This is a common issue,had it a few times with my phone , if the app is installed on sdcard instead of internal storage ,the widget does not appear on the list, you can simply go to Settings->apps->find the app and then select the option to move it to internal storage from your android itself.

[http://www.technipages.com/fix-android-app-widgets-not-appearing-on-widget-list][1] There is another way to declare in the manifest as android:externalstorage(syntax isnt correct) which works as well (I cant find the link though to the answer and I have not tried it)

Sam M.
  • 3
  • 3