如何在Android开放的窗口小部件的应用程序?部件、应用程序、窗口、如何在

2023-09-04 06:47:26 作者:手提感情刀

当我们单击窗口小部件在那个时候我需要打开一个活动的屏幕(或应用程序)。如何做到这一点?

when we click the widget at that time i need to open a activity screen(or application).How to do this?

推荐答案

您需要在您的小部件设置onClickpendingIntent

You need to set an onClickpendingIntent on your widget

Intent intent = new Intent(context, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener to the button
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.appwidget_provider_layout);
views.setOnClickPendingIntent(R.id.button, pendingIntent);

检查了这一点

Check this out

Processing多个按钮点击,在Android部件