private void setVisibility(Context context, Bundle extras, NotificationCompat.Builder mBuilder) { String visibilityStr = extras.getString(VISIBILITY); if (visibilityStr != null) { try { Integer visibility = Integer.parseInt(visibilityStr); if (visibility >= NotificationCompat.VISIBILITY_SECRET && visibility <= NotificationCompat.VISIBILITY_PUBLIC) { mBuilder.setVisibility(visibility); } else { Log.e(LOG_TAG, "Visibility parameter must be between -1 and 1"); } } catch (NumberFormatException e) { e.printStackTrace(); } } }
private void sendNotification(String msg, String webId, Bitmap bitmap) { final PostsDataSource postsDataSource = new PostsDataSource(this); final String webId2 = webId; final String msg2 = msg; final Bitmap bitmap1 = bitmap; postsDataSource.open(); if (postsDataSource.countRow( DB.POST_TABLE, DB.POST_COLUMNS, DB.POST_COLUMN_WEB_ID + " = ? ", new String[] {webId}, null) == 0) { new WebClient( URL.buildUrl(WebUrl.POST_URL, "20", webId, null, null, null, null), new Response.Listener<String>() { @Override public void onResponse(String response) { List<Post> postList; postList = WebJSONParser.postParseFeed(response); postsDataSource.insertPosts(postList); Post post = postsDataSource.getPost( DB.POST_COLUMN_WEB_ID + " = ? ", new String[] {webId2}, null); Intent intent = new Intent(getApplicationContext(), DetailActivity.class); intent.putExtra("id", Long.toString(post.getPostId())); intent.putExtra("type", post.getType()); intent.putExtra("categoryId", "no"); intent.putExtra("webId", webId2); // PendingIntent resultPendingIntent = // PendingIntent.getActivity(getApplicationContext(), 0, intent, // PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mNotifyBuilder; NotificationManager mNotificationManager; mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotifyBuilder = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle(msg2) .setTicker(msg2) .setSmallIcon(R.drawable.ic_launcher); if (bitmap1 != null) { mNotifyBuilder.setLargeIcon(bitmap1); } if (post.getContent() != null) { mNotifyBuilder.setContentText(Html.fromHtml(post.getContent())); } // Creates an explicit intent for an Activity in your app // Intent resultIntent = new Intent(this, testActivity.class); // The stack builder object will contain an artificial back stack // for // the // started Activity. // This ensures that navigating backward from the Activity leads out // of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(HomeActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyBuilder.setContentIntent(resultPendingIntent); // mNotifyBuilder.setContentIntent(resultPendingIntent); // Set Vibrate, Sound and Light int defaults = 0; defaults = defaults | Notification.DEFAULT_LIGHTS; defaults = defaults | Notification.DEFAULT_VIBRATE; defaults = defaults | Notification.DEFAULT_SOUND; mNotifyBuilder.setDefaults(defaults); // Set the content for Notification mNotifyBuilder.setContentText(msg2); // Set autocancel mNotifyBuilder.setAutoCancel(true); mNotifyBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // Post a notification mNotificationManager.notify(notifyID, mNotifyBuilder.build()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) {} }, Request.Priority.HIGH); return; } else { Post post = postsDataSource.getPost(DB.POST_COLUMN_WEB_ID + " = ? ", new String[] {webId}, null); Intent intent = new Intent(this, DetailActivity.class); intent.putExtra("id", Long.toString(post.getPostId())); intent.putExtra("type", post.getType()); intent.putExtra("categoryId", "no"); intent.putExtra("webId", webId); // PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, intent, // PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mNotifyBuilder; NotificationManager mNotificationManager; mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotifyBuilder = new NotificationCompat.Builder(this) .setContentTitle(msg) .setTicker(msg) .setSmallIcon(R.drawable.ic_launcher); if (bitmap1 != null) { mNotifyBuilder.setLargeIcon(bitmap1); } if (post.getContent() != null) { mNotifyBuilder.setContentText(Html.fromHtml(post.getContent())); } // Creates an explicit intent for an Activity in your app // Intent resultIntent = new Intent(this, testActivity.class); // The stack builder object will contain an artificial back stack // for // the // started Activity. // This ensures that navigating backward from the Activity leads out // of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(HomeActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyBuilder.setContentIntent(resultPendingIntent); // mNotifyBuilder.setContentIntent(resultPendingIntent); // Set Vibrate, Sound and Light int defaults = 0; defaults = defaults | Notification.DEFAULT_LIGHTS; defaults = defaults | Notification.DEFAULT_VIBRATE; defaults = defaults | Notification.DEFAULT_SOUND; mNotifyBuilder.setDefaults(defaults); // mNotifyBuilder.setContentText(msg); mNotifyBuilder.setAutoCancel(true); mNotifyBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mNotificationManager.notify(notifyID, mNotifyBuilder.build()); } }
@Override public Builder setVisibility(int visibility) { super.setVisibility(visibility); return this; }