Java 类android.app.PendingIntent 实例源码

项目:PeSanKita-android    文件:ExpirationListener.java   
public static void setAlarm(Context context, long waitTimeMillis) {
  Intent        intent        = new Intent(context, ExpirationListener.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
  AlarmManager  alarmManager  = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

  alarmManager.cancel(pendingIntent);
  alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + waitTimeMillis, pendingIntent);
}
项目:Clipcon-AndroidClient    文件:NotificationService.java   
@Override
public void handleMessage(android.os.Message msg) {
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    intent = new Intent(getApplicationContext(), GroupActivity.class);
    intent.putExtra("History", "test");
    intent.setAction("NOW");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);

    pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    builder = new Notification.Builder(getApplicationContext());
    builder.setSmallIcon(R.drawable.icon_logo);
    builder.setTicker("new Clipcon"); //** 이 부분은 확인 필요
    builder.setWhen(System.currentTimeMillis());
    builder.setContentTitle("Clipcon Alert"); //** 큰 텍스트로 표시
    builder.setContentText("History data is updated"); //** 작은 텍스트로 표시
    builder.setAutoCancel(true);
    builder.setPriority(Notification.PRIORITY_MAX); //** MAX 나 HIGH로 줘야 가능함
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.FLAG_ONLY_ALERT_ONCE);
    builder.setContentIntent(pendingIntent);

    notificationManager.notify(id, builder.build());
}
项目:phonk    文件:SchedulerManager.java   
public void addAlarm(Date date, int id, String data, int interval, boolean repeating, boolean wakeUpScreen) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' h:mm a");

    // intent
    Intent intent = new Intent(c, AlarmReceiver.class);
    intent.putExtra(ALARM_INTENT, data);
    intent.putExtra(Project.SETTINGS_SCREEN_WAKEUP, wakeUpScreen);
    intent.putExtra(Project.NAME, mProject.getName());
    intent.putExtra(Project.FOLDER, mProject.getFolder());
    PendingIntent sender = PendingIntent.getBroadcast(c, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set Alarm
    if (repeating) mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), interval, sender);
    else mAlarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);

    // add to a global alarm thingie
    addTask(new Task(id, mProject, Task.TYPE_ALARM ,cal, interval, repeating, wakeUpScreen));
}
项目:BizareChat    文件:NotificationUtils.java   
public void showNotificationMessage(String title, String message,
                                    String timeStamp, Intent intent) {
    if (TextUtils.isEmpty(message)) {
        return;
    }

    if (!CurrentUser.getInstance().isNotificationsOn()) {
        return;
    }

    int icon = R.mipmap.ic_launcher;
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    context,
                    0,
                    intent,
                    PendingIntent.FLAG_CANCEL_CURRENT
            );
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context);
    showSmallNotification(notifBuilder, icon, title, message, timeStamp, resultPendingIntent);
}
项目:MuslimMateAndroid    文件:Alarms.java   
/**
 * Function to set alarm notification every day
 *
 * @param context Application context
 * @param hour    Hour of alarm
 * @param min     Min of alarm
 * @param id      ID of alarm
 */
public static void setAlarmForAzkar(Context context, int hour, int min, int id , String type) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, min);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Bundle details = new Bundle();
    details.putString("Azkar", type);
    Intent alarmReceiver = new Intent(context, AzkarAlarm.class);
    alarmReceiver.putExtras(details);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, alarmReceiver, PendingIntent.FLAG_UPDATE_CURRENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // kitkat...
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
    } else {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(), 1000 * 60 * 60 * 24, pendingIntent);
    }
}
项目:immersify    文件:ToggleNotification.java   
public static void show(Context context) {
    // Build toggle action
    Intent notificationServiceIntent = new Intent(context, NotificationService.class);
    notificationServiceIntent.setAction(ACTION_TOGGLE);
    PendingIntent notificationPendingIntent = PendingIntent.getService(context, 0, notificationServiceIntent, 0);
    NotificationCompat.Action toggleAction = new NotificationCompat.Action(
            R.drawable.ic_border_clear_black_24dp,
            "Toggle",
            notificationPendingIntent
    );

    // Build notification
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_zoom_out_map_black_24dp)
                    .setContentTitle("Immersify")
                    .setContentText("Tap to toggle immersive mode")
                    .setContentIntent(notificationPendingIntent)
                    .setPriority(NotificationCompat.PRIORITY_MIN)
                    .setCategory(NotificationCompat.CATEGORY_SERVICE)
                    .addAction(toggleAction)
                    .setOngoing(true);

    // Clear existing notifications
    ToggleNotification.cancel(context);

    // Notify the notification manager to create the notification
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
项目:remotedroid    文件:SMSUtils.java   
public void sendSMS(String address, String content) {
    lastSentSMSStatus = -1;
    SmsManager smsManager = SmsManager.getDefault();

    PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0,
            new Intent("SMS_SENT"), 0);

    mContext.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            lastSentSMSStatus = getResultCode();
            Toast.makeText(mContext,"message sent", Toast.LENGTH_LONG).show();
        }
    }, new IntentFilter("SMS_SENT"));

    smsManager.sendTextMessage("tel:".concat(address), null, content, sentPI, null);
}
项目: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, 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);
    }
项目:XERUNG    文件:MyFirebaseMessagingService.java   
private void sendMultilineNotification(String title, String messageBody) {
    //Log.e("DADA", "ADAD---"+title+"---message---"+messageBody);
    int notificationId = 0;
    Intent intent = new Intent(this, MainDashboard.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_custom_notification)
            .setLargeIcon(largeIcon)
            .setContentTitle(title/*"Firebase Push Notification"*/)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(messageBody))
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notificationBuilder.build());
}
项目:AutoScrollr    文件:CustomTabs.java   
/**
 * Method used to set the Action Button
 * @param icon The icon you've to show
 * @param description The description of the action
 * @param pendingIntent The pending intent it executes
 * @param tint True if you want to tint the icon, false if not.
 */
public Style setActionButton(@DrawableRes int icon, String description, PendingIntent
        pendingIntent,
                             boolean tint) {
    this.actionButton = new ActionButton
            (BitmapFactory.decodeResource(context.getResources(), icon),
                    description,
                    pendingIntent,
                    tint);
    return this;
}
项目:AutoVolume    文件:MainActivity.java   
private void notification() {

        notification = new NotificationCompat.Builder(this);
       notification.setSmallIcon(R.drawable.sound);
        notification.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
                R.drawable.sound));
        notification.setTicker("Auto Volume");
        notification.setOngoing(true);
        notification.setContentTitle("Go to Auto Volume");
        notification.setWhen(System.currentTimeMillis());

        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setContentIntent(pendingIntent);

        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(uniqueID, notification.build());

    }
项目:container    文件:GetIntentSender.java   
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    String creator = (String) args[1];
    args[1] = getHostPkg();
    String[] resolvedTypes = (String[]) args[6];
    int type = (int) args[0];
    if (args[5] instanceof Intent[]) {
        Intent[] intents = (Intent[]) args[5];
        if (intents.length > 0) {
            Intent intent = intents[intents.length - 1];
            if (resolvedTypes != null && resolvedTypes.length > 0) {
                intent.setDataAndType(intent.getData(), resolvedTypes[resolvedTypes.length - 1]);
            }
            Intent proxyIntent = redirectIntentSender(type, creator, intent);
            if (proxyIntent != null) {
                intents[intents.length - 1] = proxyIntent;
            }
        }
    }
    if (args.length > 7 && args[7] instanceof Integer) {
        args[7] = PendingIntent.FLAG_UPDATE_CURRENT;
    }
    IInterface sender = (IInterface) method.invoke(who, args);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && sender != null && creator != null) {
        VActivityManager.get().addPendingIntent(sender.asBinder(), creator);
    }
    return sender;
}
项目:ulogger-android    文件:LoggerService.java   
/**
 * Show notification
 *
 * @param mId Notification Id
 */
private void showNotification(int mId) {
    if (Logger.DEBUG) { Log.d(TAG, "[showNotification " + mId + "]"); }

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_stat_notify_24dp)
                    .setContentTitle(getString(R.string.app_name))
                    .setContentText(String.format(getString(R.string.is_running), getString(R.string.app_name)));
    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager.notify(mId, mBuilder.build());
}
项目:XERUNG    文件:MyFirebaseMessagingService.java   
private void sendMultilineNotification(String title, String messageBody) {
    //Log.e("DADA", "ADAD---"+title+"---message---"+messageBody);
    int notificationId = 0;
    Intent intent = new Intent(this, MainDashboard.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_custom_notification)
            .setLargeIcon(largeIcon)
            .setContentTitle(title/*"Firebase Push Notification"*/)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(messageBody))
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notificationBuilder.build());
}
项目:Android-Scrapper    文件:DashPagerPresenterImpl.java   
@Override
public void onChildAdded(final Game game) {
    if (DatabaseContract.checkGameValidity(game, mMapper.getPosition())) {
        if (mDashAdapter != null)
            mDashAdapter.addGame(game);
        // Start score scraper
        if (new DateTime(game.getGameDateTime(), DateTimeZone.getDefault()).plusMinutes(game.getLeagueType().getAvgTime()).isBeforeNow() && // If Game has already started
                game.getGameStatus() == GameStatus.NEUTRAL
                && !(game.getFirstTeam().getAcronym().equals(DefaultFactory.Team.ACRONYM) || game.getSecondTeam().getAcronym().equals(DefaultFactory.Team.ACRONYM)) // if teams are initialized
                ) {
            Intent gameIntent = new Intent(mView.getActivity(), GameUpdateReceiver.class);
            Log.i(TAG, "onChildAdded: Should Have completed game " + game.getId());
            gameIntent.putExtra("game", game.getId());
            PendingIntent pendingIntent = PendingIntent.getBroadcast(mView.getActivity(), (int) game.getId(), gameIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            long interval = game.getLeagueType().getRefreshInterval() * 60 * 1000L;
            AlarmManager manager = (AlarmManager) mView.getActivity().getSystemService(Context.ALARM_SERVICE);
            manager.setRepeating(AlarmManager.RTC_WAKEUP, new DateTime().getMillis(), interval, pendingIntent);
        }
    }
}
项目:Minitask    文件:MyDateTimeUtils.java   
public void ScheduleNotification(Notification notification,
                                 Context context, int notificationID, String dateTime) {
    Intent notificationIntent = new Intent(context, NotificationPublisher.class);
    notificationIntent.putExtra(NOTIFICATION_ID, notificationID);
    notificationIntent.putExtra(NOTIFICATION, notification);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    // parse string parameter to milliseconds for later alarm set
    Date futureInMillis = null;
    try {
        futureInMillis = dateTimeFormatter.parse(dateTime);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, futureInMillis.getTime(), pendingIntent);
}
项目:NovaMusicPlayer    文件:NovaNotificationManager.java   
public NovaNotificationManager(MusicService service) throws RemoteException {
    mService = service;
    updateSessionToken();

    mNotificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);

    createNotificationChannelForAndroidO();

    String pkgName = mService.getPackageName();


    mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
            new Intent(ACTION_PLAY).setPackage(pkgName), PendingIntent.FLAG_CANCEL_CURRENT);
    mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
            new Intent(ACTION_PAUSE).setPackage(pkgName), PendingIntent.FLAG_CANCEL_CURRENT);
    mPrevIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
            new Intent(ACTION_PREV).setPackage(pkgName), PendingIntent.FLAG_CANCEL_CURRENT);
    mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
            new Intent(ACTION_NEXT).setPackage(pkgName), PendingIntent.FLAG_CANCEL_CURRENT);

    if (mNotificationManager != null) {
        mNotificationManager.cancelAll();
    }
}
项目:Brevent    文件:BreventIntentService.java   
private static void showNoBrevent(Context context, boolean exit) {
    UILog.i("no brevent, exit: " + exit);
    Notification.Builder builder = buildNotification(context);
    builder.setAutoCancel(true);
    builder.setVisibility(Notification.VISIBILITY_PUBLIC);
    builder.setSmallIcon(BuildConfig.IC_STAT);
    int title = exit ? R.string.brevent_status_stopped : R.string.brevent_status_unknown;
    builder.setContentTitle(context.getString(title));
    File file = AppsActivityHandler.fetchLogs(context);
    if (BuildConfig.RELEASE && file != null) {
        builder.setContentText(context.getString(R.string.brevent_status_report));
        Intent intent = new Intent(context, BreventActivity.class);
        intent.setAction(BreventIntent.ACTION_FEEDBACK);
        intent.putExtra(BreventIntent.EXTRA_PATH, file.getPath());
        builder.setContentIntent(PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT));
    }
    Notification notification = builder.build();
    getNotificationManager(context).notify(ID2, notification);
    if (exit) {
        BreventActivity.cancelAlarm(context);
    }
}
项目:GitHub    文件:UtilsDisplay.java   
static void showUpdateNotAvailableNotification(Context context, String title, String content, int smallIconResourceId) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentIntent(contentIntent)
            .setContentTitle(title)
            .setContentText(content)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setSmallIcon(smallIconResourceId)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setOnlyAlertOnce(true)
            .setAutoCancel(true);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
项目:orgzly-android    文件:ListWidgetProvider.java   
private static void scheduleUpdate(Context context) {
    /*
     schedule updates via AlarmManager, because we don't want to wake the device on every update
     see https://developer.android.com/guide/topics/appwidgets/index.html#MetaData
     */
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    PendingIntent intent = getAlarmIntent(context);
    alarmManager.cancel(intent);

    /* repeat after every full hour because results of search can change on new day
        because of timezones repeat every hour instead of every day */
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 1);
    alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, intent);
}
项目:chromium-for-android-56-debug-video    文件:IntentHandler.java   
/**
 * @param intent An Intent to be checked.
 * @param context A context.
 * @return Whether an intent originates from Chrome or a first-party app.
 */
public static boolean isIntentChromeOrFirstParty(Intent intent, Context context) {
    if (intent == null) return false;

    PendingIntent token = fetchAuthenticationTokenFromIntent(intent);
    if (token == null) return false;

    // Do not ignore a valid URL Intent if the sender is Chrome. (If the PendingIntents are
    // equal, we know that the sender was us.)
    if (isChromeToken(token, context)) {
        return true;
    }
    if (ExternalAuthUtils.getInstance().isGoogleSigned(
                context, ApiCompatibilityUtils.getCreatorPackage(token))) {
        return true;
    }
    return false;
}
项目:Automata    文件:FCM.java   
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, Main.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 =
            new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Automata")
                    .setContentText(messageBody)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
项目:CustomAndroidOneSheeld    文件:PushMessagesReceiver.java   
static protected void showNotificationWithUrl(Context context, String title, String notificationText, String url) {
    // TODO Auto-generated method stub
    NotificationCompat.Builder build = new NotificationCompat.Builder(
            context);
    build.setSmallIcon(OneSheeldApplication.getNotificationIcon());
    build.setContentTitle(title);
    build.setContentText(notificationText);
    build.setTicker(notificationText);
    build.setWhen(System.currentTimeMillis());
    Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent intent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
    build.setContentIntent(intent);
    Notification notification = build.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_ALL;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(2, notification);
}
项目:q-mail    文件:MessageListWidgetProvider.java   
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.message_list_widget_layout);

    views.setTextViewText(R.id.folder, context.getString(R.string.integrated_inbox_title));

    Intent intent = new Intent(context, MessageListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    views.setRemoteAdapter(R.id.listView, intent);

    PendingIntent viewAction = viewActionTemplatePendingIntent(context);
    views.setPendingIntentTemplate(R.id.listView, viewAction);

    PendingIntent composeAction = composeActionPendingIntent(context);
    views.setOnClickPendingIntent(R.id.new_message, composeAction);

    appWidgetManager.updateAppWidget(appWidgetId, views);
}
项目:JavaIsFun    文件:Notification_receiver.java   
@Override
    public void onReceive(Context context, Intent intent) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService
                (context.NOTIFICATION_SERVICE);

        Intent repeating_intent = new Intent(context, MainActivity.class);
        repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, repeating_intent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setSmallIcon(R.drawable.microchip);
            builder.setVisibility(Notification.VISIBILITY_PUBLIC);
            builder.setPriority(1);
            builder.setVibrate(new long[]{1000, 1000});
            builder.setContentIntent(pendingIntent);
            builder.setSmallIcon(R.mipmap.ic_launcher);
            builder.setContentTitle("Não esqueça de praticar!");
            builder.setContentText("Que tal dar uma praticada no bom e velho Java?");
//          builder.setAutoCancel(true);
            notificationManager.notify(100, builder.build());

        } else {
            builder.setSmallIcon(R.drawable.microchip);
            builder.setVisibility(Notification.VISIBILITY_PUBLIC);
            builder.setPriority(1);
            builder.setVibrate(new long[]{1000, 1000});
            builder.setContentIntent(pendingIntent);
            builder.setSmallIcon(R.mipmap.ic_launcher);
            builder.setContentTitle("Não esqueça de praticar!");
            builder.setContentText("Que tal dar uma praticada no bom e velho Java?");
//          builder.setAutoCancel(true);
            notificationManager.notify(100, builder.build());

        }


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


    }
项目:Saiy-PS    文件:NotificationHelper.java   
/**
 * Show a computing notification.
 *
 * @param ctx the application context
 */
public static void createComputingNotification(@NonNull final Context ctx) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "createComputingNotification");
    }

    try {

        final Intent actionIntent = new Intent(NotificationService.INTENT_CLICK);
        actionIntent.setPackage(ctx.getPackageName());
        actionIntent.putExtra(NotificationService.CLICK_ACTION, NotificationService.NOTIFICATION_COMPUTING);

        final PendingIntent pendingIntent = PendingIntent.getService(ctx, NotificationService.NOTIFICATION_COMPUTING,
                actionIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, NOTIFICATION_CHANNEL_INTERACTION);

        builder.setContentIntent(pendingIntent).setSmallIcon(android.R.drawable.ic_popup_sync)
                .setTicker(ctx.getString(ai.saiy.android.R.string.notification_computing)).setWhen(System.currentTimeMillis())
                .setContentTitle(ctx.getString(ai.saiy.android.R.string.app_name))
                .setContentText(ctx.getString(ai.saiy.android.R.string.notification_computing) + "... "
                        + ctx.getString(ai.saiy.android.R.string.notification_tap_cancel))
                .setAutoCancel(true);


        final Notification not = builder.build();
        final NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(NotificationService.NOTIFICATION_COMPUTING, not);

    } catch (final Exception e) {
        if (DEBUG) {
            MyLog.e(CLS_NAME, "createComputingNotification failure");
            e.printStackTrace();
        }
    }
}
项目:Android-Programming-BigNerd    文件:PollService.java   
@Override
protected void onHandleIntent(@Nullable Intent intent) {
    if (!isNetworkAvailableAndConnected()) {
        return;
    }

    String query = QueryPreferences.getStoredQuery(this);
    String lastResultId = QueryPreferences.getLastResultId(this);
    List<GalleryItem> items;

    if (query == null) {
        items = new FlickrFetchr().fetchRecentPhotos();
    } else {
        items = new FlickrFetchr().searchPhotos(query);
    }

    if (items.size() == 0) {
        return;
    }

    String resultId = items.get(0).getId();
    if (resultId == null || !resultId.equals(lastResultId)) {
        Resources resources = getResources();
        Intent i = PhotoGalleryActivity.newIntent(this);
        PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);

        Notification notification = new NotificationCompat.Builder(this)
                .setTicker(resources.getString(R.string.new_pictures_title))
                .setSmallIcon(android.R.drawable.ic_menu_report_image)
                .setContentTitle(resources.getString(R.string.new_pictures_title))
                .setContentText(resources.getString(R.string.new_pictures_text))
                .setContentIntent(pi)
                .setAutoCancel(true)
                .build();
        QueryPreferences.setLastResultId(this, resultId);

        showBackgroundNotification(0, notification);
    }

}
项目:puremadrid    文件:MyFirebaseMessagingService.java   
private void sendNotification(int id, String title, String message, int color) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra(MainActivity.KEY_OPENED_FROM_NOTIFICATION, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"")
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(title)
            .setContentText(message)
            .setContentIntent(pendingIntent)
            .setColor(color)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(message))
            .setAutoCancel(true)
            ;

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notificationBuilder.setSound(defaultSoundUri);

    notificationBuilder.setVibrate(new long[]{1000, 1000});

    notificationBuilder.setLights(color, 1000, 1000);


    Notification notification = notificationBuilder.build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(id, notification);
}
项目:publicProject    文件:DownLoadService.java   
private Notification getNotifaction(String title, int progress) {
    Intent intent = new Intent(this, DownLoadActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Notification.Builder builder = new Notification.Builder(this);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setContentTitle(title);
    builder.setAutoCancel(true);
    builder.setContentIntent(pendingIntent);
    if (progress > 0) {
        builder.setProgress(100, progress, false);
        builder.setContentText(progress + "%");
    }
    return builder.build();
}
项目:FiveMinsMore    文件:MapsActivity.java   
public void removeLocationUpdates() {
    // Set intent for Tracking
    Intent mServiceIntent = new Intent(this, TrackingService.class);
    PendingIntent mPendingIntent = PendingIntent.getService(
            this, 0, mServiceIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // End tracking
    LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mPendingIntent);
    unbindService(this);
    stopService(mServiceIntent);
}
项目:chromium-for-android-56-debug-video    文件:OmahaClient.java   
/**
 * Sets a repeating alarm that fires request registration Intents.
 * Setting the alarm overwrites whatever alarm is already there, and rebooting
 * clears whatever alarms are currently set.
 */
private void scheduleRepeatingAlarm() {
    Intent registerIntent = createRegisterRequestIntent(this);
    PendingIntent pIntent = PendingIntent.getService(this, 0, registerIntent, 0);
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    setAlarm(am, pIntent, AlarmManager.RTC, mTimestampForNewRequest);
}
项目:CSipSimple    文件:Compatibility.java   
/**
 * Wrapper to set alarm at exact time
 * @see AlarmManager#setExact(int, long, PendingIntent)
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void setExactAlarm(AlarmManager alarmManager, int alarmType, long firstTime,
        PendingIntent pendingIntent) {
    if(isCompatible(Build.VERSION_CODES.KITKAT)) {
        alarmManager.setExact(alarmType, firstTime, pendingIntent);
    }else {
        alarmManager.set(alarmType, firstTime, pendingIntent);
    }
}
项目:GitHub    文件:PhoneUtils.java   
/**
 * 发送短信
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.SEND_SMS"/>}</p>
 *
 * @param phoneNumber 接收号码
 * @param content     短信内容
 */
public static void sendSmsSilent(final String phoneNumber, final String content) {
    if (StringUtils.isEmpty(content)) return;
    PendingIntent sentIntent = PendingIntent.getBroadcast(Utils.getApp(), 0, new Intent(), 0);
    SmsManager smsManager = SmsManager.getDefault();
    if (content.length() >= 70) {
        List<String> ms = smsManager.divideMessage(content);
        for (String str : ms) {
            smsManager.sendTextMessage(phoneNumber, null, str, sentIntent, null);
        }
    } else {
        smsManager.sendTextMessage(phoneNumber, null, content, sentIntent, null);
    }
}
项目:FastAndroid    文件:BaseCallActivity.java   
public void showOnGoingNotification(String title, String content) {
    Intent intent = new Intent(getIntent().getAction());
    Bundle bundle = new Bundle();
    onSaveFloatBoxState(bundle);
    intent.putExtra("floatbox", bundle);
    intent.putExtra("callAction", RongCallAction.ACTION_RESUME_CALL.getName());
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1000, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationUtil.showNotification(this, title, content, pendingIntent, CALL_NOTIFICATION_ID, Notification.DEFAULT_LIGHTS);
}
项目:treasure    文件:AlarmUtil.java   
/**
 * 开启轮询服务
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void startAlarmService(Context context, int triggerAtMillis, Class<?> cls, String action) {
    Intent intent = new Intent(context, cls);
    intent.setAction(action);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    startAlarmIntent(context, triggerAtMillis,pendingIntent);
}
项目:react-native-geo-fence    文件:RNGeoFenceModule.java   
/**
 * Gets a PendingIntent to send with the request to add or remove Geofences. Location Services
 * issues the Intent inside this PendingIntent whenever a geofence transition occurs for the
 * current list of geofences.
 *
 * @return A PendingIntent for the IntentService that handles geofence transitions.
 */
private PendingIntent getGeofencePendingIntent() {
    // Reuse the PendingIntent if we already have it.
    if (mGeofencePendingIntent != null) {
        return mGeofencePendingIntent;
    }
    Intent intent = new Intent(getReactApplicationContext(), GeofenceTransitionsIntentService.class);
    // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling
    // addGeofences() and removeGeofences().
    return PendingIntent.getService(getReactApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
项目:chromium-for-android-56-debug-video    文件:CustomTabIntentDataProvider.java   
/**
 * Triggers the client-defined action when the user clicks a custom menu item.
 * @param menuIndex The index that the menu item is shown in the result of
 *                  {@link #getMenuTitles()}
 */
public void clickMenuItemWithUrl(ChromeActivity activity, int menuIndex, String url) {
    Intent addedIntent = new Intent();
    addedIntent.setData(Uri.parse(url));
    try {
        // Media viewers pass in PendingIntents that contain CHOOSER Intents.  Setting the data
        // in these cases prevents the Intent from firing correctly.
        PendingIntent pendingIntent = mMenuEntries.get(menuIndex).second;
        pendingIntent.send(
                activity, 0, isMediaViewer() ? null : addedIntent, mOnFinished, null);
    } catch (CanceledException e) {
        Log.e(TAG, "Custom tab in Chrome failed to send pending intent.");
    }
}
项目:Orin    文件:PlayingNotificationImpl24.java   
private PendingIntent retrievePlaybackAction(final String action) {
    final ComponentName serviceName = new ComponentName(service, MusicService.class);
    Intent intent = new Intent(action);
    intent.setComponent(serviceName);

    return PendingIntent.getService(service, 0, intent, 0);
}
项目:Cable-Android    文件:MultipleRecipientNotificationBuilder.java   
public MultipleRecipientNotificationBuilder(Context context, NotificationPrivacyPreference privacy) {
  super(context, privacy);

  setColor(context.getResources().getColor(R.color.textsecure_primary));
  setSmallIcon(R.drawable.icon_notification);
  setContentTitle(context.getString(R.string.app_name));
  setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
  setCategory(NotificationCompat.CATEGORY_MESSAGE);
  setPriority(TextSecurePreferences.getNotificationPriority(context));
  setGroupSummary(true);
}
项目:q-mail    文件:MessageCompose.java   
public void launchUserInteractionPendingIntent(PendingIntent pendingIntent, int requestCode) {
    requestCode |= REQUEST_MASK_RECIPIENT_PRESENTER;
    try {
        startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0);
    } catch (SendIntentException e) {
        e.printStackTrace();
    }
}