Java Code Examples for android.app.PendingIntent#getActivity()

The following examples show how to use android.app.PendingIntent#getActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OCRFloating.java    From loco-answers with GNU General Public License v3.0 6 votes vote down vote up
private void notification() {
    Intent i = new Intent(this, OCRFloating.class);
    i.setAction("stop");
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "stop");
    mBuilder.setContentText("Trivia Hack: Committed to speed and performance :)")
            .setContentTitle("Tap to remove overlay screen")
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setContentIntent(pi)
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setOngoing(true).setAutoCancel(true)
            .addAction(android.R.drawable.ic_menu_more, "Open Trivia Hack", pendingIntent);

    notificationManager.notify(1545, mBuilder.build());

}
 
Example 2
Source File: Core.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
static NotificationCompat.Builder getNotificationError(Context context, String channel, String title, Throwable ex) {
    // Build pending intent
    Intent intent = new Intent(context, ActivityView.class);
    intent.setAction("error");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(
            context, ActivityView.REQUEST_ERROR, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context, channel)
                    .setSmallIcon(R.drawable.baseline_warning_white_24)
                    .setContentTitle(context.getString(R.string.title_notification_failed, title))
                    .setContentText(Log.formatThrowable(ex, false))
                    .setContentIntent(pi)
                    .setAutoCancel(false)
                    .setShowWhen(true)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setOnlyAlertOnce(true)
                    .setCategory(NotificationCompat.CATEGORY_ERROR)
                    .setVisibility(NotificationCompat.VISIBILITY_SECRET)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(Log.formatThrowable(ex, "\n", false)));

    return builder;
}
 
Example 3
Source File: DispatchService.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected final void notify(int resID, int code, Intent notifyIntent) {
    Log.d(TAG, "notify(...) " + resID + ", " + notifyIntent.toUri(Intent.URI_INTENT_SCHEME));
    // Pending intent used to launch the notification intent
    PendingIntent actionIntent =
            PendingIntent.getActivity(
                    getBaseContext(),
                    0,
                    notifyIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    // Always force the locale before we send the notification
    Locales.updateLocale(getBaseContext(), getString(R.string.force_locale));
    mNotificationFactory
            .setContentIntent(actionIntent)
            .setContentText(resID, code)
            .doNotify();
}
 
Example 4
Source File: NotificationReceiver.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
private static void showMentionMoreNotification(final Context context,
        final int count) {
    if (AppContext.DEBUG) {
        Log.d(NotificationReceiver.TAG,
                "showMentionMoreNotification count=" + count);
    }
    final String title = "饭否消息";
    final String message = "收到" + count + "条提到你的消息";
    final Intent intent = new Intent(context, HomePage.class);
    intent.setAction("DUMY_ACTION " + System.currentTimeMillis());
    intent.putExtra(Constants.EXTRA_PAGE, 1);
    final PendingIntent contentIntent = PendingIntent.getActivity(context,
            0, intent, 0);
    NotificationReceiver.showNotification(
            NotificationReceiver.NOTIFICATION_ID_MENTION, context,
            contentIntent, title, message, R.drawable.ic_notify_mention);
}
 
Example 5
Source File: ServiceSinkhole.java    From NetGuard with GNU General Public License v3.0 6 votes vote down vote up
private void showErrorNotification(String message) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify");
    builder.setSmallIcon(R.drawable.ic_error_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_error, message))
            .setContentIntent(pi)
            .setColor(tv.data)
            .setOngoing(false)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        builder.setCategory(NotificationCompat.CATEGORY_STATUS)
                .setVisibility(NotificationCompat.VISIBILITY_SECRET);

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_error, message));
    notification.setSummaryText(message);

    NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build());
}
 
Example 6
Source File: PlayNotifyManager.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
private Notification buildNotification() {

        NotificationCompat.Builder builder = new NotificationCompat.Builder(activity);

        Intent intent = new Intent(activity, MainActivity.class);
        PendingIntent startMainActivity = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        builder.setContentIntent(startMainActivity)
                .setTicker(activity.getString(R.string.app_name_us))
                .setSmallIcon(R.drawable.logo_small_icon)
                .setWhen(System.currentTimeMillis())
                .setOngoing(true)
                .setCustomContentView(createContentView())
                .setCustomBigContentView(createContentBigView())
                .setPriority(Notification.PRIORITY_HIGH);

        return builder.build();
    }
 
Example 7
Source File: BsFirebaseMessagingService.java    From buddysearch with Apache License 2.0 6 votes vote down vote up
private void updateNotification(String senderId, String senderFullName, String message, boolean needSound) {
    if (DialogPresenter.getCurrentPeerId() != null) {
        return;
    }
    Intent intent = new Intent(this, DialogActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(DialogActivity.KEY_PEER_ID, senderId);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(senderFullName == null ? getString(com.buddysearch.android.library.R.string.loading) : senderFullName)
            .setContentText(message)
            .setSmallIcon(com.buddysearch.android.data.R.drawable.ic_notification_message)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);
    if (needSound) {
        notificationBuilder.setSound(defaultSoundUri);
    }

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(senderId.hashCode(), notificationBuilder.build());
}
 
Example 8
Source File: TaskListenerForNotifacation.java    From miappstore with Apache License 2.0 5 votes vote down vote up
public TaskListenerForNotifacation(Context context, DownloadManager manager) {
    this.context = context;
    this.downloadManager = manager;
    notifiManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificaions = new ConcurrentHashMap<Long, NotificationInfo>();
    contentIntent = new Intent(context, DownLoadActivity.class);
    pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_ONE_SHOT);

}
 
Example 9
Source File: MainActivity.java    From wearable with Apache License 2.0 5 votes vote down vote up
void bigTextNoti() {
	//create the intent to launch the notiactivity, then the pentingintent.
	Intent viewIntent = new Intent(this, NotiActivity.class);
	viewIntent.putExtra("NotiID", "Notification ID is " + notificationID);
	
	PendingIntent viewPendingIntent =
	        PendingIntent.getActivity(this, 0, viewIntent, 0);

	BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
	bigStyle.bigText("Big text style.\n"
			+ "We should have more room to add text for the user to read, instead of a short message.");

	
	//Now create the notification.  We must use the NotificationCompat or it will not work on the wearable.
	NotificationCompat.Builder notificationBuilder =
	        new NotificationCompat.Builder(this)
	        .setSmallIcon(R.drawable.ic_launcher)
	        .setContentTitle("Simple Noti")
	        .setContentText("This is a simple notification")
	        .setContentIntent(viewPendingIntent)
	        .setStyle(bigStyle);

	// Get an instance of the NotificationManager service
	NotificationManagerCompat notificationManager =
	        NotificationManagerCompat.from(this);

	// Build the notification and issues it with notification manager.
	notificationManager.notify(notificationID, notificationBuilder.build());
	notificationID++;
}
 
Example 10
Source File: PixivArtProvider.java    From PixivforMuzei3 with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private RemoteActionCompat shareImage(Artwork artwork) {
    if (!running) {
        return null;
    }
    final Context context = checkContext();
    File newFile = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),
            artwork.getToken() + ".png");
    Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", newFile);
    Intent sharingIntent = new Intent()
            .setAction(Intent.ACTION_SEND)
            .setType("image/*")
            .putExtra(Intent.EXTRA_STREAM, uri);

    String title = context.getString(R.string.command_shareImage);
    return new RemoteActionCompat(
            IconCompat.createWithResource(context, R.drawable.ic_baseline_share_24),
            title,
            title,
            PendingIntent.getActivity(
                    context,
                    (int) artwork.getId(),
                    IntentUtils.chooseIntent(sharingIntent, SHARE_IMAGE_INTENT_CHOOSER_TITLE, context),
                    PendingIntent.FLAG_UPDATE_CURRENT
            )
    );
}
 
Example 11
Source File: IRCService.java    From Atomic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle command
 *
 * @param intent
 */
private void handleCommand(Intent intent) {
  if( ACTION_FOREGROUND.equals(intent.getAction()) ) {
    if( foreground ) {
      return; // XXX: We are already in foreground...
    }
    foreground = true;


    Intent notifyIntent = new Intent(this, ServersActivity.class);
    notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);


    // Set the icon, scrolling text and timestamp
    // now using NotificationCompat for Linter happiness
    Notification notification = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_service_icon)
        .setWhen(System.currentTimeMillis())
        .setContentText(getText(R.string.notification_running))
        .setTicker(getText(R.string.notification_not_connected))
        .setContentTitle(getText(R.string.app_name))
        .setContentIntent(contentIntent)
        .setPriority(Notification.PRIORITY_MIN)
        .build();

    startForegroundCompat(FOREGROUND_NOTIFICATION, notification);
  } else if( ACTION_BACKGROUND.equals(intent.getAction()) && !foreground ) {
    stopForegroundCompat(FOREGROUND_NOTIFICATION);
  } else if( ACTION_ACK_NEW_MENTIONS.equals(intent.getAction()) ) {
    ackNewMentions(intent.getIntExtra(EXTRA_ACK_SERVERID, -1), intent.getStringExtra(EXTRA_ACK_CONVTITLE));
  }
}
 
Example 12
Source File: UpgradeService.java    From catnut with MIT License 5 votes vote down vote up
private void download(Intent intent) throws IOException {
	String link = intent.getExtras().getString(DOWNLOAD_LINK);
	URL url = new URL(link);
	HttpURLConnection connection = (HttpURLConnection) url.openConnection();
	File apk = new File(getExternalCacheDir().getPath() + "/"
			+ Uri.parse(link).getLastPathSegment());
	FileOutputStream outputStream = new FileOutputStream(apk);
	InputStream inputStream = new BufferedInputStream(connection.getInputStream());

	connection.connect();
	int length = connection.getContentLength();

	byte[] buffer = new byte[1024];
	int tmp;
	int count = 0;
	mBuilder.setContentTitle(getString(R.string.download_apk));
	mBuilder.setContentText(getString(R.string.downloading));
	while ((tmp = inputStream.read(buffer)) != -1) {
		count += tmp;
		outputStream.write(buffer, 0, tmp);
		mBuilder.setProgress(100, (int) ((count * 1.f / length) * 100), true);
		mNotificationManager.notify(ID, mBuilder.build());
	}
	inputStream.close();
	outputStream.close();
	connection.disconnect();

	Intent install = new Intent(Intent.ACTION_VIEW);
	install.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive");
	PendingIntent piInstall = PendingIntent.getActivity(this, 0, install, 0);
	mBuilder.setProgress(0, 0, false);
	mBuilder.setContentIntent(piInstall);

	mBuilder.setTicker(getString(R.string.done_download))
			.setContentTitle(getString(R.string.done_download))
			.setContentText(getString(R.string.click_to_upgrade));
	mNotificationManager.notify(ID, mBuilder.setDefaults(Notification.DEFAULT_ALL).build());
}
 
Example 13
Source File: PostMessageService.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
private int showFailedNotification(final String title, final String message) {
    final int id = 11;

    final Notification notification = new Notification(
            R.drawable.ic_notify_icon, title, System.currentTimeMillis());
    final PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(), 0);
    notification.setLatestEventInfo(this, title, message, contentIntent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    this.nm.notify(id, notification);
    return id;

}
 
Example 14
Source File: APWidget.java    From Android-Wifi-Hotspot-Manager-Class with Apache License 2.0 5 votes vote down vote up
private PendingIntent tphs(Context c) {
    Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
    //Intent.ACTION_MAIN, null);
    //intent.addCategory(Intent.CATEGORY_LAUNCHER);
    //final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.TetherSettings");
    //intent.setComponent(cn);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    return pi;
}
 
Example 15
Source File: PurchaseFlowLaunchTest.java    From android-easy-checkout with Apache License 2.0 5 votes vote down vote up
@Test
public void startIntentSendIntentException() throws RemoteException, BillingException, IntentSender.SendIntentException {
    PurchaseFlowLauncher launcher = spy(new PurchaseFlowLauncher(mBillingContext, TYPE_IN_APP));
    int requestCode = 1001;
    PendingIntent pendingIntent = PendingIntent.getActivity(mBillingContext.getContext(), 1, new Intent(), 0);
    Bundle bundle = new Bundle();
    bundle.putLong(Constants.RESPONSE_CODE, 0L);
    bundle.putParcelable(Constants.RESPONSE_BUY_INTENT, pendingIntent);

    doThrow(new IntentSender.SendIntentException()).when(mActivity).startIntentSenderForResult(
            any(IntentSender.class), anyInt(), any(Intent.class), anyInt(), anyInt(), anyInt());

    when(mService.getBuyIntent(
            mBillingContext.getApiVersion(),
            mBillingContext.getContext().getPackageName(),
            "",
            TYPE_IN_APP,
            ""
    )).thenReturn(bundle);

    try {
        launcher.launch(mService, mActivity, requestCode, null, "", "");
    } catch (BillingException e) {
        assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_SEND_INTENT_FAILED);
    } finally {
        verify(mService).getBuyIntent(
                mBillingContext.getApiVersion(),
                mBillingContext.getContext().getPackageName(),
                "",
                TYPE_IN_APP,
                ""
        );
        verifyNoMoreInteractions(mService);
    }
}
 
Example 16
Source File: CoreApp.java    From Android-Application with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void uncaughtException(Thread t, Throwable throwable) {
    //If this exception comes from CameraView, ignore, disable camera and make a toast
    if(throwable.getStackTrace()[0].getClassName().equals("android.hardware.Camera")){
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor = preferences.edit();
        try {
            editor.putBoolean("overlay_enabled", false);
            editor.putBoolean("cameraview_crashed", true);
            editor.commit();
        } catch (Throwable everything){
            Log.w("ExceptionHandler", "putting boolean to preferences crashed... " + everything.getMessage());
        }
        Log.w("ExceptionHandler", "CameraView error caught and disabled RGB overlay: " + throwable.getMessage());

        //try to rerun mainactivity
        Intent mStartActivity = new Intent(CoreApp.this, MainActivity.class);
        int mPendingIntentId = 123456;
        PendingIntent mPendingIntent = PendingIntent.getActivity(CoreApp.this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager mgr = (AlarmManager) CoreApp.this.getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, mPendingIntent);
    }

    //let crashlytics handle the exception after that
    mDefaultUEH.uncaughtException(t, throwable);

}
 
Example 17
Source File: Home.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static PendingIntent getHomePendingIntent() {
    return PendingIntent.getActivity(xdrip.getAppContext(), 0, new Intent(xdrip.getAppContext(), Home.class), android.app.PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 18
Source File: NotificationsUtils.java    From intra42 with Apache License 2.0 4 votes vote down vote up
private static void notify(AppClass app, ScaleTeams scaleTeams, boolean imminentCorrection) {
    String title;
    Intent notificationIntent = null;
    PendingIntent pendingIntentOpen = null;

    UsersLTE userAction = null;
    Integer projectsAction = null;

    NotificationCompat.Builder builder = getBaseNotification(app)
            .setSubText(app.getString(R.string.notifications_bookings_sub_text));

    if (imminentCorrection)
        title = app.getString(R.string.notification_bookings_title_imminent);
    else
        title = app.getString(R.string.notification_bookings_title_new);

    String text = "";
    if (scaleTeams.corrector != null && scaleTeams.corrector.equals(app.me)) { // i'm the corrector

        if (scaleTeams.teams != null && scaleTeams.teams.users != null && !scaleTeams.teams.users.isEmpty())
            userAction = scaleTeams.teams.getLeader();
        else if (scaleTeams.correcteds != null && !scaleTeams.correcteds.isEmpty())
            userAction = scaleTeams.correcteds.get(0);

        if (userAction == null)
            text = app.getString(R.string.booking_correct_somebody)
                    .replace("_date_", DateTool.getDateTimeLong(scaleTeams.beginAt));
        else if (scaleTeams.scale != null) {
            notificationIntent = UserActivity.getIntent(app, userAction);
            text = app.getString(R.string.booking_correct_login_project)
                    .replace("_date_", DateTool.getDateTimeLong(scaleTeams.beginAt))
                    .replace("_project_", scaleTeams.scale.name)
                    .replace("_login_", userAction.login);
        } else {
            notificationIntent = UserActivity.getIntent(app, userAction);
            text = app.getString(R.string.booking_correct_login)
                    .replace("_date_", DateTool.getDateTimeLong(scaleTeams.beginAt))
                    .replace("_login_", userAction.login);
        }
    } else { // i'm corrected

        if (scaleTeams.corrector == null && scaleTeams.scale != null) {
            text = app.getString(R.string.booking_corrected_by)
                    .replace("_date_", DateTool.getDateTimeLong(scaleTeams.beginAt))
                    .replace("_project_", scaleTeams.scale.name);
        } else if (scaleTeams.corrector != null && scaleTeams.scale != null) {
            notificationIntent = UserActivity.getIntent(app, scaleTeams.corrector);
            userAction = scaleTeams.corrector;
            text = app.getString(R.string.booking_corrected_by_login)
                    .replace("_date_", DateTool.getDateTimeLong(scaleTeams.beginAt))
                    .replace("_project_", scaleTeams.scale.name)
                    .replace("_login_", scaleTeams.corrector.login);
        }
    }

    if (scaleTeams.teams != null) {
        projectsAction = scaleTeams.teams.projectId;
    }

    if (notificationIntent != null) {
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        pendingIntentOpen = PendingIntent.getActivity(app, scaleTeams.id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    builder.setChannelId(app.getString(R.string.notifications_bookings_unique_id))
            .setContentTitle(title)
            .setContentText(text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
            .setContentIntent(pendingIntentOpen)
            .setWhen(scaleTeams.beginAt.getTime())
            .setGroup(app.getString(R.string.notifications_bookings_unique_id));

    if (userAction != null) {
        Intent intentUserAction = UserActivity.getIntent(app, userAction);
        if (intentUserAction != null)
            intentUserAction.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntentUser = PendingIntent.getActivity(app, userAction.id, intentUserAction, 0);
        builder.addAction(R.drawable.ic_person_black_24dp, app.getString(R.string.notification_see_user), pendingIntentUser);
    }

    if (projectsAction != null) { // add action open project
        Intent intentProjectAction;
        if (userAction != null)
            intentProjectAction = ProjectActivity.getIntent(app, projectsAction, userAction);
        else
            intentProjectAction = ProjectActivity.getIntent(app, projectsAction);
        if (intentProjectAction != null)
            intentProjectAction.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntentProject = PendingIntent.getActivity(app, projectsAction, intentProjectAction, 0);
        builder.addAction(R.drawable.ic_class_black_24dp, app.getString(R.string.notification_see_project), pendingIntentProject);
    }

    Notification notification = builder.build();

    NotificationManagerCompat.from(app).notify(app.getString(R.string.notifications_bookings_unique_id), scaleTeams.id, notification);
}
 
Example 19
Source File: SmallMediaPlayer.java    From QuranAndroid with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Private constructor for the notification media player small
 *
 * @param context Application context
 */
private SmallMediaPlayer(Context context) {

    notificationSmallView = new RemoteViews(context.getPackageName(), R.layout.notification_player_small);

    displayActivity = new Intent(context, QuranPageReadActivity.class);
    displayActivity.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, displayActivity, 0);

    //pause button in notification
    notificationSmallView.setOnClickPendingIntent(R.id.ib_pause,
            PendingIntent.getBroadcast(context, 1, new Intent(AppConstants.MediaPlayer.PAUSE),
                    PendingIntent.FLAG_UPDATE_CURRENT));

    //previous button in notification
    notificationSmallView.setOnClickPendingIntent(R.id.ib_previous,
            PendingIntent.getBroadcast(context, 1, new Intent(AppConstants.MediaPlayer.BACK),
                    PendingIntent.FLAG_UPDATE_CURRENT));

    //next button in notification
    notificationSmallView.setOnClickPendingIntent(R.id.ib_next,
            PendingIntent.getBroadcast(context, 1, new Intent(AppConstants.MediaPlayer.FORWARD),
                    PendingIntent.FLAG_UPDATE_CURRENT));

    //play button in notification
    notificationSmallView.setOnClickPendingIntent(R.id.ib_play,
            PendingIntent.getBroadcast(context, 1, new Intent(AppConstants.MediaPlayer.PLAY),
                    PendingIntent.FLAG_UPDATE_CURRENT));

    //stop button in notification
    notificationSmallView.setOnClickPendingIntent(R.id.ib_stop,
            PendingIntent.getBroadcast(context, 1, new Intent(AppConstants.MediaPlayer.STOP)
                    , PendingIntent.FLAG_UPDATE_CURRENT));

    //retrieve open application
    notificationSmallView.setOnClickPendingIntent(R.id.im_logo, configPendingIntent);

    builder = NotificationChannelManager.createSmallMediaNotificcation(context,
            SMALL_MEDIA_CHANNEL_ID,
            SMALL_MEDIA_CHANNEL_NAME,
            notificationSmallView);

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

    notificationManager.notify(0, builder.build());

    resume();
}
 
Example 20
Source File: CheckForMail.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPostExecute(List<Submission> messages) {
    if (messages != null) {
        if (!messages.isEmpty()) {
            NotificationManager notificationManager =
                    (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
            for (Submission s : messages) {
                Intent readIntent = new Intent(c, OpenContent.class);
                readIntent.putExtra(OpenContent.EXTRA_URL,
                        "https://reddit.com" + s.getPermalink());
                readIntent.setAction(s.getTitle());
                PendingIntent readPI = PendingIntent.getActivity(c,
                        (int) (s.getCreated().getTime() / 1000), readIntent,
                        0);

                Intent cancelIntent = new Intent(c, CancelSubNotifs.class);
                cancelIntent.putExtra(CancelSubNotifs.EXTRA_SUB, s.getSubredditName());
                PendingIntent cancelPi = PendingIntent.getActivity(c,  (int)s.getCreated().getTime() / 1000, cancelIntent,
                        0);


                NotificationCompat.BigTextStyle notiStyle =
                        new NotificationCompat.BigTextStyle();
                notiStyle.setBigContentTitle("/r/" + s.getSubredditName());

                notiStyle.bigText(Html.fromHtml(s.getTitle() + " " + c.getString(
                        R.string.submission_properties_seperator_comments)) + " "
                        + s.getAuthor());


                Notification notification =
                        new NotificationCompat.Builder(c).setContentIntent(readPI)
                                .setSmallIcon(R.drawable.notif)
                                .setTicker(c.getString(
                                        R.string.sub_post_notifs_notification_title,
                                        s.getSubredditName()))
                                .setWhen(System.currentTimeMillis())
                                .setAutoCancel(true)
                                .setChannelId(Reddit.CHANNEL_SUBCHECKING)
                                .setContentTitle("/r/"
                                        + s.getSubredditName()
                                        + " " + c.getString(
                                        R.string.submission_properties_seperator_comments) + " "
                                        + Html.fromHtml(s.getTitle()))
                                .setContentText(Html.fromHtml(s.getTitle()) + " " + c.getString(
                                        R.string.submission_properties_seperator_comments) + " "
                                        + s.getAuthor())
                                .setColor(Palette.getColor(s.getSubredditName()))
                                .setStyle(notiStyle)
                                .addAction(R.drawable.close, c.getString(
                                        R.string.sub_post_notifs_notification_btn,
                                        s.getSubredditName()), cancelPi)
                                .build();
                notificationManager.notify((int) (s.getCreated().getTime() / 1000),
                        notification);
            }
        }
    }
    if (Reddit.notificationTime != -1) new NotificationJobScheduler(c).start(c);
}