當前位置: 首頁>>代碼示例>>Java>>正文


Java NotificationCompat類代碼示例

本文整理匯總了Java中android.support.v7.app.NotificationCompat的典型用法代碼示例。如果您正苦於以下問題:Java NotificationCompat類的具體用法?Java NotificationCompat怎麽用?Java NotificationCompat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NotificationCompat類屬於android.support.v7.app包,在下文中一共展示了NotificationCompat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onReceive

import android.support.v7.app.NotificationCompat; //導入依賴的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: createNotification

import android.support.v7.app.NotificationCompat; //導入依賴的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

示例3: onStartCommand

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "WhiteService->onStartCommand");

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setContentTitle("Foreground");
    builder.setContentText("I am a foreground service");
    builder.setContentInfo("Content Info");
    builder.setWhen(System.currentTimeMillis());
    Intent activityIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    Notification notification = builder.build();
    startForeground(FOREGROUND_ID, notification);
    return super.onStartCommand(intent, flags, startId);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:WhiteService.java

示例4: onReceive

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder( context );

    builder.setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Test")
            .setContentText( intent.getStringExtra("text") )
            .setSubText("Three Line")
            .setContentInfo("info")
            .setWhen( System.currentTimeMillis() );

    manager.notify(0, builder.build());
    Log.d("onReceive", "はいったお!!!!!!!!");

}
 
開發者ID:OldBigBuddha,項目名稱:AlarmWithL-T,代碼行數:17,代碼來源:TestReceiver.java

示例5: onPreExecute

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
@Override
protected void onPreExecute() {
    b = new NotificationCompat.Builder(context);
    nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent resultIntent = new Intent(context, MainActivity.class);

    resultPendingIntent =
            PendingIntent.getActivity(
                    context,
                    0,
                    resultIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

    b.setAutoCancel(false)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon))
            .setSmallIcon(R.drawable.ic_battery_mgr_mod)
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setContentIntent(resultPendingIntent)
            .setOngoing(true)
    ;

}
 
開發者ID:erfanoabdi,項目名稱:BatteryModPercentage,代碼行數:24,代碼來源:NotifService.java

示例6: sendNotification

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("FCM Message")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
 
開發者ID:khokharnikunj8,項目名稱:SVNITChapters,代碼行數:21,代碼來源:MyFireBaseMessagingService.java

示例7: createNotification

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
private Notification createNotification() {
    LighthouseTrack track = service.getTrack();
    Podcast podcast = track.getPodcast();
    Record record = track.getRecord();

    RemoteViews remoteViews = new RemoteViews(service.getPackageName(), R.layout.notification);
    RemoteViews bigRemoteViews = new RemoteViews(service.getPackageName(), R.layout.notification_big);

    notificationBuilder.setSmallIcon(R.drawable.notification_icon)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentTitle(podcast.getName())
            .setContent(remoteViews)
            .setCustomBigContentView(bigRemoteViews)
            .setContentIntent(createContentIntent(podcast, record));

    setRecordState(remoteViews, podcast, record);
    setRecordState(bigRemoteViews, podcast, record);

    setPlayPauseState(remoteViews);
    setPlayPauseState(bigRemoteViews);

    setNotificationPlaybackState(bigRemoteViews);

    return notificationBuilder.build();
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:26,代碼來源:MediaNotificationManager.java

示例8: saveOneRecord

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
/**
 * save one activity record
 * @param activityRecord record to save
 * @return the file path this record is saved
 */
public static boolean saveOneRecord(ActivityRecord activityRecord) {
    boolean ret = saveOneRecord(activityRecord.toJsonString());
    if (ret) {
        Application app = StallBuster.getInstance().getApp();
        Intent intent = new Intent(StallBuster.getInstance().getApp(), ReportListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(StallBuster.getInstance().getApp(), 1, intent, FLAG_UPDATE_CURRENT);
        NotificationManager nm = (NotificationManager)app.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(NOTIFICATION_ID);
        Notification notification = new NotificationCompat.Builder(app)
                .setAutoCancel(true)
                .setContentTitle(app.getString(R.string.notification_title, activityRecord.cost, activityRecord.activity_name))
                .setContentText(app.getString(R.string.notification_text))
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setContentIntent(pendingIntent)
                .build();
        nm.notify(NOTIFICATION_ID, notification);
    }
    return ret;
}
 
開發者ID:zhangjianli,項目名稱:StallBuster,代碼行數:26,代碼來源:RecordsStore.java

示例9: mainNotification

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
private NotificationCompat.Builder mainNotification() {
    if (mainNotification == null) {
        mainNotification = new NotificationCompat.Builder(this);
        mainNotification.setAutoCancel(false);
        mainNotification.setSmallIcon(R.drawable.ic_play);

        // Close app on dismiss
        Intent intentDismiss = new Intent(this, NotificationDismissedReceiver.class);
        intentDismiss.putExtra("com.my.app.notificationId", notificationId);
        PendingIntent pendingDelete = PendingIntent.getBroadcast(this, notificationId, intentDismiss, 0);
        mainNotification.setDeleteIntent(pendingDelete);

        // Set focus to MainActivity
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        PendingIntent pendingContent = PendingIntent.getBroadcast(this, notificationId, intent, 0);
        mainNotification.setContentIntent(pendingContent);
    }
    return mainNotification;
}
 
開發者ID:sovteam,項目名稱:buddybox,代碼行數:21,代碼來源:MainActivity.java

示例10: notifyCommand

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
/**
 * led command notification
 * @param argbColor    led color
 * @return running result
 */
public boolean notifyCommand(int argbColor) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    if (argbColor == COLOR.NONE.getLocalColor()) {
        notificationManager.cancel(NOTIFICATION_ID);
    }
    else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.mipmap.icon_color_big);
        builder.setContentTitle(context.getResources().getString(R.string.actuator_led_notification));
        builder.setLights(argbColor, 1000, 0);

        notificationManager.notify(NOTIFICATION_ID, builder.build());
    }

    return true;
}
 
開發者ID:SKT-ThingPlug,項目名稱:thingplug-sdk-android,代碼行數:23,代碼來源:Led.java

示例11: sendNotification

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, StartingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.bee_logo_app)
            .setContentTitle("Alert")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
 
開發者ID:sarikaya,項目名稱:Bee-Analyzer,代碼行數:18,代碼來源:MyFirebaseMessagingService.java

示例12: from

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
/**
 * Build a notification using the information from the given media session. Makes heavy use
 * of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
 *
 * @param context      Context used to construct the notification.
 * @param mediaSession Media session to get information.
 * @return A pre-built notification with information from the given media session.
 */
static NotificationCompat.Builder from(
        Context context, MediaSessionCompat mediaSession) {
    MediaControllerCompat controller = mediaSession.getController();
    MediaMetadataCompat mediaMetadata = controller.getMetadata();
    MediaDescriptionCompat description = mediaMetadata.getDescription();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setSubText(description.getDescription())
            .setLargeIcon(description.getIconBitmap())
            .setContentIntent(controller.getSessionActivity())
            .setDeleteIntent(
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    return builder;
}
 
開發者ID:SergeyVinyar,項目名稱:AndroidAudioExample,代碼行數:27,代碼來源:MediaStyleHelper.java

示例13: showTranslateInfo

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
private void showTranslateInfo(final Translate translate){

        String result=translate.getTranslation()[0];

        NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(ClipboardService.this)
                                        .setSmallIcon(R.drawable.small_icon)
                                        .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                                        .setContentTitle(getString(R.string.app_name))
                                        .setContentText(result)
                                        .setWhen(System.currentTimeMillis())
                                        .setPriority(Notification.PRIORITY_DEFAULT)
                                        .setStyle(new NotificationCompat.BigTextStyle().bigText(result));

                                Intent shareIntent = new Intent().setAction(Intent.ACTION_SEND).setType("text/plain");
                                shareIntent.putExtra(Intent.EXTRA_TEXT,result);

                                PendingIntent sharePi = PendingIntent.getActivity(ClipboardService.this,0,shareIntent,0);

                                mBuilder.addAction(R.drawable.ic_share_white_24dp,getString(R.string.share),sharePi);

                                NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                                manager.notify(0,mBuilder.build());

    }
 
開發者ID:zhaoweihaoChina,項目名稱:MrTranslator,代碼行數:25,代碼來源:ClipboardService.java

示例14: showNotification

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
static public void showNotification(Context context, String msg) {
    NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notificationManager.notify(1,
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_notification_icon)
                    .setColor(Util.getColor(context, R.color.colorPrimary))
                    .setContentTitle(context.getString(R.string.app_name))
                    .setContentText(msg)
                    .setContentIntent(pendingIntent)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(msg))
                    .build());
}
 
開發者ID:Faerbit,項目名稱:android-crond,代碼行數:18,代碼來源:MainActivity.java

示例15: createNotification

import android.support.v7.app.NotificationCompat; //導入依賴的package包/類
/**
 * Creates the notification
 * 
 * @param messageResId
 *            message resource id. The message must have one String parameter,<br />
 *            f.e. <code>&lt;string name="name"&gt;%s is connected&lt;/string&gt;</code>
 * @param defaults
 *            signals that will be used to notify the user
 */
private void createNotification(final int messageResId, final int defaults) {
	final Intent parentIntent = new Intent(this, FeaturesActivity.class);
	parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	final Intent targetIntent = new Intent(this, HTSActivity.class);

	final Intent disconnect = new Intent(ACTION_DISCONNECT);
	final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT);

	// both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed
	final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[] { parentIntent, targetIntent }, PendingIntent.FLAG_UPDATE_CURRENT);
	final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
	builder.setContentIntent(pendingIntent);
	builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName()));
	builder.setSmallIcon(R.drawable.ic_stat_notify_hts);
	builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true);
	builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.hts_notification_action_disconnect), disconnectAction));

	final Notification notification = builder.build();
	final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	nm.notify(NOTIFICATION_ID, notification);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:31,代碼來源:HTSService.java


注:本文中的android.support.v7.app.NotificationCompat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。