我想在通知通知提示时从广播接收器运行javascript函数。接收者已在清单文件中注册。动态注册将不起作用。这样的接收器类是静态的,因此我无法在MainActivity中访问webview以便返回webview.onloadUrl(js函数)。有谁知道如何解决这个问题?
Intent displayIntent = new Intent(this, DisplayReceiver.class);
displayIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
displayIntent.putExtra("anomaly_array", (Serializable) geoList);
displayPendingIntent = PendingIntent.getService(this, 0, displayIntent, 0);
mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
...
.setContentIntent(displayPendingIntent);
DisplayReceiver是MainActivity的内部类,我需要在onReceive中运行webview
public static class DisplayReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
....
webView.loadUrl(urlBuilder.toString());