当前位置: 首页>>代码示例>>Java>>正文


Java NotificationManagerCompat类代码示例

本文整理汇总了Java中android.support.v4.app.NotificationManagerCompat的典型用法代码示例。如果您正苦于以下问题:Java NotificationManagerCompat类的具体用法?Java NotificationManagerCompat怎么用?Java NotificationManagerCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NotificationManagerCompat类属于android.support.v4.app包,在下文中一共展示了NotificationManagerCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
@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, 0, 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();
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:26,代码来源:WaterReminderReceiver.java

示例2: sendNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
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, 0, 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, 0, 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);
    }
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:24,代码来源:NotificationUpdateService.java

示例3: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
@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();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:34,代码来源:AndroidAutoHeardReceiver.java

示例4: setupUI

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
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);
}
 
开发者ID:Dentacoin,项目名称:aftercare-app-android,代码行数:20,代码来源:DCSettingsActivity.java

示例5: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
@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) {
        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();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:32,代码来源:MarkReadReceiver.java

示例6: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
@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);
          DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);

          messageIdsCollection.addAll(messageIds);
        }

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

        return null;
      }
    }.execute();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:35,代码来源:AndroidAutoHeardReceiver.java

示例7: didReceivedNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
@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();
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:19,代码来源:VideoEncodingService.java

示例8: onStartCommand

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
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, currentProgress == 0);
    startForeground(4, builder.build());
    NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build());
    return Service.START_NOT_STICKY;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:22,代码来源:VideoEncodingService.java

示例9: hasPermission

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
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());
            }
        }
    });
}
 
开发者ID:jsayol,项目名称:cordova-plugin-firebase-sdk,代码行数:19,代码来源:MessagingComponent.java

示例10: showNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
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);
}
 
开发者ID:5GSD,项目名称:AIMSICDL,代码行数:23,代码来源:MiscUtils.java

示例11: showServiceSucceedNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
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, 0, 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);
}
 
开发者ID:akexorcist,项目名称:Android-ProgressNotification,代码行数:18,代码来源:ApplyPremiumAccountService.java

示例12: showServiceFailedNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
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, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = new NotificationCompat.Builder(getApplicationContext(), 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);
}
 
开发者ID:akexorcist,项目名称:Android-ProgressNotification,代码行数:18,代码来源:ApplyPremiumAccountService.java

示例13: showDisabledNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, 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());
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:26,代码来源:ServiceSinkhole.java

示例14: showAutoStartNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
private void showAutoStartNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_APPROVE, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, 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_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());
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:27,代码来源:ServiceSinkhole.java

示例15: showUpdateNotification

import android.support.v4.app.NotificationManagerCompat; //导入依赖的package包/类
private void showUpdateNotification(String name, String url) {
    Intent download = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    PendingIntent pi = PendingIntent.getActivity(this, 0, download, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, 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());
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:27,代码来源:ServiceSinkhole.java


注:本文中的android.support.v4.app.NotificationManagerCompat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。