Search in sources :

Example 11 with TaskStackBuilder

use of android.app.TaskStackBuilder in project Fairphone by Kwamecorp.

the class UpdaterService method setNotification.

private void setNotification() {
    Context context = getApplicationContext();
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.fairphone_updater_tray_icon_small).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.fairphone_updater_tray_icon)).setContentTitle(context.getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.fairphoneUpdateMessage));
    Intent resultIntent = new Intent(context, FairphoneUpdater.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(FairphoneUpdater.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    Notification notificationWhileRunnig = builder.build();
    // Add notification
    manager.notify(0, notificationWhileRunnig);
    // to update the activity
    Intent updateIntent = new Intent(FairphoneUpdater.FAIRPHONE_UPDATER_NEW_VERSION_RECEIVED);
    sendBroadcast(updateIntent);
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

Example 12 with TaskStackBuilder

use of android.app.TaskStackBuilder in project MadMax by deviz92.

the class FirebaseServiceMessage method onMessageReceived.

/*    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate");
    }*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    String body = remoteMessage.getNotification().getBody();
    Map<String, String> data = remoteMessage.getData();
    Log.d(TAG, "notification body: " + body);
    String message[], messageContent = null;
    // Creates an explicit intent for an Activity in the app
    Intent resultIntent = null;
    messageContent = body;
    switch(data.get("notificationTitle")) {
        case "notification_invite":
            resultIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
            resultIntent.putExtra("groupID", data.get("groupID"));
            break;
        case "notification_expense_added":
            resultIntent = new Intent(getApplicationContext(), ExpenseDetailActivity.class);
            resultIntent.putExtra("groupID", data.get("groupID"));
            resultIntent.putExtra("expenseID", data.get("expenseID"));
            break;
        case "notification_expense_removed":
            resultIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
            resultIntent.putExtra("groupID", data.get("groupID"));
            resultIntent.putExtra("expenseID", data.get("expenseID"));
            break;
        case "notification_proposalExpense_added":
            resultIntent = new Intent(getApplicationContext(), PendingExpenseDetailActivity.class);
            resultIntent.putExtra("expenseID", data.get("expenseID"));
            break;
    }
    // User provaCurrent = MainActivity.getCurrentUser();
    resultIntent.putExtra("userID", getCurrentUID());
    NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.icon).setContentTitle(remoteMessage.getNotification().getTitle()).setContentText(messageContent);
    // 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(getApplicationContext());
    // 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 | PendingIntent.FLAG_ONE_SHOT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    // mId allows you to update the notification later on.
    mNotificationManager.notify(1, notification);
/*String body = remoteMessage.getNotification().getBody();
        Log.d(TAG, "notification body: "+body);
        Map<String, String> data = remoteMessage.getData();
        showNotification(remoteMessage.getNotification().getTitle(), body, data);*/
}
Also used : NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) GroupDetailActivity(com.polito.mad17.madmax.activities.groups.GroupDetailActivity) ExpenseDetailActivity(com.polito.mad17.madmax.activities.expenses.ExpenseDetailActivity) PendingExpenseDetailActivity(com.polito.mad17.madmax.activities.expenses.PendingExpenseDetailActivity) NotificationCompat(android.support.v7.app.NotificationCompat) PendingExpenseDetailActivity(com.polito.mad17.madmax.activities.expenses.PendingExpenseDetailActivity) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder)

Example 13 with TaskStackBuilder

use of android.app.TaskStackBuilder in project android-beacon-library by AltBeacon.

the class BluetoothMedic method sendScreenNotification.

@RequiresApi(21)
private void sendScreenNotification(String message, String detail) {
    Context context = mContext;
    if (context == null) {
        LogManager.e(TAG, "congtext is unexpectedly null");
        return;
    }
    initializeWithContext(context);
    if (this.mNotificationsEnabled) {
        if (!this.mNotificationChannelCreated) {
            createNotificationChannel(context, "err");
        }
        NotificationCompat.Builder builder = (new NotificationCompat.Builder(context, "err")).setContentTitle("BluetoothMedic: " + message).setSmallIcon(mNotificationIcon).setVibrate(new long[] { 200L, 100L, 200L }).setContentText(detail);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntent(new Intent("NoOperation"));
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
        builder.setContentIntent(resultPendingIntent);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            notificationManager.notify(1, builder.build());
        }
    }
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) NotificationCompat(androidx.core.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) RequiresApi(androidx.annotation.RequiresApi)

Example 14 with TaskStackBuilder

use of android.app.TaskStackBuilder in project superCleanMaster by joyoyao.

the class Notifications method sendNotification.

public void sendNotification() {
    long itemId = 12345678910L;
    int notificationId = ((Long) itemId).intValue();
    // Create PendingIntent
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra("hello", itemId);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    // Create Notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle("Title").setContentText("Notification text").setContentIntent(resultPendingIntent);
    Notification notification = builder.build();
    // Show Notification
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notification);
}
Also used : NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

Example 15 with TaskStackBuilder

use of android.app.TaskStackBuilder in project zype-android by zype.

the class PlayerService method createNotificationChannel.

@RequiresApi(Build.VERSION_CODES.O)
private void createNotificationChannel(String channelId, String channelName, String videoTitle, String videoId, MediaSessionCompat.Token mediaSessionToken, Boolean isPlay) {
    Intent resultIntent = new Intent(this, VideoDetailActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString(BundleConstants.VIDEO_ID, videoId);
    resultIntent.putExtras(bundle);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    // Create the TaskStackBuilder and add the intent, which inflates the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntentWithParentStack(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationChannel chan = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
    chan.enableVibration(false);
    chan.setSound(null, null);
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    assert manager != null;
    manager.createNotificationChannel(chan);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
    notificationBuilder.setContentIntent(resultPendingIntent).setContentTitle(this.getString(R.string.app_name)).setContentText(videoTitle).setSmallIcon(R.drawable.ic_background_playback).setPriority(NotificationCompat.PRIORITY_MAX).setCategory(Notification.CATEGORY_SERVICE).setAutoCancel(true).setOngoing(true).setWhen(0);
    if (isPlay) {
        notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_pause_black_24dp, "Pause", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
    } else {
        notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_play_arrow_black_24dp, "Play", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
    }
    notificationBuilder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle().setMediaSession(mediaSessionToken).setShowCancelButton(true).setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_STOP)));
    Notification notification = notificationBuilder.build();
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(ZypeApp.NOTIFICATION_ID, notificationBuilder.build());
    startForeground(ZypeApp.NOTIFICATION_ID, notification);
}
Also used : NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle) TaskStackBuilder(android.app.TaskStackBuilder) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) NotificationChannel(android.app.NotificationChannel) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

TaskStackBuilder (android.app.TaskStackBuilder)24 PendingIntent (android.app.PendingIntent)23 Intent (android.content.Intent)23 Notification (android.app.Notification)18 NotificationManager (android.app.NotificationManager)18 NotificationCompat (android.support.v4.app.NotificationCompat)9 NotificationChannel (android.app.NotificationChannel)6 SharedPreferences (android.content.SharedPreferences)6 SpannableStringBuilder (android.text.SpannableStringBuilder)5 SuppressLint (android.annotation.SuppressLint)4 TargetApi (android.annotation.TargetApi)4 Bitmap (android.graphics.Bitmap)4 Typeface (android.graphics.Typeface)4 FloatingActionButton (android.support.design.widget.FloatingActionButton)4 SpannableString (android.text.SpannableString)4 View (android.view.View)4 InterstitialAd (com.google.android.gms.ads.InterstitialAd)4 Context (android.content.Context)2 Resources (android.content.res.Resources)2 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)2