This is my code:
public class SimpleWidgetProvider extends AppWidgetProvider {
BluetoothAdapter mBluetoothAdapter;
String number="";
PendingIntent pendingIntent;
Button b;
//private static final String MyOnClick = "myOnClickTag";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//final int count = appWidgetIds.length;
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, SimpleWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.simple_widget);
views.setOnClickPendingIntent(R.id.actionButton, pendingIntent);
//views.setOnClickPendingIntent(R.id.button1, getPendingSelfIntent(context, MyOnClick));
appWidgetManager.updateAppWidget(appWidgetId, views);
//Toast.makeText(context, "Button Clicked", Toast.LENGTH_SHORT).show();
}
In my widget there is a button (id:actionButton in the layout), what I want is when I click on this button, bluetooth of the device will turn on and app will show a toast. I was working on the toast part for testing at first but unable to do it. How to do this? As you can see I am using pending intents, is it impossible to do what I want? Or there are other ways? Searched the net at first but didn't get the exact solution, so asking for your suggestions.