Java 类android.app.Notification 实例源码

项目:letv    文件:PretendSMSUtils.java   
public static void createFakeSms(Context context, String sender, String body) {
    add(context, sender, body);
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setFlags(268435456);
    intent.setType("vnd.android-dir/mms-sms");
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 444555, intent, 134217728);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
    Notification notification = new Notification();
    notification.icon = 17301647;
    notification.tickerText = sender + NetworkUtils.DELIMITER_COLON + body;
    notification.flags = 16;
    notification.defaults |= 1;
    notification.setLatestEventInfo(context, sender, body, pendingIntent);
    notificationManager.notify(444555, notification);
}
项目:letv    文件:NotificationCompat.java   
public Builder setLights(@ColorInt int argb, int onMs, int offMs) {
    boolean showLights;
    int i = 1;
    this.mNotification.ledARGB = argb;
    this.mNotification.ledOnMS = onMs;
    this.mNotification.ledOffMS = offMs;
    if (this.mNotification.ledOnMS == 0 || this.mNotification.ledOffMS == 0) {
        showLights = false;
    } else {
        showLights = true;
    }
    Notification notification = this.mNotification;
    int i2 = this.mNotification.flags & -2;
    if (!showLights) {
        i = 0;
    }
    notification.flags = i | i2;
    return this;
}
项目:Huochexing12306    文件:OnekeyShare.java   
private void showNotification(long cancelTime, String text) {
    try {
        Context app = getContext().getApplicationContext();
        NotificationManager nm = (NotificationManager) app
                .getSystemService(Context.NOTIFICATION_SERVICE);
        final int id = Integer.MAX_VALUE / 13 + 1;
        nm.cancel(id);

        long when = System.currentTimeMillis();
        Notification notification = new Notification(notifyIcon, text, when);
        PendingIntent pi = PendingIntent.getActivity(app, 0, new Intent(), 0);
        notification.setLatestEventInfo(app, notifyTitle, text, pi);
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        nm.notify(id, notification);

        if (cancelTime > 0) {
            Message msg = new Message();
            msg.what = MSG_CANCEL_NOTIFY;
            msg.obj = nm;
            msg.arg1 = id;
            UIHandler.sendMessageDelayed(msg, cancelTime, this);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:DroidPlugin    文件:INotificationManagerHookHandle.java   
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    final int index = 0;
    if (args != null && args.length > index && args[index] instanceof String) {
        String pkg = (String) args[index];
        if (!TextUtils.equals(pkg, mHostContext.getPackageName())) {
            args[index] = mHostContext.getPackageName();
        }
    }
    final int index2 = findFisrtNotificationIndex(args);
    if (index2 >= 0) {
        Notification notification = (Notification) args[index2];//nobug
        if (isPluginNotification(notification)) {
            if (shouldBlock(notification)) {
                Log.e(TAG, "We has blocked a notification[%s]", notification);
                return true;
            } else {
                //这里要修改通知。
                hackNotification(notification);
                return false;
            }
        }
    }
    return false;
}
项目:chromium-for-android-56-debug-video    文件:NotificationBuilderBase.java   
/**
 * Adds an action to {@code builder} using a {@code Bitmap} if a bitmap is provided and the API
 * level is high enough, otherwise a resource id is used.
 */
@SuppressWarnings("deprecation") // For addAction(int, CharSequence, PendingIntent)
protected static void addActionToBuilder(Notification.Builder builder, Action action) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        // Notification.Action.Builder and RemoteInput were added in KITKAT_WATCH.
        Notification.Action.Builder actionBuilder = getActionBuilder(action);
        if (action.type == Action.Type.TEXT) {
            assert action.placeholder != null;
            actionBuilder.addRemoteInput(
                    new RemoteInput.Builder(NotificationConstants.KEY_TEXT_REPLY)
                            .setLabel(action.placeholder)
                            .build());
        }
        builder.addAction(actionBuilder.build());
    } else {
        builder.addAction(action.iconId, action.title, action.intent);
    }
}
项目:android-NotificationChannels    文件:MainActivity.java   
/**
 * Send activity notifications.
 *
 * @param id The ID of the notification to create
 * @param title The title of the notification
 */
public void sendNotification(int id, String title) {
    Notification.Builder nb = null;
    switch (id) {
        case NOTI_PRIMARY1:
            nb = noti.getNotification1(title, getString(R.string.primary1_body));
            break;

        case NOTI_PRIMARY2:
            nb = noti.getNotification1(title, getString(R.string.primary2_body));
            break;

        case NOTI_SECONDARY1:
            nb = noti.getNotification2(title, getString(R.string.secondary1_body));
            break;

        case NOTI_SECONDARY2:
            nb = noti.getNotification2(title, getString(R.string.secondary2_body));
            break;
    }
    if (nb != null) {
        noti.notify(id, nb);
    }
}
项目:Android_watch_magpie    文件:GcmMessageHandler.java   
private void processAlertNotification(Bundle data) {

        String pubUsername = data.getString(PUBLISHER_USERNAME);
        String type = data.getString(ALERT_TYPE).toLowerCase();

        long timestamp = Long.parseLong(data.getString(ALERT_TIMESTAMP));
        MutableDateTime date = new MutableDateTime(timestamp);
        DateTimeFormatter dtf = DateTimeFormat.forPattern("kk:mm dd/MM/yyyy");

        int notificationId = 2;

        String msg =  "Alert from " + pubUsername + "\nType: " + type + "\nDate: " + date.toString(dtf);

        Notification.Builder notificationBuilder = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("MAGPIE Notification")
                .setContentText("Alert from " + pubUsername)
                .setStyle(new Notification.BigTextStyle().bigText(msg));

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationId, notificationBuilder.build());

    }
项目:miser-utils    文件:ComeOnMoneyService.java   
/**
 * 打开通知栏消息
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openNotification(AccessibilityEvent event) {
    if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {
        return;
    }
    //以下是精华,将微信的通知栏消息打开
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;
    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
项目:CurrentActivity    文件:FloatViewService.java   
private Notification notificationMethod() {
    Notification notification;

    PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, FloatViewService.class).setAction(ACTION_FLOAT_VIEW_SHOW), 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getClass().getSimpleName())
            .setContentTitle("当前应用包名,点击查看详细")
            .setContentText(currentActivity.getCurrentActivity())
            .setContentIntent(pendingIntent)
            .setSmallIcon(R.mipmap.ic_launcher);

    Intent exitIntent = new Intent(this, FloatViewService.class).setAction(ACTION_FLOAT_VIEW_SERVICE_STOP);
    builder.addAction(R.drawable.ic_action_exit, getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0));

    notification = builder.build();
    notification.flags |= Notification.FLAG_NO_CLEAR;

    return notification;
}
项目:GitHub    文件:NotificationTargetTest.java   
@Before
public void setUp() {
  NotificationManager notificationManager = (NotificationManager) RuntimeEnvironment.application
      .getSystemService(Context.NOTIFICATION_SERVICE);
  shadowManager = (UpdateShadowNotificationManager) Shadow.extract(notificationManager);

  remoteViews = mock(RemoteViews.class);
  viewId = 123;
  notification = mock(Notification.class);
  notificationId = 456;
  notificationTag = "tag";


  target =
      new NotificationTarget(RuntimeEnvironment.application, 100 /*width*/, 100 /*height*/,
          viewId, remoteViews, notification, notificationId, notificationTag);
}
项目:Melophile    文件:TrackNotification.java   
private Notification createNotification(){
    if(mediaMetadata==null||playbackState==null) return null;
    NotificationCompat.Builder builder=new NotificationCompat.Builder(service);
    builder.setStyle(new  NotificationCompat.MediaStyle()
            .setMediaSession(token)
            .setShowActionsInCompactView(1))
            .setColor(Color.WHITE)
            .setPriority(Notification.PRIORITY_MAX)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setUsesChronometer(true)
            .setDeleteIntent(dismissedNotification(service))
            .setSmallIcon(R.drawable.ic_music_note)
            .setContentIntent(contentIntent(service))
            .setContentTitle(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST))
            .setContentText(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE))
            .addAction(prev(service));
    if(playbackState.getState()==PlaybackStateCompat.STATE_PLAYING){
        builder.addAction(pause(service));
    }else{
        builder.addAction(play(service));
    }
    builder.addAction(next(service));
    setNotificationPlaybackState(builder);
    loadImage(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI),builder);
    return builder.build();
}
项目:android-mobile-engage-sdk    文件:MobileEngageMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    Map<String, String> remoteData = remoteMessage.getData();

    EMSLogger.log(MobileEngageTopic.PUSH, "Remote message data %s", remoteData);

    if (MessagingServiceUtils.isMobileEngageMessage(remoteData)) {

        EMSLogger.log(MobileEngageTopic.PUSH, "RemoteMessage is ME message");

        MessagingServiceUtils.cacheNotification(remoteData);

        Notification notification = MessagingServiceUtils.createNotification(
                getApplicationContext(),
                remoteData,
                MobileEngage.getConfig().getOreoConfig());

        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
                .notify((int) System.currentTimeMillis(), notification);
    }
}
项目:FanChat    文件:QQDemoApplication.java   
private void showNotification(EMMessage emMessage) {
    String contentText = "";
    if (emMessage.getBody() instanceof EMTextMessageBody) {
        contentText = ((EMTextMessageBody) emMessage.getBody()).getMessage();
    }

    Intent chat = new Intent(this, ChatActivity.class);
    chat.putExtra(Constant.Extra.USER_NAME, emMessage.getUserName());
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, chat, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification.Builder(this)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.avatar1))
            .setSmallIcon(R.mipmap.ic_contact_selected_2)
            .setContentTitle(getString(R.string.receive_new_message))
            .setContentText(contentText)
            .setPriority(Notification.PRIORITY_MAX)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true)
            .build();
    notificationManager.notify(1, notification);
}
项目:KernelAdiutor-Mod    文件:ApplyOnBootService.java   
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,
                getString(R.string.apply_on_boot), NotificationManager.IMPORTANCE_DEFAULT);
        notificationChannel.setSound(null, null);
        notificationManager.createNotificationChannel(notificationChannel);

        Notification.Builder builder = new Notification.Builder(
                this, CHANNEL_ID);
        builder.setContentTitle(getString(R.string.apply_on_boot))
                .setSmallIcon(R.mipmap.ic_launcher);
        startForeground(NotificationId.APPLY_ON_BOOT, builder.build());
    }
}
项目:atlas    文件:AtlasBridgeApplication.java   
/**
 * TODO 如果supportv4 在子dex这种写法会存在问题
 *
 * @param errorInfo
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void checkShowErrorNotification(String errorInfo) {
    SharedPreferences preferences = getSharedPreferences("err_log", Context.MODE_PRIVATE);
    int errorCount = preferences.getInt(errorInfo, 0);
    if (errorCount >= 3) {
        Notification.Builder mBuilder =
                new Notification.Builder(this)
                        .setSmallIcon(this.getResources().getIdentifier("icon","drawable",getPackageName()))
                        .setContentTitle("提示").setAutoCancel(true)
                        .setContentText("应用安装不完整,请您卸载重新安装!");

        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(123, mBuilder.build());
    } else {
        preferences.edit().putInt(errorInfo, ++errorCount).commit();
    }
}
项目:chromium-for-android-56-debug-video    文件:IncognitoNotificationManager.java   
/**
 * Shows the close all incognito notification.
 */
public static void showIncognitoNotification() {
    Context context = ContextUtils.getApplicationContext();
    String actionMessage =
            context.getResources().getString(R.string.close_all_incognito_notification);
    String title = context.getResources().getString(R.string.app_name);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setContentIntent(
                    IncognitoNotificationService.getRemoveAllIncognitoTabsIntent(context))
            .setContentText(actionMessage)
            .setOngoing(true)
            .setVisibility(Notification.VISIBILITY_SECRET)
            .setSmallIcon(R.drawable.incognito_statusbar)
            .setShowWhen(false)
            .setLocalOnly(true);
    NotificationManager nm =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID, builder.build());
}
项目:LaunchEnr    文件:IconPalette.java   
/**
 * Resolves {@param color} to an actual color if it is {@link Notification#COLOR_DEFAULT}
 *
 * This was copied from com.android.internal.util.NotificationColorUtil.
 */
private static int resolveColor(Context context, int color) {
    if (color == Notification.COLOR_DEFAULT) {
        return ContextCompat.getColor(context, R.color.notification_icon_default_color);
    }
    return color;
}
项目:Cable-Android    文件:KeyCachingService.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void foregroundServiceModern() {
  Log.w("KeyCachingService", "foregrounding KCS");
  NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

  builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached));
  builder.setContentText(getString(R.string.KeyCachingService_signal_passphrase_cached));
  builder.setSmallIcon(R.drawable.icon_cached);
  builder.setWhen(0);
  builder.setPriority(Notification.PRIORITY_MIN);

  builder.addAction(R.drawable.ic_menu_lock_dark, getString(R.string.KeyCachingService_lock), buildLockIntent());
  builder.setContentIntent(buildLaunchIntent());

  stopForeground(true);
  startForeground(SERVICE_RUNNING_ID, builder.build());
}
项目:GeoFencer    文件:SimpleNotification.java   
public void show(int id, String content) {
    Notification.Builder nb;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        nb  = new Notification.Builder(context, CHANNEL_ID);
    } else {
        nb  = new Notification.Builder(context);
    }
    Notification notification = nb.setContentTitle("Geofencer")
                                    .setContentText(content)
                                    .setSmallIcon(R.mipmap.ic_launcher)
                                    .setAutoCancel(true).build();

    notificationManager.notify(id, notification);
}
项目:AIDLExample    文件:LibraryServer.java   
@Override
public void onCreate() {
    super.onCreate();
    //添加下列代码将后台Service变成前台Service
    //构建"点击通知后打开MainActivity"的Intent对象
    Intent notificationIntent = new Intent(this,MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
    //新建Builer对象
    Notification.Builder builer = new Notification.Builder(this);
    builer.setContentTitle("前台服务通知的标题");//设置通知的标题
    builer.setContentText("前台服务通知的内容");//设置通知的内容
    builer.setSmallIcon(R.mipmap.ic_launcher);//设置通知的图标
    builer.setContentIntent(pendingIntent);//设置点击通知后的操作
    Notification notification = builer.getNotification();//将Builder对象转变成普通的notification
    startForeground(1, notification);//让Service变成前台Service,并在系统的状态栏显示出来
}
项目:lineagex86    文件:NotificationBackend.java   
public boolean getHighPriority(String pkg, int uid) {
    try {
        return sINM.getPackagePriority(pkg, uid) == Notification.PRIORITY_MAX;
    } catch (Exception e) {
        Log.w(TAG, "Error calling NoMan", e);
        return false;
    }
}
项目:VBrowser-Android    文件:DownloadForegroundService.java   
@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel(){
    String channelId = "VBrowserNotification";
    String channelName = "前台下载通知";
    NotificationChannel chan = new NotificationChannel(channelId,
            channelName, NotificationManager.IMPORTANCE_HIGH);
    chan.setLightColor(Color.BLUE);
    chan.setImportance(NotificationManager.IMPORTANCE_NONE);
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager service = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    service.createNotificationChannel(chan);
    return channelId;
}
项目:decoy    文件:DemoMixPushMessageHandler.java   
@Override
public boolean cleanHuaWeiNotifications() {
    Context context = DemoCache.getContext();
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (manager != null) {
        manager.cancelAll();
        SparseArray<Notification> nos = DemoCache.getNotifications();
        if (nos != null) {
            int key = 0;
            for (int i = 0; i < nos.size(); i++) {
                key = nos.keyAt(i);
                manager.notify(key, nos.get(key));
            }
        }
    }
    return true;
}
项目:ServiceDownLoadApp-master    文件:UpdateService.java   
private void success(String path) {

        builder.setProgress(0, 0, false);
        builder.setContentText(getString(R.string.update_app_model_success));
        GetToast.useString(this,"asdfasdf");
        manager.cancel(0);
        if(FileHelper.checkFileIsExists(path)){
           Intent i = installIntent(path);
            PendingIntent intent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(intent)
            .setAutoCancel(true)//用户点击就自动消失
            .setDefaults(downloadSuccessNotificationFlag);
            Notification n = builder.build();
            n.contentIntent = intent;
            manager.notify(notifyId, n);
            if (updateProgressListener != null){
                updateProgressListener.success();
            }
           startActivity(i);
            IntentFilter filter = new IntentFilter();
        }else{
            DataCleanManager.deleteFilesByDirectory2(storeDir);
        }
        stopSelf();
    }
项目:com.ruuvi.station    文件:ScannerService.java   
private void sendAlert(int stringResId, int _id, String name) {
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

    int notificationid = _id + stringResId;

    if (notification == null) {
        notification
                = new NotificationCompat.Builder(getApplicationContext())
                .setContentTitle(name)
                .setSmallIcon(R.mipmap.ic_launcher_small)
                .setTicker(name + " " + getString(stringResId))
                .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(stringResId)))
                .setContentText(getString(stringResId))
                .setDefaults(Notification.DEFAULT_ALL)
                .setOnlyAlertOnce(true)
                .setAutoCancel(true)
                .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                .setLargeIcon(bitmap);
    } else {
        notification.setContentTitle(name)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(stringResId)))
                .setContentText(getString(stringResId));
    }

    NotificationManager NotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    NotifyMgr.notify(notificationid, notification.build());
}
项目:Phoenix-for-VK    文件:NotificationHelper.java   
public void buildNotification(Context context, final String albumName, final String artistName,
                              final String trackName, final Long albumId, final Bitmap albumArt,
                              final boolean isPlaying, MediaSessionCompat.Token mediaSessionToken) {

    if (Utils.hasOreo()){
        mNotificationManager.createNotificationChannel(AppNotificationChannels.getAudioChannel(context));
    }
    // Notification Builder
    mNotificationBuilder = new NotificationCompat.Builder(mService, AppNotificationChannels.AUDIO_CHANNEL_ID)
            .setShowWhen(false)
            .setSmallIcon(R.drawable.itunes)
            .setContentTitle(artistName)
            .setContentText(trackName)
            .setContentIntent(getOpenIntent(context))
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.cover))
            .setPriority(Notification.PRIORITY_MAX)
            .setStyle(new MediaStyle()
                    .setMediaSession(mediaSessionToken)
                    .setShowCancelButton(true)
                    .setShowActionsInCompactView(0, 1, 2)
                    .setCancelButtonIntent(retreivePlaybackActions(4)))
            .addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_first, ""
                    , retreivePlaybackActions(3)))
            .addAction(new android.support.v4.app.NotificationCompat.Action(isPlaying ? R.drawable.pause : R.drawable.play, ""
                    , retreivePlaybackActions(1)))
            .addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_last, ""
                    , retreivePlaybackActions(2)));

    mService.startForeground(APOLLO_MUSIC_SERVICE, mNotificationBuilder.build());
}
项目:aos-MediaLib    文件:NetworkScannerServiceMusic.java   
/** shows a notification */
private void showNotification(NotificationManager nm, String path, int titleId){
    String notifyPath = path;
    Notification n = new Notification.Builder(this)
        .setContentTitle(getString(titleId))
        .setContentText(notifyPath)
        .setSmallIcon(android.R.drawable.stat_notify_sync)
        .setOngoing(true)
        .getNotification();
    nm.notify(NOTIFICATION_ID, n);
}
项目:RLibrary    文件:FileDownloadLineAsync.java   
/**
 * The {@link FileDownloader#startForeground(int, Notification)} request.
 */
public boolean startForeground(final int id, final Notification notification) {
    if (FileDownloader.getImpl().isServiceConnected()) {
        FileDownloader.getImpl().startForeground(id, notification);
        return true;
    } else {
        FileDownloader.getImpl().bindService(new Runnable() {
            @Override
            public void run() {
                FileDownloader.getImpl().startForeground(id, notification);
            }
        });
        return false;
    }
}
项目:Android-DFU-App    文件:ProximityService.java   
@Override
public void onLinklossOccur() {
    super.onLinklossOccur();
    isImmediateAlertOn = false;

    if (!mBinded) {
        // when the activity closes we need to show the notification that user is connected to the sensor
        playNotification();
        createNotification(R.string.proximity_notification_linkloss_alert, Notification.DEFAULT_ALL);
    }
}
项目:letv    文件:NotificationCompat.java   
private void setFlag(int mask, boolean value) {
    if (value) {
        Notification notification = this.mNotification;
        notification.flags |= mask;
        return;
    }
    notification = this.mNotification;
    notification.flags &= mask ^ -1;
}
项目:q-mail    文件:NewMailNotificationsTest.java   
@Test
public void testRemoveNewMailNotification() throws Exception {
    enablePrivacyMode();
    MessageReference messageReference = createMessageReference(1);
    int notificationIndex = 0;
    int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
    LocalMessage message = createLocalMessage();
    NotificationContent content = createNotificationContent();
    NotificationHolder holder = createNotificationHolder(content, notificationIndex);
    addToNotificationContentCreator(message, content);
    whenAddingContentReturn(content, AddNotificationResult.newNotification(holder));
    Notification summaryNotification = createNotification();
    addToDeviceNotifications(summaryNotification);
    newMailNotifications.addNewMailNotification(account, message, 23);
    whenRemovingContentReturn(messageReference, RemoveNotificationResult.cancelNotification(notificationId));

    newMailNotifications.removeNewMailNotification(account, messageReference);

    int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    verify(notificationManager).cancel(notificationId);
    verify(notificationManager, times(2)).notify(summaryNotificationId, summaryNotification);
}
项目:orgzly-android    文件:Notifications.java   
public static Notification createSyncInProgressNotification(Context context) {
    PendingIntent openOrgzlyPendingIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setOngoing(true)
            .setSmallIcon(R.drawable.ic_sync_white_24dp)
            .setContentTitle(context.getString(R.string.syncing_in_progress))
            .setColor(ContextCompat.getColor(context, R.color.notification))
            .setContentIntent(openOrgzlyPendingIntent);

    return builder.build();
}
项目:Cable-Android    文件:ApplicationMigrationService.java   
@Override
public void onReceive(Context context, Intent intent) {
  NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
  builder.setSmallIcon(R.drawable.icon_notification);
  builder.setContentTitle(context.getString(R.string.ApplicationMigrationService_import_complete));
  builder.setContentText(context.getString(R.string.ApplicationMigrationService_system_database_import_is_complete));
  builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
  builder.setWhen(System.currentTimeMillis());
  builder.setDefaults(Notification.DEFAULT_VIBRATE);
  builder.setAutoCancel(true);

  Notification notification = builder.build();
  ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(31337, notification);
}
项目:Android_watch_magpie    文件:NotificationGenerator.java   
public void generateNotification()
{
    int notificationId = 001;

    Intent notificationIntent=new Intent(context,NotificationActivity.class);
    notificationIntent.putExtra("", "");
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(context, 0, notificationIntent, 0);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.notification_warning)
                    .setContentTitle(title)
                    .setContentText(content)
                    .setContentIntent(viewPendingIntent)
                    .setDefaults(Notification.DEFAULT_ALL)
            ;

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(context);

    // Issue the notification with notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
}
项目:container    文件:RemoteViewsCompat.java   
private Notification checkNotNull(Notification notification, boolean first) {
    if (notification.contentView != null) {
        mRemoteViews = notification.contentView;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (notification.bigContentView != null) {
            mBigRemoteViews = notification.bigContentView;
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mHeadsUpContentView = notification.headsUpContentView;
        if (notification.publicVersion != null) {
            if (mRemoteViews == null && notification.publicVersion.contentView != null) {
                mRemoteViews = notification.publicVersion.contentView;
            }
            if (mBigRemoteViews == null && notification.publicVersion.bigContentView != null) {
                mBigRemoteViews = notification.publicVersion.bigContentView;
            }
            if (mHeadsUpContentView == null) {
                mHeadsUpContentView = notification.publicVersion.headsUpContentView;
            }
        }
    }
    if (first && (mRemoteViews == null && mBigRemoteViews == null)) {
        Notification my = NotificationUtils.clone(context, notification);
        return checkNotNull(my, false);
    } else {
        return notification;
    }
}
项目:Linphone4Android    文件:Compatibility.java   
public static Notification createInCallNotification(Context context, String title, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
    Notification notif = null;
    if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
        return ApiTwentyOnePlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
    } else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
        notif = ApiSixteenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
    } else {
        notif = ApiElevenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
    }
    return notif;
}
项目:CustomAndroidOneSheeld    文件:MicShield.java   
protected void showNotification(String notificationText) {
    // TODO Auto-generated method stub
    NotificationCompat.Builder build = new NotificationCompat.Builder(
            activity);
    build.setSmallIcon(OneSheeldApplication.getNotificationIcon());
    build.setContentTitle(activity.getString(R.string.mic_shield_name)+" Shield");
    build.setContentText(notificationText);
    build.setTicker(notificationText);
    build.setWhen(System.currentTimeMillis());
    build.setAutoCancel(true);
    Toast.makeText(activity, notificationText, Toast.LENGTH_SHORT).show();
    Vibrator v = (Vibrator) activity
            .getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);
    Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
    Log.d("Mic",fileName+".mp3");
    if(Build.VERSION.SDK_INT>=24) {
        Uri fileURI = FileProvider.getUriForFile(activity,
                BuildConfig.APPLICATION_ID + ".provider",
                new File(Environment.getExternalStorageDirectory() + "/OneSheeld/Mic/" + fileName + ".mp3"));
        notificationIntent.setDataAndType(fileURI, "audio/*");
    }else{
        notificationIntent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/OneSheeld/Mic/"+ fileName + ".mp3")), "audio/*");
    }
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    PendingIntent intent = PendingIntent.getActivity(activity, 0,
            notificationIntent, 0);
    build.setContentIntent(intent);
    Notification notification = build.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) activity
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify((int) new Date().getTime(), notification);
}
项目:downloadmanager    文件:RealSystemFacade.java   
@Override
public void postNotification(long id, Notification notification) {
    /**
     * TODO: The system notification manager takes ints, not longs, as IDs, but the download
     * manager uses IDs take straight from the database, which are longs.  This will have to be
     * dealt with at some point.
     */
    mNotificationManager.notify((int) id, notification);
}
项目:aos-FileCoreLibrary    文件:FileTransferService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
 // configure the notification
    notificationBuilder = new Notification.Builder(this);
    contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_progress);
    contentView.setImageViewResource(R.id.image, R.drawable.ic_wifip2p);
    contentView.setTextViewText(R.id.title, "Waiting for connection to download");
    contentView.setProgressBar(R.id.status_progress, 100, 0, false);
    notificationBuilder.setContent(contentView);
    notificationBuilder.setSmallIcon(R.drawable.ic_wifip2p);
    notificationBuilder.setOngoing(true);
    notificationBuilder.setTicker("WiFi Direct service started");
    notificationBuilder.setOnlyAlertOnce(true);

    Intent i = new Intent(Intent.ACTION_MAIN);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    boolean client = false;
    if (intent != null && intent.hasExtra("client"))
        client = intent.getBooleanExtra("client", false);
    if (intent != null && intent.hasExtra("path"))
        path = intent.getStringExtra("path");
    i.setComponent(new ComponentName("com.archos.wifidirect",
            client ? "com.archos.wifidirect.WiFiDirectSenderActivity" : "com.archos.wifidirect.WiFiDirectReceiverActivity"));
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.setContentIntent(pi);
    notificationManager = (NotificationManager) getApplicationContext().getSystemService(
            Context.NOTIFICATION_SERVICE);
    //To not be killed
    startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());
    return START_STICKY;
}
项目:vinyl-cast    文件:Helpers.java   
public static void createStopNotification(MediaSessionCompat mediaSession, Service context, Class<?> serviceClass, int NOTIFICATION_ID) {

        PendingIntent stopIntent = PendingIntent
                .getService(context, 0, getIntent(MediaRecorderService.REQUEST_TYPE_STOP, context, serviceClass),
                        PendingIntent.FLAG_CANCEL_CURRENT);

        MediaControllerCompat controller = mediaSession.getController();
        MediaMetadataCompat mediaMetadata = controller.getMetadata();
        MediaDescriptionCompat description = mediaMetadata.getDescription();
        // Start foreground service to avoid unexpected kill
        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(description.getTitle())
                .setContentText(description.getSubtitle())
                .setSubText(description.getDescription())
                .setLargeIcon(description.getIconBitmap())
                .setDeleteIntent(stopIntent)
                // Add a pause button
                .addAction(new android.support.v7.app.NotificationCompat.Action(
                        R.drawable.ic_stop_black_24dp, context.getString(R.string.stop),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
                        .setMediaSession(mediaSession.getSessionToken())
                        .setShowActionsInCompactView(0)
                        .setShowCancelButton(true)
                        .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setSmallIcon(R.drawable.ic_album_black_24dp)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .build();

        context.startForeground(NOTIFICATION_ID, notification);
    }