AppWidgetProvider handle touch event problem

萝らか妹 提交于 2019-12-13 07:31:46

问题


i am adding installed AppWidgetViews to my application as AppWidgetHostView. The problem is they don't handle any touch events as they were added to home screen. Here is part of my code;


AppWidgetHost host = new AppWidgetHost(getContext(), HOST_ID);
AppWidgetManager manager = AppWidgetManager.getInstance(getContext());

int id = host.allocateAppWidgetId();
AppWidgetHostView view = host.createView(getContext(), id, info);

Lets say AppWidgetProviderInfo object "info" belongs to "com.android.alarmclock.AnalogAppWidgetProvider", which is the default analog clock widget of android. This view has to launch clock setting when a click performed on it as it performed on home screen, still i have no response from it. Is there a way to solve this problem? Thanks in advance...


回答1:


I am not sure this will answer your question.

To handle onClick event in android homescreen, I use PendingIntent to setOnClick behavior.

Intent iText = new Intent(this, urTargetActivity.class);
PendingIntent pendingText = PendingIntent.getActivity(context,0, iText,0);
views.setOnClickPendingIntent(R.id.textView1,pendingText);

I am not sure about using it with AppWidgetHostView but the way I have done before is using it in the service to call the configuration activity page which is working without any problem.

Hope this could help you somehow :)



来源:https://stackoverflow.com/questions/7514009/appwidgetprovider-handle-touch-event-problem

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