微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.support.v4.app.NotificationManagerCompat的实例源码

项目:Android-Wear-Projects    文件WaterReminderReceiver.java   
@Override
public void onReceive(Context context,Intent intent) {
    Intent intent2 = new Intent(context,MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context,intent2,PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = ringtoneManager.getDefaultUri(ringtoneManager.TYPE_ALARM);

    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setAutoCancel(true)   //Automatically delete the notification
            .setSmallIcon(R.drawable.water_bottle_flat) //Notification icon
            .setContentIntent(pendingIntent)
            .setContentTitle("Time to hydrate")
            .setContentText("Drink a glass of water Now")
            .setCategory(Notification.CATEGORY_REMINDER)
            .setPriority(Notification.PRIORITY_HIGH)
            .setSound(defaultSoundUri);


    notificationmanagerCompat notificationmanager = notificationmanagerCompat.from(context);
    notificationmanager.notify(0,notificationBuilder.build());

    Toast.makeText(context,"Repeating Alarm Received",Toast.LENGTH_SHORT).show();
}
项目:zabbkit-android    文件NotificationUpdateService.java   
private void sendNotification(String title,String content) {

        // this intent will open the activity when the user taps the "open" action on the notification
        Intent viewIntent = new Intent(this,MainActivity.class);
        PendingIntent pendingViewIntent = PendingIntent.getActivity(this,viewIntent,0);

        // this intent will be sent when the user swipes the notification to dismiss it
        Intent dismissIntent = new Intent(ZabbkitConstants.NOTIFICATION_disMISS);
        PendingIntent pendingDeleteIntent = PendingIntent.getService(this,dismissIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(title)
                .setContentText(content)
                .setGroup(GROUP_KEY)
                .setDeleteIntent(pendingDeleteIntent)
                .setContentIntent(pendingViewIntent);

        Notification notification = builder.build();

        notificationmanagerCompat notificationmanagerCompat = notificationmanagerCompat.from(this);
        notificationmanagerCompat.notify(notificationId++,notification);
    }
项目:Cable-Android    文件AndroidAutoHeardReceiver.java   
@Override
protected void onReceive(final Context context,Intent intent,@Nullable final MasterSecret masterSecret)
{
  if (!HEARD_ACTION.equals(intent.getAction()))
    return;

  final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

  if (threadIds != null) {
    int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA,-1);
    notificationmanagerCompat.from(context).cancel(notificationId);

    new AsyncTask<Void,Void,Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();

        for (long threadId : threadIds) {
          Log.i(TAG,"Marking meassage as read: " + threadId);
          List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId,true);

          messageIdsCollection.addAll(messageIds);
        }

        MessageNotifier.updateNotification(context,masterSecret);
        MarkReadReceiver.process(context,messageIdsCollection);

        return null;
      }
    }.execute();
  }
}
项目:aftercare-app-android    文件DCSettingsActivity.java   
private void setupUI() {
    if (notificationmanagerCompat.from(this).areNotificationsEnabled()) {
        llSettingsEnableNotifications.setVisibility(View.GONE);
        llSettingsNotifications.setVisibility(View.VISIBLE);
    } else {
        llSettingsEnableNotifications.setVisibility(View.VISIBLE);
        llSettingsNotifications.setVisibility(View.GONE);
    }

    swSettingsSounds.setChecked(DcsoundManager.getInstance().isSoundEnabled());
    swSettingsMusic.setChecked(DcsoundManager.getInstance().isMusicEnabled());
    swSettingsVoice.setChecked(DcsoundManager.getInstance().isVoiceFemale());
    swSettingsDailyBrushing.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.DAILY_BrushING,false));
    swSettingsChangeBrush.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.CHANGE_Brush,false));
    swSettingsVisitDentist.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.VISIT_DENTIST,false));
    swSettingsReminderToVisit.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.REMINDER_TO_VISIT,false));
    swSettingsHealthyHabits.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.HEALTHY_HABIT,false));
    swSettingsEnableNotifications.setChecked(false);
}
项目:PeSanKita-android    文件MarkReadReceiver.java   
@Override
protected void onReceive(final Context context,@Nullable final MasterSecret masterSecret)
{
  if (!CLEAR_ACTION.equals(intent.getAction()))
    return;

  final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

  if (threadIds != null) {
    notificationmanagerCompat.from(context).cancel(intent.getIntExtra(NOTIFICATION_ID_EXTRA,-1));

    new AsyncTask<Void,Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();

        for (long threadId : threadIds) {
          Log.w(TAG,"Marking as read: " + threadId);
          List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId,true);
          messageIdsCollection.addAll(messageIds);
        }

        process(context,messageIdsCollection);

        MessageNotifier.updateNotification(context,masterSecret);

        return null;
      }
    }.execute();
  }
}
项目:PeSanKita-android    文件AndroidAutoHeardReceiver.java   
@Override
protected void onReceive(final Context context,true);
          DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);

          messageIdsCollection.addAll(messageIds);
        }

        MessageNotifier.updateNotification(context,messageIdsCollection);

        return null;
      }
    }.execute();
  }
}
项目:airgram    文件VideoEncodingService.java   
@Override
public void didReceivednotification(int id,Object... args) {
    if (id == NotificationCenter.FileUploadProgressChanged) {
        String fileName = (String)args[0];
        if (path != null && path.equals(fileName)) {
            Float progress = (Float) args[1];
            Boolean enc = (Boolean) args[2];
            currentProgress = (int)(progress * 100);
            builder.setProgress(100,currentProgress,currentProgress == 0);
            notificationmanagerCompat.from(ApplicationLoader.applicationContext).notify(4,builder.build());
        }
    } else if (id == NotificationCenter.stopEncodingService) {
        String filepath = (String)args[0];
        if (filepath == null || filepath.equals(path)) {
            stopSelf();
        }
    }
}
项目:airgram    文件VideoEncodingService.java   
public int onStartCommand(Intent intent,int flags,int startId) {
    path = intent.getStringExtra("path");
    if (path == null) {
        stopSelf();
        return Service.START_NOT_STICKY;
    }
    FileLog.e("tmessages","start video service");
    if (builder == null) {
        builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
        builder.setSmallIcon(android.R.drawable.stat_sys_upload);
        builder.setWhen(System.currentTimeMillis());
        builder.setContentTitle(LocaleController.getString("AppName",R.string.AppName));
        builder.setTicker(LocaleController.getString("SendingVideo",R.string.SendingVideo));
        builder.setContentText(LocaleController.getString("SendingVideo",R.string.SendingVideo));
    }
    currentProgress = 0;
    builder.setProgress(100,currentProgress == 0);
    startForeground(4,builder.build());
    notificationmanagerCompat.from(ApplicationLoader.applicationContext).notify(4,builder.build());
    return Service.START_NOT_STICKY;
}
项目:cordova-plugin-firebase-sdk    文件MessagingComponent.java   
public void hasPermission(final CallbackContext callbackContext) {
    mFirebase.cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            try {
                Log.i(TAG,"Checking permission");
                Context context = mFirebase.cordova.getActivity();
                notificationmanagerCompat notificationmanagerCompat = notificationmanagerCompat.from(context);
                boolean areNotificationsEnabled = notificationmanagerCompat.areNotificationsEnabled();
                JSONObject object = new JSONObject();
                object.put("isEnabled",areNotificationsEnabled);
                callbackContext.success(object);
            } catch (Exception e) {
                Log.e(TAG,"Error checking permission");
                callbackContext.error(e.getMessage());
            }
        }
    });
}
项目:AimsICDL    文件MiscUtils.java   
public static void showNotification(Context context,String tickertext,String contentText,@DrawableRes int drawable_id,boolean auto_cancel) {
    int NOTIFICATION_ID = 1;

    Intent notificationIntent = new Intent(context,MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND);

    PendingIntent contentIntent = PendingIntent.getActivity(
            context,NOTIFICATION_ID,notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);
    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),drawable_id);
    Notification notification =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(drawable_id)
                    .setLargeIcon(largeIcon)
                    .setTicker(tickertext)
                    .setContentTitle(context.getResources().getString(R.string.main_app_name))
                    .setContentText(contentText)
                    .setongoing(true)
                    .setAutoCancel(auto_cancel)
                    .setContentIntent(contentIntent)
                    .build();
    notificationmanagerCompat.from(context).notify(NOTIFICATION_ID,notification);
}
项目:Android-ProgressNotification    文件ApplyPremiumAccountService.java   
private void showServiceSucceednotification(String userId,ApplyPremiumAccountResult applyPremiumAccountResult) {
    Intent intent = new Intent(this,ResultActivity.class);
    intent.putExtra(EXTRA_USER_ID,userId);
    intent.putExtra(EXTRA_APPLY_PREMIUM_ACCOUNT_RESULT,applyPremiumAccountResult);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,intent,PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = new NotificationCompat.Builder(getApplicationContext(),GROUP_ID)
            .setSmallIcon(R.drawable.ic_request_done_small)
            .setContentTitle(getString(R.string.notification_your_request_is_done))
            .setContentText(getString(R.string.notification_click_here_to_resume_the_app))
            .setTicker(getString(R.string.notification_registered))
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(Notification.PRIORITY_HIGH)
            .setContentIntent(pendingIntent)
            .build();
    notificationmanagerCompat.from(this).notify(NOTIFICATION_ID_RESULT,notification);
}
项目:Android-ProgressNotification    文件ApplyPremiumAccountService.java   
private void showServiceFailedNotification(String userId) {
    Intent intent = new Intent(this,ApplyAccountActivity.class);
    intent.putExtra(EXTRA_USER_ID,userId);
    intent.setFlags(Intent.FLAG_ACTIVITY_broUGHT_TO_FRONT);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,GROUP_ID)
            .setSmallIcon(R.drawable.ic_request_Failed_small)
            .setContentTitle(getString(R.string.notification_your_request_has_been_denied))
            .setContentText(getString(R.string.notification_click_here_to_try_again_in_the_app))
            .setTicker(getString(R.string.notification_request_Failed))
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(Notification.PRIORITY_HIGH)
            .setContentIntent(pendingIntent)
            .build();
    notificationmanagerCompat.from(this).notify(NOTIFICATION_ID_RESULT,notification);
}
项目:MKAPP    文件ServiceSinkhole.java   
private void showdisablednotification() {
    Intent main = new Intent(this,ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this,main,PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff,tv,true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked))
            .setContentIntent(pi)
            .setColor(tv.data)
            .setongoing(false)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS)
                .setVisibility(Notification.VISIBILITY_SECRET);
    }

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_revoked));

    notificationmanagerCompat.from(this).notify(NOTIFY_disABLED,notification.build());
}
项目:MKAPP    文件ServiceSinkhole.java   
private void showAutoStartNotification() {
    Intent main = new Intent(this,ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_APPROVE,true);
    PendingIntent pi = PendingIntent.getActivity(this,NOTIFY_AUTOSTART,true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_autostart))
            .setContentIntent(pi)
            .setColor(tv.data)
            .setongoing(false)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS)
                .setVisibility(Notification.VISIBILITY_SECRET);
    }

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_autostart));

    notificationmanagerCompat.from(this).notify(NOTIFY_AUTOSTART,notification.build());
}
项目:MKAPP    文件ServiceSinkhole.java   
private void showUpdateNotification(String name,String url) {
    Intent download = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
    PendingIntent pi = PendingIntent.getActivity(this,download,PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary,true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_update))
            .setContentIntent(pi)
            .setColor(tv.data)
            .setongoing(false)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS)
                .setVisibility(Notification.VISIBILITY_SECRET);
    }

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_update));
    notification.setSummaryText(name);

    notificationmanagerCompat.from(this).notify(NOTIFY_UPDATE,notification.build());
}
项目:AndroidAudioExample    文件PlayerService.java   
private void refreshNotificationAndForegroundStatus(int playbackState) {
    switch (playbackState) {
        case PlaybackStateCompat.STATE_PLAYING: {
            startForeground(NOTIFICATION_ID,getNotification(playbackState));
            break;
        }
        case PlaybackStateCompat.STATE_PAUSED: {
            notificationmanagerCompat.from(PlayerService.this).notify(NOTIFICATION_ID,getNotification(playbackState));
            stopForeground(false);
            break;
        }
        default: {
            stopForeground(true);
            break;
        }
    }
}
项目:three-things-today    文件NotificationIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // Todo(smcgruer): Skip if today is already done.

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentTitle("Three Things Today")
            .setContentText("Record what happened today!")
            .setDefaults(NotificationCompat.DEFAULT_ALL)
            .setSmallIcon(R.drawable.ic_stat_name);
    Intent notifyIntent = new Intent(this,MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(
            this,notifyIntent,PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notificationCompat = builder.build();
    notificationmanagerCompat managerCompat = notificationmanagerCompat.from(this);
    managerCompat.notify(NOTIFICATION_ID,notificationCompat);
}
项目:Cable-Android    文件MarkReadReceiver.java   
@Override
protected void onReceive(final Context context,masterSecret);

        return null;
      }
    }.execute();
  }
}
项目:react-native-streaming-audio-player    文件Medianotificationmanager.java   
public Medianotificationmanager(AudioPlayerService service) throws remoteexception {
    mService = service;
    updateSessionToken();

    mnotificationmanager = notificationmanagerCompat.from(service);

    String pkg = mService.getPackageName();
    mPauseIntent = PendingIntent.getbroadcast(mService,REQUEST_CODE,new Intent(ACTION_PAUSE).setPackage(pkg),PendingIntent.FLAG_CANCEL_CURRENT);
    mPlayIntent = PendingIntent.getbroadcast(mService,new Intent(ACTION_PLAY).setPackage(pkg),PendingIntent.FLAG_CANCEL_CURRENT);
    mPrevIoUsIntent = PendingIntent.getbroadcast(mService,new Intent(ACTION_PREV).setPackage(pkg),PendingIntent.FLAG_CANCEL_CURRENT);
    mNextIntent = PendingIntent.getbroadcast(mService,new Intent(ACTION_NEXT).setPackage(pkg),PendingIntent.FLAG_CANCEL_CURRENT);

    // Cancel all notifications to handle the case where the Service was killed and
    // restarted by the system.
    mnotificationmanager.cancelAll();
}
项目:revolution-irc    文件Channelnotificationmanager.java   
public void setopened(Context context,boolean opened) {
    synchronized (this) {
        mOpened = opened;
        if (mOpened) {
            mMessages.clear();
            int prevCount = mUnreadMessageCount;
            mUnreadMessageCount = 0;
            notificationmanager.getInstance().callUnreadMessageCountCallbacks(mConnection,mChannel,prevCount);
            mStorage.requestResetChannelCounter(mConnection.getUUID(),getChannel());

            // cancel the notification
            notificationmanagerCompat.from(context).cancel(mNotificationId);
        }
    }
    notificationmanager.getInstance().updateSummaryNotification(context);
}
项目:AndroidProgramming3e    文件NotificationReceiver.java   
@Override
public void onReceive(Context c,Intent i) {
    Log.i(TAG,"received result: " + getResultCode());
    if (getResultCode() != Activity.RESULT_OK) {
        // A foreground activity cancelled the broadcast
        return;
    }

    int requestCode = i.getIntExtra(PollService.REQUEST_CODE,0);
    Notification notification = (Notification)
            i.getParcelableExtra(PollService.NOTIFICATION);

    notificationmanagerCompat notificationmanager = 
            notificationmanagerCompat.from(c);
    notificationmanager.notify(requestCode,notification);
}
项目:q-mail    文件NotificationController.java   
NotificationController(Context context,notificationmanagerCompat notificationmanager) {
    this.context = context;
    this.notificationmanager = notificationmanager;

    NotificationActionCreator actionBuilder = new NotificationActionCreator(context);
    certificateErrorNotifications = new CertificateErrorNotifications(this);
    authenticationErrorNotifications = new AuthenticationErrorNotifications(this);
    syncNotifications = new SyncNotifications(this,actionBuilder);
    sendFailedNotifications = new SendFailedNotifications(this,actionBuilder);
    newMailNotifications = NewMailNotifications.newInstance(this,actionBuilder);
}
项目:q-mail    文件SyncNotificationsTest.java   
private NotificationController createFakeNotificationController(notificationmanagerCompat notificationmanager,Builder builder) {
    NotificationController controller = mock(NotificationController.class);
    when(controller.getContext()).thenReturn(RuntimeEnvironment.application);
    when(controller.getnotificationmanager()).thenReturn(notificationmanager);
    when(controller.createNotificationBuilder()).thenReturn(builder);
    when(controller.getAccountName(any(Account.class))).thenReturn(ACCOUNT_NAME);
    return controller;
}
项目:q-mail    文件AuthenticationErrorNotificationsTest.java   
private NotificationController createFakeNotificationController(notificationmanagerCompat notificationmanager,NotificationCompat.Builder builder) {
    NotificationController controller = mock(NotificationController.class);
    when(controller.getContext()).thenReturn(RuntimeEnvironment.application);
    when(controller.getnotificationmanager()).thenReturn(notificationmanager);
    when(controller.createNotificationBuilder()).thenReturn(builder);
    return controller;
}
项目:q-mail    文件SendFailedNotificationsTest.java   
private NotificationController createFakeNotificationController(notificationmanagerCompat notificationmanager,Builder builder) {
    NotificationController controller = mock(NotificationController.class);
    when(controller.getContext()).thenReturn(RuntimeEnvironment.application);
    when(controller.getnotificationmanager()).thenReturn(notificationmanager);
    when(controller.createNotificationBuilder()).thenReturn(builder);
    return controller;
}
项目:device-messaging    文件MessageReadReceiver.java   
@Override
public void onReceive(Context context,Intent intent) {
    Log.d(TAG,"onReceive called");
    int conversationId = intent.getIntExtra(CONVERSATION_ID,-1);
    if (conversationId != -1) {
        Log.d(TAG,"Conversation " + conversationId + " was read");
        notificationmanagerCompat.from(context).cancel(conversationId);
    }
}
项目:LaravelNewsApp    文件Notify.java   
public static void showNewPostNotifications(){
    if (!Prefs.NotificationsEnabled()){
        return;
    }
    notificationPosts = PostRepository.getUnSeen();
    android.support.v4.app.NotificationCompat.InBoxStyle inBoxStyle = new android.support.v4.app.NotificationCompat.InBoxStyle();
        for(Post post : notificationPosts){
            inBoxStyle.addLine(post.getTitle());
        }
    //Notification sound
    SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(App.getAppContext());
    String strringtonePreference = preference.getString("notifications_new_message_ringtone","DEFAULT_SOUND");
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(App.getAppContext());
    mBuilder.setSmallIcon(R.drawable.ic_notifications)
            .setColor(App.getAppContext().getResources().getColor(R.color.brandColor))
            .setSound(Uri.parse(strringtonePreference))
            .setAutoCancel(true)
            .setContentTitle("Laravel News")
            .setContentText(getSummaryMessage())
            .setContentIntent(getNotificationIntent())
            .setStyle(inBoxStyle)
            .setGroup("LNA_NOTIFICATIONS_GROUP");

    //Check the vibrate
    if(Prefs.NotificationVibrateEnabled()){
        mBuilder.setVibrate(new long[]  {1000,1000});
    }

    Notification notification = mBuilder.build();
    // Issue the group notification
    notificationmanagerCompat notificationmanager = notificationmanagerCompat.from(App.getAppContext());
    notificationmanager.notify(1,notification);
}
项目:LaunchEnr    文件PermissionUtils.java   
private static boolean checkNotificationListenerPermission(Activity activity) {

        Set<String> enabledListeners = notificationmanagerCompat.getEnabledListenerPackages(activity);

        boolean isAccess = false;
        if (enabledListeners != null) {
            isAccess = enabledListeners.contains(activity.getPackageName());
        }

        return isAccess;
    }
项目:PeSanKita-android    文件MessageNotifier.java   
private static void sendMultipleThreadNotification(@NonNull  Context context,@NonNull  NotificationState notificationState,boolean signal)
{
  MultipleRecipientNotificationBuilder builder       = new MultipleRecipientNotificationBuilder(context,TextSecurePreferences.getNotificationPrivacy(context));
  List<NotificationItem>               notifications = notificationState.getNotifications();

  builder.setMessageCount(notificationState.getMessageCount(),notificationState.getThreadCount());
  builder.setMostRecentSender(notifications.get(0).getIndividualRecipient());
  builder.setGroup(NOTIFICATION_GROUP);

  long timestamp = notifications.get(0).getTimestamp();
  if (timestamp != 0) builder.setWhen(timestamp);

  builder.addActions(notificationState.getMarkAsReadIntent(context,SUMMARY_NOTIFICATION_ID));

  ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());

  while(iterator.hasPrevIoUs()) {
    NotificationItem item = iterator.prevIoUs();
    builder.addMessageBody(item.getIndividualRecipient(),item.getText());
  }

  if (signal) {
    builder.setAlarms(notificationState.getringtone(),notificationState.getVibrate());
    builder.setTicker(notifications.get(0).getIndividualRecipient(),notifications.get(0).getText());
  }

  notificationmanagerCompat.from(context).notify(SUMMARY_NOTIFICATION_ID,builder.build());
}
项目:Musicoco    文件PlayNotifyManager.java   
public PlayNotifyManager(Activity activity,IPlayControl control,DBMusicocoController dbController) {
    this.activity = activity;
    this.control = control;
    this.dbController = dbController;
    this.manager = notificationmanagerCompat.from(activity);
    this.playNotifyReceiver = new PlayNotifyReceiver();
}
项目:SuspendNotification    文件MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(this);
    editor = sharedPreferences.edit();
    title = (EditText)findViewById(R.id.title);
    content = (EditText)findViewById(R.id.content);
    manager = notificationmanagerCompat.from(this);
    setIsChecked();
    setIsCheckedBoot();
    setCheckedHideIcon();
    setCheckedHideNew();
    clipBoardMonitor();
    Log.d(TAG,"onCreate: ");
    boolean back = getIntent().getBooleanExtra("moveTaskToBack",false);
    if(back){
        moveTaskToBack(true);
        //Log.i(TAG,"onCreate: veTaskToBack");
    }
    //当前活动被销毁后再重建时保证调用onNewIntent()方法
    onNewIntent(getIntent());
    if (!isCheckedHideNew){
        notifAddNew();
    }
}
项目:WearVibrationCenter    文件TimedMuteManager.java   
private void unmute() {
    if (!mutedCurrently) {
        return;
    }

    mutedCurrently = false;
    notificationmanagerCompat.from(service).cancel(NOTIFICATION_ID_MUTE_DURATION);
    handler.removeCallbacksAndMessages(null);

    if (prevIoUsZenMode != 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        service.requestInterruptionFilterSafe(prevIoUsZenMode);
        prevIoUsZenMode = 0;
    }
}
项目:LucaHome-AndroidApplication    文件NotificationController.java   
public void CreateCameraNotification(
        int notificationId,@NonNull Class<?> receiverActivity) {

    if (!_settingsController.IsCameraNotificationEnabled()) {
        Logger.getInstance().Warning(TAG,"Not allowed to display camera notification!");
        return;
    }

    Bitmap bitmap = BitmapFactory.decodeResource(_context.getResources(),R.drawable.camera);
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().setHintHideIcon(true).setBackground(bitmap);
    RemoteViews remoteViews = new RemoteViews(_context.getPackageName(),R.layout.notification_camera);

    // Action for button show camera
    Intent goToSecurityIntent = new Intent(_context,receiverActivity);
    PendingIntent goToSecurityPendingIntent = PendingIntent.getActivity(_context,34678743,goToSecurityIntent,0);
    NotificationCompat.Action goToSecurityWearaction = new NotificationCompat.Action.Builder(R.drawable.camera,"Go to security",goToSecurityPendingIntent).build();

    remoteViews.setonClickPendingIntent(R.id.goToSecurity,goToSecurityPendingIntent);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(_context);
    builder.setSmallIcon(R.drawable.camera)
            .setContentTitle("Camera is active!")
            .setContentText("Go to security!")
            .setTicker("")
            .extend(wearableExtender)
            .addAction(goToSecurityWearaction);

    Notification notification = builder.build();
    notification.contentView = remoteViews;
    notification.bigContentView = remoteViews;

    notificationmanagerCompat notificationmanager = notificationmanagerCompat.from(_context);
    notificationmanager.notify(notificationId,notification);
}
项目:MKAPP    文件ServiceSinkhole.java   
private void stopStats() {
    Log.i(TAG,"Stats stop");
    stats = false;
    this.removeMessages(MSG_STATS_UPDATE);
    if (state == State.stats) {
        Log.d(TAG,"Stop foreground state=" + state.toString());
        stopForeground(true);
        state = State.none;
    } else
        notificationmanagerCompat.from(ServiceSinkhole.this).cancel(NOTIFY_TRAFFIC);
}
项目:mapBox-plugins-android    文件OfflineDownloadService.java   
@Override
public void onCreate() {
  super.onCreate();
  notificationmanager = notificationmanagerCompat.from(this);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    setupNotificationChannel();
  }
}
项目:Tasks    文件IndividualReceiver.java   
@Override
public void onReceive(Context context,"Receive result with code - " + getResultCode());
    if (getResultCode() != Activity.RESULT_OK){
        return;
    }

    int reqCode = intent.getIntExtra(IndividualService.REQ_CODE,0);
    Notification notification = intent.getParcelableExtra(IndividualService.NOTIFICATION);

    notificationmanagerCompat compat = notificationmanagerCompat.from(context);
    compat.notify(reqCode,notification);
}
项目:MyEyepetizer    文件ShowNotification.java   
@Override
public void onReceive(Context context,Intent intent) {
    if (getResultCode() != Activity.RESULT_OK) {
        return;
    }

    int requestCode = intent.getIntExtra(UpdateService.CODE_REQUEST,0);
    Notification notification = (Notification) intent.getParcelableExtra(UpdateService.NOTIFICATION);

    notificationmanagerCompat nmc = notificationmanagerCompat.from(context);
    nmc.notify(requestCode,notification);
}
项目:AndroidAudioExample    文件PlayerService.java   
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID,getString(R.string.notification_channel_name),notificationmanagerCompat.IMPORTANCE_DEFAULT);
        notificationmanager notificationmanager = (notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationmanager.createNotificationChannel(notificationChannel);

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .build();
        audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUdioFOCUS_GAIN)
                .setonAudioFocuschangelistener(audioFocuschangelistener)
                .setAcceptsDelayedFocusGain(false)
                .setwillPauseWhenDucked(true)
                .setAudioAttributes(audioAttributes)
                .build();
    }

    audioManager = (AudioManager) getSystemService(Context.AUdio_SERVICE);

    mediaSession = new MediaSessionCompat(this,"PlayerService");
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);

    Context appContext = getApplicationContext();

    Intent activityIntent = new Intent(appContext,MainActivity.class);
    mediaSession.setSessionActivity(PendingIntent.getActivity(appContext,activityIntent,0));

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON,null,appContext,MediaButtonReceiver.class);
    mediaSession.setMediaButtonReceiver(PendingIntent.getbroadcast(appContext,mediaButtonIntent,0));

    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this),new DefaultTrackSelector(),new DefaultLoadControl());
    exoPlayer.addListener(exoPlayerListener);
    DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(),Util.getUserAgent(this,getString(R.string.app_name)),null);
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"),new LeastRecentlyUsedCacheevictor(1024 * 1024 * 100)); // 100 Mb max
    this.dataSourceFactory = new CacheDataSourceFactory(cache,httpDataSourceFactory,CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGnorE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。