将传入URL的推送通知重定向到WebView页面中具有接收者主动性的页面,我想在此页面上打开URL。
但他通过指导浏览器在接收器中打开页面来完成当前项目。如果你能提供帮助,我将不胜感激。
我通过推送提交的JSON数据:
{
"alert": "Push bildirimi",
"badge": "Increment",
"uri": "http://www.google.com.tr"
}
Receiver.java
import android.app.Activity;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import com.parse.ParseAnalytics;
import com.parse.ParsePushBroadcastReceiver;
import org.json.JSONException;
import org.json.JSONObject;
public class Receiver extends ParsePushBroadcastReceiver {
// public MainActivity anasayfa;
/*public Receiver(WebView webview) {
this.webview = webview;
}*/
@Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
ParseAnalytics.trackAppOpenedInBackground(intent);
// Anlik Bildirim acildiginda MainActivity'imizi baslatiyoruz.
Log.d("msg_info", "onPushOpen");
String uriString = null;
try {
Log.d("msg_info", "icerdeyim");
JSONObject pushData = new JSONObject(intent.getStringExtra("com.parse.Data"));
uriString = pushData.optString("uri");
} catch (JSONException e) {
Log.v("com.parse.ParsePushReceiver", "Unexpected JSONException when receiving push data: ", e);
}
Class<? extends Activity> cls = getActivity(context, intent);
Intent activityIntent;
if (uriString != null && !uriString.isEmpty()) {
activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
} else {
activityIntent = new Intent(context, MainActivity.class);
}
activityIntent.putExtras(intent.getExtras());
if (Build.VERSION.SDK_INT >= 22) {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(cls);
stackBuilder.addNextIntent(activityIntent);
stackBuilder.startActivities();
} else {
activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(activityIntent);
}
}
}
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.computer.bildirimler.R;
/*import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;*/
public class MainActivity extends Activity {
public WebView webView;
private String uri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView)findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
//webView.getSettings().setJavaScriptEnabled(true);
Log.d("msg_info", "haber yükleniyor");
webView.loadUrl(uri);
}
}