How to connect an android widget to my android application? both are my Android applications

∥☆過路亽.° 提交于 2019-12-08 07:16:28
Rahul

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);

And also See this question Launching activity from widget

The activity that you are trying to call needs to be public (exported) in the manifest of its app. There is nothing special about starting activities from a widget, other than the fact that you use a PendingIntent to allow the widget to work as a part of your app (it runs inside the launcher app).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!