use of android.app.Notification in project robolectric by robolectric.
the class ShadowNotificationBuilderTest method build_setsContentInfoOnNotification.
@Test
public void build_setsContentInfoOnNotification() throws Exception {
builder.setContentInfo("11");
Notification notification = builder.build();
assertThat(shadowOf(notification).getContentInfo().toString()).isEqualTo("11");
}
use of android.app.Notification in project ShortcutBadger by leolin310148.
the class BadgeIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
int badgeCount = intent.getIntExtra("badgeCount", 0);
mNotificationManager.cancel(notificationId);
notificationId++;
Notification.Builder builder = new Notification.Builder(getApplicationContext()).setContentTitle("").setContentText("").setSmallIcon(R.drawable.ic_launcher);
Notification notification = builder.build();
ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount);
mNotificationManager.notify(notificationId, notification);
}
}
use of android.app.Notification in project MusicDNA by harjot-oberai.
the class MediaPlayerService method buildNotification.
private void buildNotification(Notification.Action action) {
Notification.MediaStyle style = new Notification.MediaStyle();
style.setShowActionsInCompactView(1);
style.setMediaSession(m_objMediaSession.getSessionToken());
Intent intent = new Intent(getApplicationContext(), MediaPlayerService.class);
intent.setAction(Constants.ACTION_STOP);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
String artist;
if (pFragment != null && pFragment.localIsPlaying) {
artist = pFragment.localTrack.getArtist();
} else {
artist = "";
}
Intent notificationIntent = new Intent(this, HomeActivity.class);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Bitmap bmp = null;
try {
bmp = ((BitmapDrawable) pFragment.selected_track_image.getDrawable()).getBitmap();
} catch (Exception e) {
e.printStackTrace();
}
if (bmp == null) {
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_default);
}
Notification notification = new Notification.Builder(this).setStyle(style).setSmallIcon(R.drawable.ic_notification).setVisibility(Notification.VISIBILITY_PUBLIC).setDeleteIntent(pendingIntent).addAction(generateAction(R.drawable.ic_skip_previous_notif, "Previous", Constants.ACTION_PREVIOUS)).addAction(action).addAction(generateAction(R.drawable.ic_skip_next_notif, "Next", Constants.ACTION_NEXT)).setContentTitle(pFragment.selected_track_title.getText()).setContentText(artist).setLargeIcon(bmp).build();
notification.contentIntent = pendingNotificationIntent;
notification.priority = Notification.PRIORITY_MAX;
if (isSwipable || (pFragment.mMediaPlayer != null && pFragment.mMediaPlayer.isPlaying())) {
notification.flags |= Notification.FLAG_ONGOING_EVENT;
}
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
try {
notificationManager.notify(1, notification);
} catch (Exception e) {
e.printStackTrace();
}
updateMediaSession();
}
use of android.app.Notification in project FileDownloaderManager by arlyxiao.
the class NotificationServiceBar method handle_notification.
public void handle_notification(FileDownloader file_downloader, int notice_id) {
if (download_service.download_store_list.size() > 1) {
return;
}
String downloaded_size = download_service.show_human_size(file_downloader.downloaded_size);
String file_size = download_service.show_human_size(file_downloader.file_size);
float num = (float) file_downloader.downloaded_size / (float) file_downloader.file_size;
int result = (int) (num * 100);
String percentage = Integer.toString(result);
android.support.v4.app.NotificationCompat.Builder mBuilder = new android.support.v4.app.NotificationCompat.Builder(context);
mBuilder.setContentTitle("Download").setContentText(Integer.toString(file_downloader.downloaded_size)).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setWhen(file_downloader.when);
Notification notification = mBuilder.getNotification();
RemoteViews content_view = new RemoteViews(context.getPackageName(), R.layout.single_download_notification);
content_view.setImageViewResource(R.id.progress_download_image, R.drawable.ic_launcher);
content_view.setTextViewText(R.id.progress_title_text, Tool.regenerate_filename(file_downloader.get_file_name()));
// content_view.setTextViewText(R.id.download_filename, "");
content_view.setTextViewText(R.id.progress_percentage, downloaded_size + " / " + file_size);
Log.i("显示正在下载的大小 ", Integer.toString(file_downloader.downloaded_size));
Log.i("显示文件的大小 ", Integer.toString(file_downloader.file_size));
content_view.setProgressBar(R.id.download_progressbar_in_service, file_downloader.file_size, file_downloader.downloaded_size, false);
final ComponentName receiver = new ComponentName(file_downloader.context, file_downloader.activity_class);
// final ComponentName receiver = new ComponentName(file_downloader.context,
// DownloadProgressNotificationWidget.class);
Intent notice_intent = new Intent(file_downloader.context.getClass().getName() + System.currentTimeMillis());
notice_intent.setComponent(receiver);
String param_name1 = file_downloader.intent_extras.getString("param_name1");
Log.i("notification bar 测试值 ", param_name1);
if (file_downloader.intent_extras != null) {
notice_intent.putExtras(file_downloader.intent_extras);
}
PendingIntent p_intent = PendingIntent.getActivity(file_downloader.context, 0, notice_intent, PendingIntent.FLAG_CANCEL_CURRENT);
// PendingIntent p_intent = PendingIntent.getBroadcast(file_downloader.context,
// 0, notice_intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.contentIntent = p_intent;
content_view.setOnClickPendingIntent(R.id.progress_content_layout, p_intent);
notification.contentView = content_view;
/// start_foreground(notice_id, notification);
download_service.startForeground(notice_id, notification);
}
use of android.app.Notification in project FileDownloaderManager by arlyxiao.
the class NotificationServiceBar method pause_notification.
public void pause_notification(ArrayList<FileDownloader> download_store_list, FileDownloader file_downloader, int notice_id) {
int length = download_store_list.size();
if (length > 0) {
return;
}
String downloaded_size = download_service.show_human_size(file_downloader.downloaded_size);
String file_size = download_service.show_human_size(file_downloader.file_size);
android.support.v4.app.NotificationCompat.Builder mBuilder = new android.support.v4.app.NotificationCompat.Builder(context);
mBuilder.setContentTitle("Download").setContentText(Integer.toString(file_downloader.downloaded_size)).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setWhen(System.currentTimeMillis());
Notification notification = mBuilder.getNotification();
RemoteViews content_view = new RemoteViews(context.getPackageName(), R.layout.single_pause_notification);
content_view.setImageViewResource(R.id.progress_pause_image, R.drawable.ic_launcher);
content_view.setTextViewText(R.id.progress_title_text, Tool.regenerate_filename(file_downloader.get_file_name()));
content_view.setTextViewText(R.id.progress_percentage, downloaded_size + " / " + file_size);
content_view.setTextViewText(R.id.wait_text, "下载暂停");
final ComponentName receiver = new ComponentName(file_downloader.context, file_downloader.activity_class);
Intent notice_intent = new Intent(file_downloader.context.getClass().getName() + System.currentTimeMillis());
notice_intent.setComponent(receiver);
String param_name1 = file_downloader.intent_extras.getString("param_name1");
Log.i("notification bar 测试值 ", param_name1);
if (file_downloader.intent_extras != null) {
notice_intent.putExtras(file_downloader.intent_extras);
}
PendingIntent p_intent = PendingIntent.getActivity(file_downloader.context, 0, notice_intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.contentIntent = p_intent;
content_view.setOnClickPendingIntent(R.id.progress_content_pause, p_intent);
notification.contentView = content_view;
download_service.startForeground(notice_id, notification);
}
Aggregations