Reputation: 93
I can make an app that shows the prayer time. I want that is also shows the time on the widget can any one tell me I can make widget and now the problem is how to send data on the widget I totally confused how to send time on the widget?/
Upvotes: 0
Views: 103
Reputation: 86
try this may be it will help you
public void onReceive(Context context, Intent intent) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget);
Intent intent = new Intent();
if (intent.getAction().equals(
Constants.ACTION_WIDGET_UPDATE_FROM_ACTIVITY)) {
String widgetText = intent.getExtras().getString(
Constants.INTENT_EXTRA_WIDGET_TEXT);
remoteViews.setTextViewText(R.id.word_text, widgetText);
} else {
remoteViews.setTextViewText(R.id.word_text, showPrayer);
}
` }
Upvotes: 1
Reputation: 95
Write this code in your widget appwidgetprovider
public void onReceive(Context context, Intent intent) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget);
Intent intent = new Intent();
if (intent.getAction().equals(
Constants.ACTION_WIDGET_UPDATE_FROM_ACTIVITY)) {
String widgetText = intent.getExtras().getString(
Constants.INTENT_EXTRA_WIDGET_TEXT);
remoteViews.setTextViewText(R.id.word_text, widgetText);
} else {
remoteViews.setTextViewText(R.id.word_text, showPrayer);
}
` }
Upvotes: 1
Reputation: 6738
Try this code in your activity....
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
AppWidgetManager appWidgetManager = AppWidgetManager
.getInstance(context);
RemoteViews remoteViews = new RemoteViews(context
.getPackageName(), R.layout.widget_layout);
remoteViews.setTextViewText(R.id.txt_time, ""
+ YOURTIME);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
setResult(RESULT_OK, resultValue);
}
Upvotes: 0