I have a music player which plays music using a service,all the broadcast receivers within that service are defined inside the service and not externally.
I am totally new to widgets so i had been seeing a few tutorials.But they didn't help me much I am totally new to pending intents soo.I am so confused right now please help me out... All i want to do is just trigger the broadcast inside the service using the button of the widget ...
Here is the copy pasted code which i had been trying to understand
RemoteViews controlButtons = new RemoteViews(context.getPackageName(),
R.layout.widget);
Intent playIntent = new Intent(context, Music_service.class);
PendingIntent playPendingIntent = PendingIntent.getService(
context, REQUEST_CODE, playIntent, INTENT_FLAGS);
controlButtons.setOnClickPendingIntent(
R.id.bPlay, playPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, controlButtons);
And here is my app :D
Create a
custom Intent Action
and set it asPendingIntent
to thewidget
item ( button in your case)Then, change your manifest to handle the
Action
passed inPendingIntent
Finally , when the play button is clicked , the
Service
will receive theAction
and started. Check for theAction
inonStartCommand
You can set similar custom
Actions
for all the required views in theWidget
.See the compile code here https://gist.github.com/androidbensin/4a9f044ac0b3110c049e
Hope your are good now. Let me know if any issues