所以我试图设置一个带有列表的窗口小部件,但是单击不起作用,所以我知道要这样做,我需要一个模板暂挂意图,因为单个项不能有自己的意图,然后添加到暂挂意图中使用填充意图的模板,我已经将所有这些添加到我的应用程序中,但是仍然无法正常工作,我遵循了建议here和here,但是当我单击一个项目时,它刚刚突出显示了表示它已经注册了一次点击,但没有执行任何操作,但是我确实在 logcat
08-06 17:02:08.001 2163-3666/? W/Binder: Binder call failed.
java.lang.NullPointerException: Attempt to read from field
'com.android.server.appwidget.AppWidgetServiceImpl$ProviderId
com.android.server.appwidget.AppWidgetServiceImpl$Provider.id'
on a null object reference
at
com.android.server.appwidget.AppWidgetServiceImpl$AppWidgetManagerLocal
.getHostedWidgetPackages(AppWidgetServiceImpl.java:4800)
at
com.android.server.accessibility.AccessibilityManagerService$SecurityPolicy
.resolveValidReportedPackageLocked(AccessibilityManagerService.java:4637)
at com.android.server.accessibility.AccessibilityManagerService
.sendAccessibilityEvent(AccessibilityManagerService.java:531)
at android.view.accessibility.IAccessibilityManager$Stub
.onTransact(IAccessibilityManager.java:71)
at android.os.Binder.execTransact(Binder.java:690)
这是我的代码,我的onUpdate方法调用一个静态更新小部件方法,该方法定义了我的模板待定意图,而我的onReceive方法
AppWidgetProvider
public class MessageMeAppWidget extends AppWidgetProvider {
private static final String TAG = "MsgMeWdgt";
@Override
public void onReceive(Context context, Intent intent) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
if (intent.getAction().equals(Constants.LAUNCH_ACTIVITY)) {
int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
//String recipientId = intent.getStringExtra(Constants.FS_ID);
//String recipientName = intent.getStringExtra(Constants.FS_NAME);
Intent i = new Intent(context, MessageListActivity.class);
Bundle b = new Bundle();
//b.putString(Constants.FS_ID, recipientId);
//b.putString(Constants.FS_ID, recipientName);
i.putExtras(b);
Bundle bundle = intent.getExtras();
String toastText = "position is " + bundle.getInt(Constants.LAUNCH_ACTIVITY);
Toast.makeText(context,toastText,Toast.LENGTH_SHORT).show();
//context.startActivity(i);
}else if(intent.getAction().equals(Constants.DONT_LAUNCH_ACTIVITY)){
//Toast.makeText(context,"",Toast.LENGTH_SHORT).show();
}
super.onReceive(context, intent);
}
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SHARED_PREFS,Context.MODE_PRIVATE);
boolean userSignedIn = sharedPreferences.getBoolean(Constants.SIGNED_IN, false);
if (userSignedIn){
//move everything in here after i know its working
}
Intent intent = new Intent(context, MessagingService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_list_view);
//populates data
remoteViews.setRemoteAdapter(R.id.widget_list,intent);
//remoteViews.setRemoteAdapter(appWidgetId, R.id.widget_list, intent);
remoteViews.setEmptyView(R.id.widget_list,R.id.empty);
Intent launchIntent = new Intent(context, WidgetAdapter.class);
launchIntent.setAction(Constants.LAUNCH_ACTIVITY);
launchIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent launchPendingIntent = PendingIntent.getBroadcast(context, 0, launchIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setPendingIntentTemplate(R.id.widget_list, launchPendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
Log.d(TAG,"on update");
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
然后我的窗口小部件服务是标准的
public class MessagingService extends RemoteViewsService {
private String TAG = "MsgSrvc";
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
Log.d(TAG,"item clicked");
return new WidgetAdapter(this.getApplicationContext(), intent);
}
}
,然后在我的小部件适配器的getViewAt方法中,我这样填写意图
Bundle extras = new Bundle();
extras.putInt(Constants.LAUNCH_ACTIVITY, position);
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
remoteViews.setOnClickFillInIntent(R.id.holder, fillInIntent);
我的清单中正在注册我的窗口小部件服务和接收者
<receiver android:name="com.sealstudios.aimessage.MessageMeAppWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/message_me_app_widget_info" />
</receiver>
<service android:name=".MessagingService"
android:permission="android.permission.BIND_REMOTEVIEWS" />
任何帮助表示赞赏
答案 0 :(得分:0)
我解决了这个问题,因为意图是指向错误的类,所以
for (int i = 0; i < Numara.Items.Count; i++)
{
driveri.Navigate().GoToUrl("https://web.whatsapp.com/send?phone=" + Numara.Items[i].ToString() + "&text=");
Thread.Sleep(3000);
Actions act = new Actions(driveri);
Thread.Sleep(500);
IReadOnlyCollection<IWebElement> rows = driveri.FindElements(By.XPath("//*[@id=\"app\"]/div/span[3]/div/div/div/div/div/div/div[2]/div"));
if (rows == null)
{
...continuation
}
else
{
...if there is an error
rows.ElementAt(0).Click();
}
}
}
应该是
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ESZGDXXXXXXXXX">
<input type="image" src="https://www.paypalobjects.com/en_GB/HK/i/btn/btn_buynowCC_LG_wCUP.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>