类android.support.v4.app.NotificationManagerCompat源码实例Demo

下面列出了怎么用android.support.v4.app.NotificationManagerCompat的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: SEAL-Demo   文件: SyncDataService.java
@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (REFRESH_ITEMS_ACTION.equals(action)) {
            Log.d(TAG, "Refresh items START");
            Analytics.trackEvent(TAG + " Refresh run items START");
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
            notificationManager.notify(NOTIFICATION_ID, buildNotification("AsureRun", "Syncing data...", R.drawable.ic_tracking, null));
            handleRefreshItems(notificationManager, false);
        } else if (DELETE_DATA_ON_FIRST_START_ACTION.equals(action)) {
            Log.d(TAG, "Delete data on first start");
            Analytics.trackEvent(TAG + " Delete data on first start");
            handleDeleteDataOnFirstStart();
        } else if (SEND_ITEM_ACTION.equals(action)) {
            Log.d(TAG, "Sending data on server");
            handleSendDataOnServer();
        }
    }
}
 
源代码2 项目: Small   文件: NotifyResultActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pending);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mNotificationId = getIntent().getIntExtra("notification_id", 0);
    TextView textView = (TextView) findViewById(R.id.notification_id_label);
    textView.setText(mNotificationId + "");

    Button removeButton = (Button) findViewById(R.id.remove_notification_button);
    removeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            NotificationManagerCompat.from(NotifyResultActivity.this).cancel(mNotificationId);
        }
    });
}
 
public MediaNotificationManager(Context context, MediaSessionCompat.Token sessionToken) throws RemoteException {
    mContext = context;
    mSessionToken = sessionToken;
    updateSessionToken();

    mNotificationManager = NotificationManagerCompat.from(context);

    String pkg = context.getPackageName();
    mPauseIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
            new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
    mPlayIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
            new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
    mPreviousIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
            new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
    mNextIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
            new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
    mStopIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
            new Intent(ACTION_STOP).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
    mStopCastIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
            new Intent(ACTION_STOP_CASTING).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();
}
 
源代码4 项目: wearable   文件: MainActivity.java
void simpleNoti() {
	
	//create the intent to launch the notiactivity, then the pentingintent.
	Intent viewIntent = new Intent(this, NotiActivity.class);
	viewIntent.putExtra("NotiID", "Notification ID is " + notificationID);
	
	PendingIntent viewPendingIntent =
	        PendingIntent.getActivity(this, 0, viewIntent, 0);

	//Now create the notification.  We must use the NotificationCompat or it will not work on the wearable.
	NotificationCompat.Builder notificationBuilder =
	        new NotificationCompat.Builder(this)
	        .setSmallIcon(R.drawable.ic_launcher)
	        .setContentTitle("Simple Noti")
	        .setContentText("This is a simple notification")
	        .setContentIntent(viewPendingIntent);

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

	// Build the notification and issues it with notification manager.
	notificationManager.notify(notificationID, notificationBuilder.build());
	notificationID++;
}
 
源代码5 项目: SuntimesWidget   文件: AlarmNotifications.java
private AlarmDatabaseAdapter.AlarmItemTaskListener onShowState(final Context context)
{
    return new AlarmDatabaseAdapter.AlarmItemTaskListener()
    {
        @Override
        public void onFinished(Boolean result, AlarmClockItem item)
        {
            Log.d(TAG, "State Saved (onShow)");
            if (item.type == AlarmClockItem.AlarmType.ALARM)
            {
                if (!NotificationManagerCompat.from(context).areNotificationsEnabled())
                {
                    // when notifications are disabled, fallback to directly starting the fullscreen activity
                    startActivity(getFullscreenIntent(context, item.getUri()));

                } else {
                    showAlarmPlayingToast(getApplicationContext(), item);
                    context.sendBroadcast(getFullscreenBroadcast(item.getUri()));   // update fullscreen activity
                }
            }
        }
    };
}
 
源代码6 项目: rcloneExplorer   文件: FirebaseMessagingService.java
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    setNotificationChannel();

    Uri uri = Uri.parse(getString(R.string.app_latest_release_url));
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getString(R.string.app_update_notification_title))
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(33, builder.build());
}
 
源代码7 项目: blade-player   文件: PlayerNotification.java
PlayerNotification(PlayerService service)
{
    this.mService = service;

    mNotificationManager = NotificationManagerCompat.from(service);

    mPlayAction = new NotificationCompat.Action(R.drawable.play_arrow, mService.getString(R.string.play),
            MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_PLAY));
    mPauseAction = new NotificationCompat.Action(R.drawable.pause_notif, mService.getString(R.string.pause),
            MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_PAUSE));
    mNextAction = new NotificationCompat.Action(R.drawable.next_arrow_notif, mService.getString(R.string.next),
            MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_SKIP_TO_NEXT));
    mPrevAction = new NotificationCompat.Action(R.drawable.prev_arrow_notif, mService.getString(R.string.prev),
            MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS));

    mNotificationManager.cancelAll();
}
 
@Override
public void onReceive(Context context, Intent intent) {
  // Get the lifeform details from the intent.
  String type = intent.getStringExtra(EXTRA_LIFEFORM_NAME);
  double lat = intent.getDoubleExtra(EXTRA_LATITUDE, Double.NaN);
  double lng = intent.getDoubleExtra(EXTRA_LONGITUDE, Double.NaN);

  if (type.equals(FACE_HUGGER)) {
    NotificationManagerCompat notificationManager =
      NotificationManagerCompat.from(context);

    NotificationCompat.Builder builder =
      new NotificationCompat.Builder(context);

    builder.setSmallIcon(R.drawable.ic_alien)
      .setContentTitle("Face Hugger Detected")
      .setContentText(Double.isNaN(lat) || Double.isNaN(lng) ?
                        "Location Unknown" :
                        "Located at " + lat + "," + lng);

    notificationManager.notify(NOTIFICATION_ID, builder.build());
  }
}
 
源代码9 项目: KUAS-AP-Material   文件: NotificationHelper.java
/**
 * Create a notification
 *
 * @param context The application context
 * @param title   Notification title
 * @param content Notification content.
 */
public static void createNotification(final Context context, final String title,
                                      final String content, int id) {
	NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

	NotificationCompat.Builder builder =
			new NotificationCompat.Builder(context).setContentTitle(title)
					.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
					.setColor(ContextCompat.getColor(context, R.color.main_theme))
					.extend(new NotificationCompat.WearableExtender()
							.setHintShowBackgroundOnly(true)).setContentText(content)
					.setAutoCancel(true).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
					.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0))
					.setSmallIcon(R.drawable.ic_stat_kuas_ap);

	builder.setVibrate(vibrationPattern);
	builder.setLights(Color.GREEN, 800, 800);
	builder.setDefaults(Notification.DEFAULT_SOUND);

	notificationManager.notify(id, builder.build());
}
 
源代码10 项目: OsmGo   文件: LocalNotificationManager.java
@Nullable
public JSONArray schedule(PluginCall call, List<LocalNotification> localNotifications) {
  JSONArray ids = new JSONArray();
  NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

  boolean notificationsEnabled = notificationManager.areNotificationsEnabled();
  if (!notificationsEnabled) {
    call.error("Notifications not enabled on this device");
    return null;
  }
  for (LocalNotification localNotification : localNotifications) {
    Integer id = localNotification.getId();
    if (localNotification.getId() == null) {
      call.error("LocalNotification missing identifier");
      return null;
    }
    dismissVisibleNotification(id);
    cancelTimerForNotification(id);
    buildNotification(notificationManager, localNotification, call);
    ids.put(id);
  }
  return ids;
}
 
@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, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notificationCompat = builder.build();
    NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
    managerCompat.notify(NOTIFICATION_ID, notificationCompat);
}
 
源代码12 项目: share-to-delete   文件: AutoCleanService.java
@Override
public boolean onStartJob(JobParameters params) {
    context = this;
    notificationManagerCompat = NotificationManagerCompat.from(context);
    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    if (!preferences.getBoolean(AutoCleanSettingsActivity.PREF_AUTO_CLEAN, false)) return false;
    sendNotification();
    cleanUp();
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Log.v(MyUtil.PACKAGE_NAME, getString(R.string.toast_auto_clean, deletedFileCount));
            Toast.makeText(
                    context,
                    getString(R.string.toast_auto_clean, deletedFileCount),
                    Toast.LENGTH_SHORT
            ).show();
            notificationManagerCompat.cancel(NOTIFICATION_JOB_ID);
        }
    }, 3000);
    return true;
}
 
@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);
}
 
源代码14 项目: Silence   文件: MarkReadReceiver.java
@Override
protected void onReceive(final Context context, Intent intent,
                         @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, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        for (long threadId : threadIds) {
          Log.w(TAG, "Marking as read: " + threadId);
          DatabaseFactory.getThreadDatabase(context).setRead(threadId);
          DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
        }

        MessageNotifier.updateNotification(context, masterSecret);
        return null;
      }
    }.execute();
  }
}
 
源代码15 项目: AndroidDemoProjects   文件: IterationActivity.java
private void setupTimer( long duration ) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from( this );
    notificationManager.cancel( 1 );
    notificationManager.notify( 1, buildNotification( duration ) );
    registerAlarmManager(duration);
    finish();
}
 
/**
 * Displays a notification.
 * @param platformTag The notification tag, see
 *                    {@link NotificationManager#notify(String, int, Notification)}.
 * @param platformId The notification id, see
 *                   {@link NotificationManager#notify(String, int, Notification)}.
 * @param notification The notification to be displayed, constructed by the provider.
 * @param channelName The name of the notification channel that the notification should be
 *                    displayed on. This method gets or creates a channel from the name and
 *                    modifies the notification to use that channel.
 * @return Whether the notification was successfully displayed (the channel/app may be blocked
 *         by the user).
 */
protected boolean notifyNotificationWithChannel(String platformTag, int platformId,
        Notification notification, String channelName) {
    ensureOnCreateCalled();

    if (!NotificationManagerCompat.from(this).areNotificationsEnabled()) return false;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String channelId = channelNameToId(channelName);
        // Create the notification channel, (no-op if already created).
        mNotificationManager.createNotificationChannel(new NotificationChannel(channelId,
                channelName, NotificationManager.IMPORTANCE_DEFAULT));

        // Check that the channel is enabled.
        if (mNotificationManager.getNotificationChannel(channelId).getImportance() ==
                NotificationManager.IMPORTANCE_NONE) {
            return false;
        }

        // Set our notification to have that channel.
        Notification.Builder builder = Notification.Builder.recoverBuilder(this, notification);
        builder.setChannelId(channelId);
        notification = builder.build();
    }

    mNotificationManager.notify(platformTag, platformId, notification);
    return true;
}
 
源代码17 项目: YTPlayer   文件: SongBroadCast.java
public void disableContext(Context context) {
    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
    notificationManagerCompat.cancel(1);
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.deleteNotificationChannel("channel_01");
    }
    Process.killProcess(Process.myPid());
}
 
源代码18 项目: TelePlus-Android   文件: VoIPService.java
protected void startRinging() {
	if(currentState==STATE_WAITING_INCOMING){
		return;
	}
	if(USE_CONNECTION_SERVICE && systemCallConnection!=null)
		systemCallConnection.setRinging();
       if (BuildVars.LOGS_ENABLED) {
           FileLog.d("starting ringing for call " + call.id);
       }
	dispatchStateChanged(STATE_WAITING_INCOMING);
	startRingtoneAndVibration(user.id);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode() && NotificationManagerCompat.from(this).areNotificationsEnabled()) {
		showIncomingNotification(ContactsController.formatName(user.first_name, user.last_name), null, user, null, 0, VoIPActivity.class);
           if (BuildVars.LOGS_ENABLED) {
               FileLog.d("Showing incoming call notification");
           }
	} else {
           if (BuildVars.LOGS_ENABLED) {
               FileLog.d("Starting incall activity for incoming call");
           }
		try {
			PendingIntent.getActivity(VoIPService.this, 12345, new Intent(VoIPService.this, VoIPActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0).send();
		} catch (Exception x) {
               if (BuildVars.LOGS_ENABLED) {
                   FileLog.e("Error starting incall activity", x);
               }
		}
		if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
			showNotification();
		}
	}
}
 
源代码19 项目: TelePlus-Android   文件: VoIPService.java
public void onUIForegroundStateChanged(boolean isForeground) {
	if (currentState == STATE_WAITING_INCOMING) {
		if (isForeground) {
			stopForeground(true);
		} else {
			if (!((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()) {
				if(NotificationManagerCompat.from(this).areNotificationsEnabled())
					showIncomingNotification(ContactsController.formatName(user.first_name, user.last_name), null, user, null, 0, VoIPActivity.class);
				else
					declineIncomingCall(DISCARD_REASON_LINE_BUSY, null);
			} else {
				AndroidUtilities.runOnUIThread(new Runnable() {
					@Override
					public void run() {
						Intent intent = new Intent(VoIPService.this, VoIPActivity.class);
						intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
						try {
							PendingIntent.getActivity(VoIPService.this, 0, intent, 0).send();
						} catch (PendingIntent.CanceledException e) {
                               if (BuildVars.LOGS_ENABLED) {
                                   FileLog.e("error restarting activity", e);
                               }
							declineIncomingCall(DISCARD_REASON_LINE_BUSY, null);
						}
						if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
							showNotification();
						}
					}
				}, 500);
			}
		}
	}
}
 
源代码20 项目: xDrip   文件: ActivityRecognizedService.java
private void raise_vehicle_notification(String msg) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentText(msg);
    builder.setSmallIcon(R.drawable.ic_launcher);
    if (VehicleMode.shouldPlaySound()) {
        setInternalPrefsLong(VEHICLE_MODE_LAST_ALERT, JoH.tsl());
        builder.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.labbed_musical_chime));
    }
    builder.setContentTitle(getString(R.string.app_name) + " " + "Vehicle mode");
    cancel_vehicle_notification();
    NotificationManagerCompat.from(this).notify(VEHICLE_NOTIFICATION_ID, builder.build());
}
 
/**
 * Create a notification manager for the specified service
 * @param service service to manage
 */
TransferNotificationManager(Service service) {
    mService = service;
    mSettings = new Settings(service);
    mNotificationManager = (NotificationManager) mService.getSystemService(
            Service.NOTIFICATION_SERVICE);

    // Android O requires the notification channels to be created
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createChannel(SERVICE_CHANNEL_ID, R.string.channel_service_name,
                NotificationManager.IMPORTANCE_MIN, false);
        createChannel(TRANSFER_CHANNEL_ID, R.string.channel_transfer_name,
                NotificationManager.IMPORTANCE_LOW, false);
        createChannel(NOTIFICATION_CHANNEL_ID, R.string.channel_notification_name,
                NotificationManager.IMPORTANCE_DEFAULT, true);
    }

    // Create the intent for opening the main activity
    mIntent = PendingIntent.getActivity(
            mService,
            0,
            new Intent(mService, TransferActivity.class),
            0
    );

    // Create the builder
    mBuilder = createBuilder(SERVICE_CHANNEL_ID)
            .setContentIntent(mIntent)
            .setContentTitle(mService.getString(R.string.service_transfer_server_title))
            .setSmallIcon(R.drawable.ic_stat_transfer);

    // Set the priority
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mBuilder.setPriority(NotificationManagerCompat.IMPORTANCE_MIN);
    } else {
        mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
    }
}
 
源代码22 项目: android-sdk   文件: SensorbergReceiver.java
public static void showNotification(Context context, int id, String title, String content, Uri uri, Action action) {

        if (NotificationManagerCompat.from(context).areNotificationsEnabled()) {
            Intent intent = new Intent(context, MainActivity.class);
            intent.putExtra("conversion", action.getInstanceUuid());

            PendingIntent openApplicationWithAction = PendingIntent.getActivity(
                    context,
                    0,
                    intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            Notification notification = new NotificationCompat.Builder(context, OREO_NOTIFICATION_CHANNEL)
                    .setContentIntent(openApplicationWithAction)
                    .setContentTitle(title)
                    .setContentText(content)
                    .setSmallIcon(R.drawable.ic_beacon)
                    .setAutoCancel(true)
                    .setShowWhen(true)
                    .build();
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(id, notification);
            SensorbergSdk.notifyConversionStatus(context, action.getInstanceUuid(), Conversion.NOTIFICATION_SHOWN);
        } else {
            SensorbergSdk.notifyConversionStatus(context, action.getInstanceUuid(), Conversion.NOTIFICATION_DISABLED);
        }


    }
 
源代码23 项目: wear   文件: NotificationUtils.java
public static void showGroupNotifications(Context context, String group) {
    Notification first = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(context.getString(R.string.page1_title))
            .setContentText(context.getString(R.string.page1_text))
            .setGroup(group)
            .build();

    Notification second = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(context.getString(R.string.page2_title))
            .setContentText(context.getString(R.string.page2_text))
            .setGroup(group)
            .build();

    Notification summary = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(context.getString(R.string.summary_title))
            .setContentText(context.getString(R.string.summary_text))
            .setGroup(group)
            .setGroupSummary(true)
            .build();

    NotificationManagerCompat.from(context).notify(getNewID(), first);
    NotificationManagerCompat.from(context).notify(getNewID(), second);
    NotificationManagerCompat.from(context).notify(getNewID(), summary);
}
 
/**
 * 是否已经授予通知相关权限
 *
 * @param context,上下文对象
 * @return
 */
private boolean isNotificationListenerServiceEnabled(Context context) {
    Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(context);
    if (packageNames.contains(context.getPackageName())) {
        return true;
    }
    return false;
}
 
源代码25 项目: EasyNLU   文件: ReminderReceiver.java
void showNotification(int id, String text, Context context){
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context, ReminderScheduler.CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_alarm_black_24dp)
            .setContentTitle("Reminder")
            .setContentText(text + "!")
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setPriority(NotificationCompat.PRIORITY_HIGH);
            //.setAutoCancel(true);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(id, builder.build());
}
 
源代码26 项目: NightWatch   文件: Notifications.java
private void bgOngoingNotification(final BgGraphBuilder bgGraphBuilder) {
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            NotificationManagerCompat
                    .from(mContext)
                    .notify(ongoingNotificationId, createOngoingNotification(bgGraphBuilder, mContext));
            if (iconBitmap != null)
                iconBitmap.recycle();
            if (notifiationBitmap != null)
                notifiationBitmap.recycle();
        }
    });
}
 
源代码27 项目: rcloneExplorer   文件: DownloadService.java
private void updateNotification(FileItem downloadItem, String content, String[] bigTextArray) {
    StringBuilder bigText = new StringBuilder();
    for (int i = 0; i < bigTextArray.length; i++) {
        bigText.append(bigTextArray[i]);
        if (i < 4) {
            bigText.append("\n");
        }
    }

    Intent foregroundIntent = new Intent(this, DownloadService.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);

    Intent cancelIntent = new Intent(this, DownloadCancelAction.class);
    PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, 0, cancelIntent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_download)
            .setContentTitle(downloadItem.getName())
            .setContentText(content)
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()))
            .addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent);

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(PERSISTENT_NOTIFICATION_ID, builder.build());
}
 
源代码28 项目: io2015-codelabs   文件: 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);
    }
}
 
源代码29 项目: rcloneExplorer   文件: DownloadService.java
private void createSummaryNotificationForFinished() {
    Notification summaryNotification =
            new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setContentTitle(getString(R.string.download_complete))
                    //set content text to support devices running API level < 24
                    .setContentText(getString(R.string.download_complete))
                    .setSmallIcon(android.R.drawable.stat_sys_download_done)
                    .setGroup(DOWNLOAD_FINISHED_GROUP)
                    .setGroupSummary(true)
                    .setAutoCancel(true)
                    .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, summaryNotification);
}
 
源代码30 项目: rcloneExplorer   文件: DownloadService.java
private void showDownloadFailedNotification(int notificationId, String contentText) {
    createSummaryNotificationForFailed();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_warning)
            .setContentTitle(getString(R.string.download_failed))
            .setContentText(contentText)
            .setGroup(DOWNLOAD_FAILED_GROUP)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId, builder.build());
}