Send notification of incoming URLs to the page with the main activity of the recipient on the WebView page, and I want to open the URL on this page.
But he did the current project, directing the browser, opening the page in the receiver. I would be grateful if you could help.
JSON data that I send via push:
{
"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 {
@Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
ParseAnalytics.trackAppOpenedInBackground(intent);
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;
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());
Log.d("msg_info", "haber yΓΌkleniyor");
webView.loadUrl(uri);
}
}
source
share