android.support.v4.app.TaskStackBuilder#addParentStack ( )源码实例Demo

下面列出了android.support.v4.app.TaskStackBuilder#addParentStack ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private PendingIntent getBrowserPendingIntent(int type) {
    Intent browserIntent = PrefManager.getWebViewIntent(context);
    browserIntent.setAction(WebReviewActivity.OPEN_ACTION);

    switch (type) {
        case BROWSER_TYPE_LESSONS:
            browserIntent.setData(Uri.parse(Browser.LESSON_URL));
            break;
        case BROWSER_TYPE_REVIEWS:
            browserIntent.setData(Uri.parse(Browser.REVIEW_URL));
            break;
    }

    TaskStackBuilder browserStackBuilder = TaskStackBuilder.create(context);
    browserStackBuilder.addParentStack(
            PrefManager.getHWAccel() ? WebReviewActivity.class : SWWebReviewActivity.class);
    browserStackBuilder.addNextIntent(browserIntent);

    return browserStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
public static void showNotification(Context context,Class<?> cls,String title,String content)
{
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Intent notificationIntent = new Intent(context, cls);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(cls);
    stackBuilder.addNextIntent(notificationIntent);

    PendingIntent pendingIntent = stackBuilder.getPendingIntent(DAILY_REMINDER_REQUEST_CODE, PendingIntent.FLAG_UPDATE_CURRENT);

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

    Notification notification = builder.setContentTitle(title)
            .setContentText(content)
            .setAutoCancel(true)
            .setSound(alarmSound)
            .setSmallIcon(R.drawable.app_icon_144)
            .setContentIntent(pendingIntent).build();

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(DAILY_REMINDER_REQUEST_CODE, notification);

}
 
/**
 * Displays a notification with the location results.
 */
void showNotification() {
    Intent notificationIntent = new Intent(mContext, MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification.Builder notificationBuilder = new Notification.Builder(mContext)
            .setContentTitle(getLocationResultTitle())
            .setContentText(getLocationResultText())
            .setSmallIcon(R.mipmap.ic_launcher)
            .setAutoCancel(true)
            .setContentIntent(notificationPendingIntent);

    getNotificationManager().notify(0, notificationBuilder.build());
}
 
源代码4 项目: ello-android   文件: ElloGcmListenerService.java
private void sendNotification(String title, String body, String webUrl) {
    NotificationCompat.Builder builder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_stat_gcm)
                    .setContentTitle(title)
                    .setContentText(body);

    Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
    resultIntent.putExtra("web_url", webUrl);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_CANCEL_CURRENT
            );
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(NOTIFICATION_ID, builder.build());
}
 
源代码5 项目: NoiseCapture   文件: MainActivity.java
protected void displayCommunityMapNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(MeasurementService.getNotificationIcon())
            .setContentTitle(getString(R.string.notification_goto_community_map_title))
            .setContentText(getString(R.string.notification_goto_community_map))
            .setAutoCancel(true);
    NotificationCompat.BigTextStyle bigTextStyle =
            new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(getString(R.string.notification_goto_community_map_title));
    bigTextStyle.bigText(getString(R.string.notification_goto_community_map));
    builder.setStyle(bigTextStyle);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://noise-planet.org/map_noisecapture"));
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(this);
    stackBuilder.addNextIntent(intent);
    builder.setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
    NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    mNM.notify(NOTIFICATION_MAP, builder.build());
}
 
源代码6 项目: Cracker   文件: Receiver.java
private void showNotification() {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setSmallIcon(R.drawable.ic_notification_bug);
    builder.setLargeIcon(getBitmap(CrashUnit.getAppIcon(context, packageName)));
    builder.setContentTitle(CrashUnit.getAppName(context, packageName));
    builder.setContentText(throwable.toString());
    builder.setAutoCancel(true);

    Intent intent = new Intent(context, DetailActivity.class);
    intent.putExtra(context.getString(R.string.detain_intent_content), getContent(throwable));
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(DetailActivity.class);
    taskStackBuilder.addNextIntent(intent);
    builder.setContentIntent(taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT));

    manager.notify(CrashUnit.NOTIFICATION_ID, builder.build());
}
 
private PendingIntent getDashboardPendingIntent() {
    Intent intent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
源代码8 项目: Sherlock   文件: CrashReporter.java
private Notification notification(CrashViewModel crashViewModel) {
  Intent crashActivityIntent = new Intent(context, CrashActivity.class);
  crashActivityIntent.putExtra(CrashActivity.CRASH_ID, crashViewModel.getIdentifier());

  TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
  stackBuilder.addParentStack(CrashActivity.class);
  stackBuilder.addNextIntent(crashActivityIntent);

  PendingIntent pendingIntent = stackBuilder.getPendingIntent(221, FLAG_UPDATE_CURRENT);

  Notification.Builder notificationBuilder = new Notification.Builder(context)
      .setContentTitle(crashViewModel.getPlace())
      .setContentText(crashViewModel.getDate())
      .setSmallIcon(R.mipmap.ic_stat_sherlock_logo)
      .setContentIntent(pendingIntent)
      .setAutoCancel(true);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notificationBuilder.setColor(ContextCompat.getColor(context, R.color.sherlock_colorAccent));
  }

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    notificationBuilder.setChannelId(CHANNEL_ID);
  }

  return notificationBuilder.build();
}
 
源代码9 项目: Android-Remote   文件: DownloadManager.java
private PendingIntent buildNotificationIntent() {
    Intent intent = new Intent(mContext, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(ClementineMediaSessionNotification.EXTRA_NOTIFICATION_ID,
            NOTIFICATION_ID_DOWNLOADS);

    // Create a TaskStack, so the app navigates correctly backwards
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
/**
 * Displays a notification with the location results.
 */
void showNotification() {
    Intent notificationIntent = new Intent(mContext, MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification.Builder notificationBuilder = new Notification.Builder(mContext,
            PRIMARY_CHANNEL)
            .setContentTitle(getLocationResultTitle())
            .setContentText(getLocationResultText())
            .setSmallIcon(R.mipmap.ic_launcher)
            .setAutoCancel(true)
            .setContentIntent(notificationPendingIntent);

    getNotificationManager().notify(0, notificationBuilder.build());
}
 
public void showNotification() {

    Bitmap bitlogo= BitmapFactory.decodeResource(context.getResources(),
  			    R.drawable.streaming_notification_default_icon);
    //Bitmap bitplay= BitmapFactory.decodeResource(context.getResources(),R.drawable.streaming_notification_default_play);
    //Bitmap bitstop= BitmapFactory.decodeResource(context.getResources(),R.drawable.streaming_notification_default_stop);
		remoteViews =new RemoteViews(context.getPackageName(),
	            R.layout.streaming_notification_player);
		notifyBuilder = new NotificationCompat.Builder(this.context)
				.setSmallIcon(R.drawable.streaming_notification_default_icon)
				.setContentText("")
        .setOngoing(true)
				.setContent(remoteViews);

		Intent resultIntent = new Intent(this.context, this.clsActivity);
		resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.context);
		stackBuilder.addParentStack(this.clsActivity);
		stackBuilder.addNextIntent(resultIntent);

		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
				PendingIntent.FLAG_UPDATE_CURRENT);

		notifyBuilder.setContentIntent(resultPendingIntent);
		//to use custom notification
		remoteViews.setOnClickPendingIntent(R.id.btn_streaming_notification_play, makePendingIntent(BROADCAST_PLAYBACK_PLAY));
		remoteViews.setOnClickPendingIntent(R.id.btn_streaming_notification_stop, makePendingIntent(BROADCAST_EXIT));
		//remoteViews.setTextViewText(R.id.textView1, information.RadioName);
		remoteViews.setImageViewBitmap(R.id.streaming_icon, bitlogo);
    //remoteViews.setImageViewBitmap(R.id.btn_streaming_notification_play, bitplay);
    //remoteViews.setImageViewBitmap(R.id.btn_streaming_notification_stop, bitstop);
		notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		notifyManager.notify(NOTIFY_ME_ID, notifyBuilder.build());
  }
 
源代码12 项目: 600SeriesAndroidUploader   文件: MasterService.java
private void showDisconnectionNotification(String title, String message) {

        String channel = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? "error" : "";

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this, channel)
                        .setPriority(PRIORITY_MAX)
                        .setSmallIcon(android.R.drawable.stat_notify_error)
                        .setContentTitle(title)
                        .setContentText(message)
                        .setTicker(message)
                        .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(this, MainActivity.class);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(MainActivity.class);

        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );

        mBuilder.setContentIntent(resultPendingIntent);

        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(USB_DISCONNECT_NOFICATION_ID, mBuilder.build());
    }
 
源代码13 项目: Saude-no-Mapa   文件: GroupsService.java
private void showNotification(Grupo grupo) {
    Intent intent = new Intent(this, ChatActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);

    intent.putExtra(GROUP_KEY, grupo);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    int notId = new Random().nextInt();

    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
            stackBuilder.getPendingIntent(notId, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.app_icon)
            .setContentTitle(getString(R.string.app_name))
            .setContentText("Você possui mensagens não lidas no grupo: " + grupo.getDescricao())
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notId, notificationBuilder.build());
}
 
源代码14 项目: Tweetin   文件: PostTask.java
private PendingIntent getPendingIntent() {
    Intent intent = postActivity.getIntent();
    intent.putExtra(postActivity.getString(R.string.post_intent_post_flag), FlagUnit.POST_RESEND);
    intent.putExtra(postActivity.getString(R.string.post_intent_text), text);
    intent.putExtra(postActivity.getString(R.string.post_intent_check_in), checkIn);
    intent.putExtra(postActivity.getString(R.string.post_intent_picture_path), picturePath);

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(postActivity);
    taskStackBuilder.addParentStack(PostActivity.class);
    taskStackBuilder.addNextIntent(intent);

    return taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
}
 
源代码15 项目: WiFiAfterConnect   文件: WifiAuthenticator.java
protected void notifyWifiDisabled() {
	NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext())
	.setSmallIcon (R.drawable.wifiac_small)//(android.R.drawable.presence_offline)
	.setContentTitle(getResourceString(R.string.notif_wifi_disabled_title))
	.setContentText(authHost + " - " + getResourceString(R.string.notif_wifi_disabled_text));
	
	Intent resultIntent = makeIntent(MainActivity.class);
	if (prefs.getReenableWifiQuiet())
		resultIntent.setAction(getResourceString(R.string.action_reenable_wifi));
	// The stack builder object will contain an artificial back stack for the
	// started Activity.
	// This ensures that navigating backward from the Activity leads out of
	// your application to the Home screen.
	TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());
	// Adds the back stack for the Intent (but not the Intent itself)
	stackBuilder.addParentStack(MainActivity.class);
	// Adds the Intent that starts the Activity to the top of the stack
	stackBuilder.addNextIntent(resultIntent);
	PendingIntent resultPendingIntent =
	        stackBuilder.getPendingIntent(
	            0,
	            PendingIntent.FLAG_UPDATE_CURRENT
	        );
	builder.setContentIntent(resultPendingIntent);
	
	Notification n = builder.build();
	debug("posting notification that wifi was disabled (" + n.toString() + ")");

	NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	nm.notify(0, n);
}
 
源代码16 项目: satstat   文件: PasvLocListenerService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType);
	prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots);
	prefCoord = Integer.valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord)));
	mNotifyFix = mSharedPreferences.getBoolean(Const.KEY_PREF_NOTIFY_FIX, mNotifyFix);
	mNotifySearch = mSharedPreferences.getBoolean(Const.KEY_PREF_NOTIFY_SEARCH, mNotifySearch);

	if (mLocationManager.getAllProviders().indexOf(LocationManager.PASSIVE_PROVIDER) >= 0) {
		if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
			requestLocationUpdates();
		else
			Log.w("PasvLocListenerService", "ACCESS_FINE_LOCATION permission not granted. Data display will not be available.");
	} else {
		Log.w("PasvLocListenerService", "No passive location provider found. Data display will not be available.");
	}

       mBuilder = new NotificationCompat.Builder(this)
	.setSmallIcon(R.drawable.ic_stat_notify_location)
	.setContentTitle(getString(R.string.value_none))
	.setContentText(getString(R.string.value_none))
	.setWhen(0)
	.setVisibility(Notification.VISIBILITY_PUBLIC);

	Intent mainIntent = new Intent(this, MainActivity.class);

	TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
	stackBuilder.addParentStack(MainActivity.class);
	stackBuilder.addNextIntent(mainIntent);

	PendingIntent mainPendingIntent =
			stackBuilder.getPendingIntent(
					0,
					PendingIntent.FLAG_UPDATE_CURRENT
					);

	mBuilder.setContentIntent(mainPendingIntent);
	
	// if we were started through a broadcast, mGpsStatusReceiver had
	// no way of picking it up, so we need to forward it manually
	mGpsStatusReceiver.onReceive(this, intent);

	return START_STICKY;
}
 
源代码17 项目: talk-android   文件: NotificationUtil.java
public static void showNotification(Context context, String message, MiPushMessage miPushMessage) {
    if (BizLogic.isNotificationOn()) {
        if (!BizLogic.isApplicationShowing(MainApp.CONTEXT) || MainApp.IS_SCREEN_LOCK) {

            int numMessages = MainApp.PREF_UTIL.getInt(Constant.NOTIFICATION_COUNT, 0) + 1;
            MainApp.PREF_UTIL.putInt(Constant.NOTIFICATION_COUNT, numMessages);
            List<String> msgList = jsonToList(MainApp.PREF_UTIL.getString(Constant.NOTIFICATION_CONTENT,
                    ""), String.class);
            if (msgList == null) {
                msgList = new ArrayList<>();
            }
            msgList.add(0, message);
            MainApp.PREF_UTIL.putString(Constant.NOTIFICATION_CONTENT, listToJson(msgList));

            /* Creates an explicit intent for an Activity in your app */
            Intent resultIntent = new Intent(context, HomeActivity.class);
            resultIntent.putExtra(PushMessageHelper.KEY_MESSAGE, miPushMessage);
            resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
            resultIntent.addCategory(CATEGORY_NOTIFICATION);

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);

            /* Adds the Intent that starts the Activity to the top of the stack */
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(context.getString(R.string.app_name));
            inboxStyle.setSummaryText(context.getString(R.string.new_message));
            for (String mMsg : msgList) {
                inboxStyle.addLine(mMsg);
            }
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setContentTitle(context.getString(R.string.app_name)) //设置通知栏标题
                    .setStyle(inboxStyle)
                    .setContentText(context.getString(R.string.new_message))
                    .setAutoCancel(true)
                    .setContentIntent(resultPendingIntent) //设置通知栏点击意图
                    .setNumber(numMessages) //设置通知集合的数量
                    .setWhen(System.currentTimeMillis()) //通知产生的时间,会在通知信息里显示,一般是系统获取到的时间
                    .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS) //向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合
                    .setSound(Uri.parse("android.resource://com.teambition.talk/" + R.raw.add), AudioManager.STREAM_NOTIFICATION)
                    .setSmallIcon(R.drawable.ic_notification); //设置通知小ICON
            mNotificationManager.notify(Constant.NOTIFICATION_ID, mBuilder.build());
        }
    }
}
 
源代码18 项目: kernel_adiutor   文件: BootService.java
private void init() {
    final List<String> applys = new ArrayList<>();
    final List<String> plugins = new ArrayList<>();

    CPUVoltage.storeVoltageTable(this);

    if (Screen.isScreenAutoHBMActive(this) && Screen.hasScreenHBM()) {
        startService(new Intent(this, AutoHighBrightnessModeService.class));
    }

    Class[] classes = {BatteryFragment.class, CPUFragment.class, CPUHotplugFragment.class,
            CPUVoltageFragment.class, EntropyFragment.class, GPUFragment.class, IOFragment.class,
            KSMFragment.class, LMKFragment.class, MiscFragment.class,
            ScreenFragment.class, SoundFragment.class, ThermalFragment.class, WakeLockFragment.class,
            VMFragment.class, WakeFragment.class, CoreControl.class
    };

    for (Class mClass : classes)
        if (Utils.getBoolean(mClass.getSimpleName() + "onboot", false, this)) {
            log("Applying on boot for " + mClass.getSimpleName());
            applys.addAll(Utils.getApplys(mClass));
        }

    String plugs;
    if (!(plugs = Utils.getString("plugins", "", this)).isEmpty()) {
        String[] ps = plugs.split("wefewfewwgwe");
        for (String plug : ps)
            if (Utils.getBoolean(plug + "onboot", false, this)) plugins.add(plug);
    }

    if (applys.size() > 0 || plugins.size() > 0) {
        final int delay = Utils.getInt("applyonbootdelay", 5, this);
        mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setContentTitle(getString(R.string.apply_on_boot))
                .setContentText(getString(R.string.apply_on_boot_time, delay))
                .setSmallIcon(R.drawable.ic_launcher_preview);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
        PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(pendingIntent);

        new Thread(new Runnable() {
            @Override
            public void run() {
                boolean notification = Utils.getBoolean("applyonbootnotification", true, BootService.this);
                for (int i = delay; i >= 0; i--)
                    try {
                        Thread.sleep(1000);
                        String note = getString(R.string.apply_on_boot_time, i);
                        if (notification) {
                            mBuilder.setContentText(note).setProgress(delay, delay - i, false);
                            mNotifyManager.notify(id, mBuilder.build());
                        } else if ((i % 10 == 0 || i == delay) && i != 0) toast(note);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                if (notification) {
                    mBuilder.setContentText(getString(R.string.apply_on_boot_finished)).setProgress(0, 0, false);
                    mNotifyManager.notify(id, mBuilder.build());
                }
                apply(applys, plugins);
                stopSelf();
            }
        }).start();
    } else stopSelf();
}
 
源代码19 项目: FaceSlim   文件: NotificationsService.java
private void notifier(String title, String url, boolean isMessage, Bitmap picture) {
    // let's display a notification, dude!
    final String contentTitle;
    if (isMessage)
        contentTitle = getString(R.string.app_name) + ": " + getString(R.string.messages);
    else
        contentTitle = getString(R.string.app_name) + ": " + getString(R.string.notifications);

    // log line (show what type of notification is about to be displayed)
    Log.i(TAG, "Start notification - isMessage: " + isMessage);

    // start building a notification
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(title))
                    .setSmallIcon(R.mipmap.ic_stat_fs)
                    .setContentTitle(contentTitle)
                    .setContentText(title)
                    .setTicker(title)
                    .setWhen(System.currentTimeMillis())
                    .setAutoCancel(true);

    // picture is available
    if (picture != null)
        mBuilder.setLargeIcon(picture);

    // ringtone
    String ringtoneKey = "ringtone";
    if (isMessage)
        ringtoneKey = "ringtone_msg";

    Uri ringtoneUri = Uri.parse(preferences.getString(ringtoneKey, "content://settings/system/notification_sound"));
    mBuilder.setSound(ringtoneUri);

    // vibration
    if (preferences.getBoolean("vibrate", false))
        mBuilder.setVibrate(new long[] {500, 500});
    else
        mBuilder.setVibrate(new long[] {0L});

    // LED light
    if (preferences.getBoolean("led_light", false)) {
        Resources resources = getResources(), systemResources = Resources.getSystem();
        mBuilder.setLights(Color.CYAN,
                resources.getInteger(systemResources.getIdentifier("config_defaultNotificationLedOn", "integer", "android")),
                resources.getInteger(systemResources.getIdentifier("config_defaultNotificationLedOff", "integer", "android")));
    }

    // priority for Heads-up
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        mBuilder.setPriority(Notification.PRIORITY_HIGH);

    // intent with notification url in extra
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("start_url", url);
    intent.setAction("NOTIFICATION_URL_ACTION");

    // final notification building
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setOngoing(false);
    Notification note = mBuilder.build();

    // LED light flag
    if (preferences.getBoolean("led_light", false))
        note.flags |= Notification.FLAG_SHOW_LIGHTS;

    // display a notification
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // because message notifications are displayed separately
    if (isMessage)
        mNotificationManager.notify(1, note);
    else
        mNotificationManager.notify(0, note);
}
 
源代码20 项目: bitseal   文件: NotificationsService.java
/**
 * Displays an Android notification to the user, informing them that the app
 * needs to be unlocked (decrypting the database). 
 * 
 * Note: This method is adapted from the example here: <br>
 * https://developer.android.com/guide/topics/ui/notifiers/notifications.html
 */
private void displayUnlockNotification()
{
	NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
	builder.setContentTitle(UNLOCK_NOTIFICATION_TITLE);
	builder.setContentText(UNLOCK_NOTIFICATION_TEXT);
	builder.setAutoCancel(true);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
	{
		builder.setSmallIcon(R.drawable.notification_icon_lollipop);
		builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
	}
	else
	{
		builder.setSmallIcon(R.drawable.notification_icon);
	}
	
	// Creates an intent to open the lock screen activity if the user selects the notification
	Intent openNotificationIntent = new Intent(this, LockScreenActivity.class);
	openNotificationIntent.putExtra(NotificationsService.EXTRA_NEW_MESSAGES_NOTIFICATION_CLEARED, true);
	
	// Creates an intent to run the notifications service if the user clears the notification
	Intent clearNotificationIntent = new Intent(getApplicationContext(), NotificationsService.class);
	clearNotificationIntent.putExtra(NotificationsService.EXTRA_NEW_MESSAGES_NOTIFICATION_CLEARED, true);
	PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, clearNotificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
	builder.setDeleteIntent(pendingIntent);
	
	// The stack builder object will contain an artificial back stack for the
	// started Activity. This ensures that navigating backward from the Activity leads out of
	// your application to the Home screen.
	TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
	
	// Adds the back stack for the Intent (but not the Intent itself)
	stackBuilder.addParentStack(LockScreenActivity.class);
	
	// Adds the Intent that starts the Activity to the top of the stack
	stackBuilder.addNextIntent(openNotificationIntent);
	PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
	builder.setContentIntent(resultPendingIntent);
	NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	
	// The notification ID number allows you to update the notification later on.
	notificationManager.notify(UNLOCK_NOTIFICATION_ID, builder.build());
}