I have a query ... How can I capture a push notification in a textview or in a list ... here is my code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit = (EditText) findViewById(R.id.edit);
button = (Button) findViewById(R.id.butt);
send = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
token = FirebaseInstanceId.getInstance().getToken();
edit.setText(token);
}
});
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GetDataFromEditText();
SendData(data);
}
});
}
public void GetDataFromEditText(){
data = edit.getText().toString();
Toast.makeText(MainActivity.this,data,Toast.LENGTH_LONG).show();
}
public void SendData(final String token) {
class PostData extends AsyncTask<String,Void,String>{
@Override
protected String doInBackground(String... params) {
String tokenHoldre = token;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
// nameValuePairs.add(new BasicNameValuePair("tokenfirebase", tokenHoldre));
nameValuePairs.add(new BasicNameValuePair("fcm_token", tokenHoldre));
// nameValuePairs.add(new BasicNameValuePair("idcliente", "08366"));
// nameValuePairs.add(new BasicNameValuePair("esregistro", "1"));
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(ServerURL);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return "Success..";
}
protected void onPostExecute(String result) {
super.onPostExecute(result);
Toast.makeText(MainActivity.this, "Success..", Toast.LENGTH_LONG).show();
}
}
PostData sendPostReqAsyncTask = new PostData();
sendPostReqAsyncTask.execute(token);
}
Here is my callback:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getData().size() >0){
type="json";
sendNotificatio(remoteMessage.getData().toString());
}
if(remoteMessage.getNotification() !=null) {
type = "message";
sendNotificatio(remoteMessage.getNotification().getBody());
}
}
private void sendNotificatio(String messageBody) {
String id="";
String message="";
String titles="";
if (type.equals("json")){
try {
JSONObject jsonObject = new JSONObject(messageBody);
id=jsonObject.getString("id");
message=jsonObject.getString("message");
titles= jsonObject.getString("title");
} catch (JSONException e) {
e.printStackTrace();
}
} else if (type.equals("message")) {
message= messageBody;
}