I would like to create a pending intent for my app widget view that will launch a sharing intent. The problem is that there is no reference to any activity in the android.appwidget.AppWidgetProvider class. The code below does not work because I don’t have access to the MainMenuActivity class. Any ideas, is this even possible?
Intent shareIntent = ShareCompat.IntentBuilder.from(MainMenuActivity.this)
.setText("Some text")
.setType("text/plain")
.getIntent();
PendingIntent actionPendingIntent = PendingIntent.getActivity(context, 0, shareIntent, 0);
views.setOnClickPendingIntent(R.id.widget_layout, actionPendingIntent);
Pass in the
Contextsupplied as a parameter to youronUpdate()method to thefrom()method onShareCompat.IntentBuilder.UPDATE
Sorry, it looks like
ShareCompat.IntentBuilderwill only work withActivity, not a genericContextlike most other things in Android. Hence, you will not be able to use it from an app widget.