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


Java Notification类代码示例

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


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

示例1: createFakeSms

import android.app.Notification; //导入依赖的package包/类
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);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:PretendSMSUtils.java

示例2: setUp

import android.app.Notification; //导入依赖的package包/类
@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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:NotificationTargetTest.java

示例3: setLights

import android.app.Notification; //导入依赖的package包/类
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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:NotificationCompat.java

示例4: onCreate

import android.app.Notification; //导入依赖的package包/类
@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());
    }
}
 
开发者ID:AyushR1,项目名称:KernelAdiutor-Mod,代码行数:20,代码来源:ApplyOnBootService.java

示例5: showNotification

import android.app.Notification; //导入依赖的package包/类
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();
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:27,代码来源:OnekeyShare.java

示例6: beforeInvoke

import android.app.Notification; //导入依赖的package包/类
@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;
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:26,代码来源:INotificationManagerHookHandle.java

示例7: addAction

import android.app.Notification; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:22,代码来源:NotificationBuilderBase.java

示例8: sendNotification

import android.app.Notification; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:googlesamples,项目名称:android-NotificationChannels,代码行数:30,代码来源:MainActivity.java

示例9: processAlertNotification

import android.app.Notification; //导入依赖的package包/类
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());

    }
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:24,代码来源:GcmMessageHandler.java

示例10: openNotification

import android.app.Notification; //导入依赖的package包/类
/**
 * 打开通知栏消息
 */
@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();
    }
}
 
开发者ID:mcxtzhang,项目名称:miser-utils,代码行数:18,代码来源:ComeOnMoneyService.java

示例11: notificationMethod

import android.app.Notification; //导入依赖的package包/类
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;
}
 
开发者ID:Omico,项目名称:CurrentActivity,代码行数:20,代码来源:FloatViewService.java

示例12: buildNotification

import android.app.Notification; //导入依赖的package包/类
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());
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:31,代码来源:NotificationHelper.java

示例13: createNotification

import android.app.Notification; //导入依赖的package包/类
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();
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:27,代码来源:TrackNotification.java

示例14: onMessageReceived

import android.app.Notification; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:emartech,项目名称:android-mobile-engage-sdk,代码行数:24,代码来源:MobileEngageMessagingService.java

示例15: showNotification

import android.app.Notification; //导入依赖的package包/类
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);
}
 
开发者ID:Vicent9920,项目名称:FanChat,代码行数:23,代码来源:QQDemoApplication.java


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