| Line 44... |
Line 44... |
| 44 |
import org.json.JSONException;
|
44 |
import org.json.JSONException;
|
| 45 |
import org.json.JSONObject;
|
45 |
import org.json.JSONObject;
|
| 46 |
|
46 |
|
| 47 |
import java.io.InputStream;
|
47 |
import java.io.InputStream;
|
| 48 |
import java.net.HttpURLConnection;
|
48 |
import java.net.HttpURLConnection;
|
| - |
|
49 |
import java.net.MalformedURLException;
|
| 49 |
import java.net.URL;
|
50 |
import java.net.URL;
|
| 50 |
import java.util.ArrayList;
|
51 |
import java.util.ArrayList;
|
| 51 |
import java.util.Map;
|
52 |
import java.util.Map;
|
| 52 |
|
53 |
|
| 53 |
/**
|
54 |
/**
|
| Line 57... |
Line 58... |
| 57 |
SharedPreferences userData;
|
58 |
SharedPreferences userData;
|
| 58 |
SharedPreferences apiData;
|
59 |
SharedPreferences apiData;
|
| 59 |
MixpanelAPI mixpanel;
|
60 |
MixpanelAPI mixpanel;
|
| 60 |
SharedPreferences.Editor userDataEditor;
|
61 |
SharedPreferences.Editor userDataEditor;
|
| 61 |
SharedPreferences.Editor apiSettingsEditor;
|
62 |
SharedPreferences.Editor apiSettingsEditor;
|
| 62 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
63 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
| 63 |
public static int NOTIFICATION_ID = 1;
|
64 |
public static int NOTIFICATION_ID = 1;
|
| 64 |
private NotificationManager mNotificationManager;
|
65 |
private NotificationManager mNotificationManager;
|
| 65 |
NotificationCompat.Builder builder;
|
66 |
NotificationCompat.Builder builder;
|
| 66 |
SharedPreferences notificationData;
|
67 |
SharedPreferences notificationData;
|
| 67 |
SharedPreferences.Editor notificationDataEditor;
|
68 |
SharedPreferences.Editor notificationDataEditor;
|
| 68 |
private static final String TAG = "MyFirebaseMsgService";
|
69 |
private static final String TAG = "MyFirebaseMsgService";
|
| 69 |
Intent intent;
|
70 |
Intent intent;
|
| 70 |
Bitmap bitmap;
|
71 |
Bitmap bitmap;
|
| 71 |
|
72 |
|
| 72 |
@Override
|
73 |
@Override
|
| 73 |
public void onMessageReceived(RemoteMessage remoteMessage) {
|
74 |
public void onMessageReceived(RemoteMessage remoteMessage) {
|
| 74 |
userData = this.getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
75 |
userData = this.getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
| 75 |
apiData = this.getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
76 |
apiData = this.getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
| Line 148... |
Line 149... |
| 148 |
Log.d("Campaign Id is same " + notificationData.getString("cid", ""), "Campaign Id is same " + extras.get("cid").toString().split("_")[0]);
|
149 |
Log.d("Campaign Id is same " + notificationData.getString("cid", ""), "Campaign Id is same " + extras.get("cid").toString().split("_")[0]);
|
| 149 |
}
|
150 |
}
|
| 150 |
else {
|
151 |
else {
|
| 151 |
notificationDataEditor.putString("cid", extras.get("cid").toString().split("_")[0]);
|
152 |
notificationDataEditor.putString("cid", extras.get("cid").toString().split("_")[0]);
|
| 152 |
notificationDataEditor.commit();
|
153 |
notificationDataEditor.commit();
|
| - |
|
154 |
try {
|
| 153 |
sendNotification(extras.get("message") + "", extras.get("type") + "", extras.get("title") + "", extras.get("url") + "", extras.get("cid") + "", bitmap);
|
155 |
sendNotification(extras.get("message") + "", extras.get("type") + "", extras.get("title") + "", extras.get("url") + "", extras.get("cid") + "", bitmap);
|
| - |
|
156 |
} catch (MalformedURLException e) {
|
| - |
|
157 |
e.printStackTrace();
|
| - |
|
158 |
}
|
| 154 |
}
|
159 |
}
|
| 155 |
} else {
|
160 |
} else {
|
| 156 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
161 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
| 157 |
AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Notification Expired", extras.get("cid") + ""),
|
162 |
AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Notification Expired", extras.get("cid") + ""),
|
| 158 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
163 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
| Line 165... |
Line 170... |
| 165 |
new NotificationRecievedData().execute(nameValuePairsGcm);
|
170 |
new NotificationRecievedData().execute(nameValuePairsGcm);
|
| 166 |
}
|
171 |
}
|
| 167 |
}
|
172 |
}
|
| 168 |
}
|
173 |
}
|
| 169 |
|
174 |
|
| 170 |
private void sendNotification(String msg, String type, String title, String url, String cid, Bitmap image) {
|
175 |
private void sendNotification(String msg, String type, String title, String url, String cid, Bitmap image) throws MalformedURLException {
|
| 171 |
JSONObject propsNotificationRecieved = new JSONObject();
|
176 |
JSONObject propsNotificationRecieved = new JSONObject();
|
| 172 |
Bundle bundle;
|
177 |
Bundle bundle;
|
| 173 |
try {
|
178 |
try {
|
| 174 |
mixpanel.identify(userData.getString("id", null));
|
179 |
mixpanel.identify(userData.getString("id", null));
|
| 175 |
propsNotificationRecieved.put("Screen", "Notification Reached");
|
180 |
propsNotificationRecieved.put("Screen", "Notification Reached");
|
| Line 202... |
Line 207... |
| 202 |
bundle.putString("cid", cid);
|
207 |
bundle.putString("cid", cid);
|
| 203 |
resultIntent.putExtras(bundle);
|
208 |
resultIntent.putExtras(bundle);
|
| 204 |
resultIntent.setAction("20");
|
209 |
resultIntent.setAction("20");
|
| 205 |
|
210 |
|
| 206 |
if (url.isEmpty()) {
|
211 |
if (url.isEmpty()) {
|
| 207 |
resultIntent.setData(Uri.parse(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", "")));
|
212 |
resultIntent.setData(Uri.parse(apiData.getString("app.domain.profitmandi", "app.profitmandi.com")));
|
| 208 |
} else {
|
213 |
} else {
|
| - |
|
214 |
URL urlString = new URL(url);
|
| - |
|
215 |
String domain = urlString.getAuthority();
|
| - |
|
216 |
String path =urlString.getFile();
|
| - |
|
217 |
String protocol=urlString.getProtocol();
|
| - |
|
218 |
String rr=urlString.getRef();
|
| - |
|
219 |
|
| - |
|
220 |
if(domain.equals(apiData.getString("app.domain.profitmandi", "app.profitmandi.com"))){
|
| 209 |
resultIntent.setData(Uri.parse(url));
|
221 |
resultIntent.setData(Uri.parse(url));
|
| - |
|
222 |
}
|
| - |
|
223 |
else{
|
| - |
|
224 |
url=protocol+"://"+(apiData.getString("app.domain.profitmandi", "app.profitmandi.com")) + path;
|
| - |
|
225 |
resultIntent.setData(Uri.parse(url));
|
| - |
|
226 |
}
|
| - |
|
227 |
|
| - |
|
228 |
|
| 210 |
}
|
229 |
}
|
| 211 |
|
230 |
|
| 212 |
} else if (type.equalsIgnoreCase("Update")) {
|
231 |
} else if (type.equalsIgnoreCase("Update")) {
|
| 213 |
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
|
232 |
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
|
| 214 |
try {
|
233 |
try {
|
| Line 398... |
Line 417... |
| 398 |
bundle = new Bundle();
|
417 |
bundle = new Bundle();
|
| 399 |
bundle.putString("cid", cid);
|
418 |
bundle.putString("cid", cid);
|
| 400 |
resultIntent.putExtras(bundle);
|
419 |
resultIntent.putExtras(bundle);
|
| 401 |
resultIntent.setAction("20");
|
420 |
resultIntent.setAction("20");
|
| 402 |
|
421 |
|
| - |
|
422 |
|
| 403 |
if (url.isEmpty()) {
|
423 |
if (url.isEmpty()) {
|
| 404 |
resultIntent.setData(Uri.parse(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", "")));
|
424 |
resultIntent.setData(Uri.parse(apiData.getString("app.domain.profitmandi", "http://app.profitmandi.com")));
|
| 405 |
} else {
|
425 |
} else {
|
| - |
|
426 |
URL urlString = new URL(url);
|
| - |
|
427 |
String domain = urlString.getAuthority();
|
| - |
|
428 |
String path =urlString.getFile();
|
| - |
|
429 |
String protocol=urlString.getProtocol();
|
| - |
|
430 |
String rr=urlString.getRef();
|
| - |
|
431 |
|
| - |
|
432 |
if(domain.equals(apiData.getString("app.domain.profitmandi", "app.profitmandi.com"))){
|
| - |
|
433 |
resultIntent.setData(Uri.parse(url));
|
| - |
|
434 |
}
|
| - |
|
435 |
else{
|
| - |
|
436 |
url=protocol+"://"+(apiData.getString("app.domain.profitmandi", "app.profitmandi.com")) + path;
|
| 406 |
resultIntent.setData(Uri.parse(url));
|
437 |
resultIntent.setData(Uri.parse(url));
|
| - |
|
438 |
}
|
| - |
|
439 |
|
| 407 |
}
|
440 |
}
|
| 408 |
|
441 |
|
| 409 |
} else if (type.equalsIgnoreCase("Update")) {
|
442 |
} else if (type.equalsIgnoreCase("Update")) {
|
| 410 |
final String appPackageName = GoogleAnalyticsTracker.getAppContext().getPackageName();
|
443 |
final String appPackageName = GoogleAnalyticsTracker.getAppContext().getPackageName();
|
| 411 |
try {
|
444 |
try {
|