Android Location service - Click on text in Widget to open app

save.png Download source code

You can listen for a onclick on a textView by adding it to the onUpdate method.

First we specify the design file shortcuts_widget.
Then we listen for onClick on the textView textViewOpenApp.

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        // There may be multiple widgets active, so update all of them
        for (int appWidgetId : appWidgetIds) {

            // Onclick listener
            Intent intent = new Intent(context, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.shortcuts_widget); // design file
            views.setOnClickPendingIntent(, pendingIntent);
            appWidgetManager.updateAppWidget(appWidgetId, views);

            // Update widget
            updateAppWidget(context, appWidgetManager, appWidgetId);

Add comment






No comments yet. You can be the first one to comment. Just write your comment in the form and click on the submit button.