--- a/app/src/main/java/com/codesys/forge/MyService.java +++ b/app/src/main/java/com/codesys/forge/MyService.java @@ -20,6 +20,7 @@ import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import java.io.BufferedReader; import java.io.IOException; @@ -39,6 +40,7 @@ private Timer mTimer; private boolean mRunning = false; private Context mContext; + String cookies = ""; private void CreateNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -95,7 +97,6 @@ @Override protected String doInBackground(Void... voids) { String urlString = "https://forge.codesys.com/rest/forge/saml"; - String cookies = CookieManager.getInstance().getCookie(urlString); try { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); @@ -115,10 +116,10 @@ stringBuilder.append(line + "\n"); } String news = stringBuilder.toString(); - JSONArray arr = new JSONArray(news); - for (int i=0; i < arr.length(); i++) + JSONObject obj = new JSONObject(news); + for (int i=0; i < obj.getJSONArray("news").length(); i++) { - String uri = arr.getString(i); + String uri = obj.getJSONArray("news").getString(i); switch(uri) { case "/forge/community-feed/": CreateNotification(1); @@ -134,13 +135,13 @@ return news; } catch(MalformedURLException e) { - + Log.e("get news", e.getLocalizedMessage()); } catch(IOException e) { - + Log.e("get news", e.getLocalizedMessage()); } catch(JSONException e) { - + Log.e("get news", e.getLocalizedMessage()); } return "error"; } @@ -169,6 +170,7 @@ @Override public int onStartCommand(Intent intent, int flags, int startId) { mRunning = true; + cookies = intent.getStringExtra("cookies"); return super.onStartCommand(intent, flags, startId); }