I am using Pushe for push notification service. When sending a notification, I can name an activity to get opened when user clicks on it.
I am sending some json content with my notification which contains a link. My problem is that I want to use this link to open an activity (Ex: opening a this link in my custom WebView Activity) I don't know how to do this.
Pushe
does open the activity you want by just naming it in click action of your notification. You also can send a json
with your notification. If you need this json data
in the activity that Pushe library
will open, you can save it in SharedPreferences
and add some code to your activity to get this data from SharedPreferences
. So if for example you want to send a link in json to be used in your WebViewActivity
, you need to add below codes:
In json receiver class:
public class MyPushListener extends PusheListenerService {
@Override
public void onMessageReceived(JSONObject message,JSONObject content){
android.util.Log.i("Pushe","Custom json Message: "+ message.toString());
// Your Code
SharedPreferences.Editor editor = getSharedPreferences("_appname_prefes", MODE_PRIVATE).edit();
editor.putString("url", message.getString("link", null));
editor.commit();
}
}
"link" is the key of your link in the json that you send and "url" is the key for saving it in the SharedPreferences
.
In your WebViewActivity
:
SharedPreferences prefs = getSharedPreferences("_appname_prefes", MODE_PRIVATE);
String url = prefs.getString("url", null);
if (url != null) {
//set this link to ur webview
}else{
//show some default page instead
}