Hello if you will not use "title" and "alert" key in your jsonObject then it will not create the by default notification in notification bar.I was able to made a custom notification instead of by default.
You can see my code and change the custom notification code from the alert dialog code.Take a look:
Code to send notification:
String otherChannelName = "channel" + user_id;
// send push notfication
String str_objid = PreferenceSetting.getObjId(mActivity);
String str_uname = PreferenceSetting.getUName(mActivity);
ParsePush push = new ParsePush();
push.setChannel(otherChannelName);
push.setMessage(message);
JSONObject data = null;
try {
data = new JSONObject("{\"action\": \""
+ NChatActivity.BUDDY_CHAT_PUSH_ACTION + "\"" + ",\"from\": \""
+ str_objid + "\"" + ",\"to\": \"" + user_id
+ "\"" + ",\"a\" : \"" + message + "\""
+ ",\"t\" : \"" + type + "\"" + "}");
} catch (JSONException e) {
e.printStackTrace();
}
push.setData(data);
push.sendInBackground();
Code to receive notification :
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle extras = intent.getExtras();
String message = extras != null ? extras.getString("com.parse.Data")
: "";
String channel = extras.getString("com.parse.Channel");
JSONObject jObject = null;
try {
if (message != null && !message.equals("")) {
jObject = new JSONObject(message);
from = jObject.getString("from");
messageText = jObject.getString("a");
type = jObject.getString("t");
}
}
catch (JSONException e) {
e.printStackTrace();
}
ActivityManager am =(ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE);
List < ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if(componentInfo.getPackageName().equalsIgnoreCase("com.pappchat"))
{
if (type.equals("Papp App")) {
if(taskInfo.get(0).topActivity.getClassName().equals("com.pappchat.NChatActivity"))
{
LoadDataTwo.getfriendInfo(from,context);
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putString("message", messageText);
b.putString("from", from);
msg.setData(b);
if(handler.sendMessage(msg)){
Log.d(TAG, "send message successfully");
}else{
Log.d(TAG, "unable to send message.");
}
}
else
{
notify(context,intent,jObject);
}
}
Here I have made custom notification in the method named notify(context,intent,jObject) You can make alert dialog in this method(when the app will be in background).
Take a look on this link ,may be useful for you : automatically-open-an-activity-without-user-action for notification