Created
September 23, 2019 11:29
-
-
Save DiganVaghasiya/e152ac446ab3fdcaad62e6d0fa5249ca to your computer and use it in GitHub Desktop.
MyWidget receiver class file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyWidget extends AppWidgetProvider { | |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | |
final int N = appWidgetIds.length; | |
Log.e("Updating widgets " , Arrays.asList(appWidgetIds)+” ”); | |
for (int i = 0; i < N; i++) { | |
int appWidgetId = appWidgetIds[i]; | |
String url = "https://www.vasundharavision.com/"; | |
Intent intent = new Intent(Intent.ACTION_VIEW); | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
intent.setData(Uri.parse(url)); | |
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); | |
// attach an on-click listener | |
// to the button | |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget); | |
views.setOnClickPendingIntent(R.id.btn, pendingIntent); | |
// To update a textview | |
views.setTextViewText(R.id.txtWidget, "Vasundhara Vision"); | |
appWidgetManager.updateAppWidget(appWidgetId, views); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment