void handleStart(Intent intent, int startId) { NotificationManager mManager = (NotificationManager) this.getApplicationContext().getSystemService(NOTIFICATION_SERVICE); int id = intent.getIntExtra(IntentStrings.SESSION, 0); String session_timings = intent.getStringExtra(IntentStrings.SESSION_TIMING); DbSingleton dbSingleton = DbSingleton.getInstance(); Session session = dbSingleton.getSessionById(id); Intent intent1 = new Intent(this.getApplicationContext(), SessionDetailActivity.class); intent1.putExtra(IntentStrings.SESSION, session.getTitle()); PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_bookmark_white_24dp) .setLargeIcon(largeIcon) .setContentTitle(session.getTitle()) .setContentText(session_timings) .setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(session_timings)) .setContentIntent(pendingNotificationIntent); intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); mManager.notify(1, mBuilder.build()); }
@Test public void testSpeakerDbInsertionHttp() throws JSONException { HttpURLConnection urlConnection = null; BufferedReader reader = null; String jsonStr = null; try { final String BASE_URL = Urls.BASE_GET_URL_ALT + Urls.EVENTS + "/" + Urls.EVENT_ID + "/" + Urls.SPEAKERS; Uri builtUri = Uri.parse(BASE_URL).buildUpon().build(); URL url = new URL(builtUri.toString()); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { return; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } if (buffer.length() == 0) { return; } jsonStr = buffer.toString(); } catch (IOException e) { return; } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { } } } Gson gson = new Gson(); try { JSONObject json = new JSONObject(jsonStr); JSONArray eventJsonArray = json.getJSONArray(Urls.SPEAKERS); if (eventJsonArray.length() > 0) { JSONObject eventJsonObject = eventJsonArray.getJSONObject(0); Speaker speaker = gson.fromJson(String.valueOf(eventJsonObject), Speaker.class); String query = speaker.generateSql(); DbSingleton instance = new DbSingleton(database, mActivity, db); instance.clearDatabase(DbContract.Speakers.TABLE_NAME); instance.insertQuery(query); Speaker speakerDetails = instance.getSpeakerList(DbContract.Speakers.ID).get(0); assertEquals(speaker.getName(), speakerDetails.getName()); assertEquals(speaker.getName(), speakerDetails.getName()); assertEquals(speaker.getBio(), speakerDetails.getBio()); assertEquals(speaker.getCountry(), speakerDetails.getCountry()); assertEquals(speaker.getEmail(), speakerDetails.getEmail()); assertEquals(speaker.getPhoto(), speakerDetails.getPhoto()); assertEquals(speaker.getWeb(), speakerDetails.getWeb()); } } catch (JSONException e) { } }