Example usage for android.app PendingIntent getActivity

List of usage examples for android.app PendingIntent getActivity

Introduction

In this page you can find the example usage for android.app PendingIntent getActivity.

Prototype

public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags) 

Source Link

Document

Retrieve a PendingIntent that will start a new activity, like calling Context#startActivity(Intent) Context.startActivity(Intent) .

Usage

From source file:net.frygo.findmybuddy.GCMIntentService.java

private static void generateAcceptfriendNotification(Context context, String message, String status) {

    Random rand = new Random();
    int x = rand.nextInt();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, customlistview.class);
    if (status.equalsIgnoreCase("accept"))
        message = message + " added you as buddy";
    else/*w w  w  .ja va  2  s . c om*/
        message = message + " rejected you as buddy";
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(x, notification);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock mWakelock = pm
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title);
    mWakelock.acquire();

    // Timer before putting Android Device to sleep mode.
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        public void run() {
            mWakelock.release();
        }
    };
    timer.schedule(task, 5000);

}

From source file:com.carpool.dj.carpool.model.GcmIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///w w  w. j ava 2 s . c o  m
@SuppressWarnings("deprecation")
private static void generateNotification(Context context, String message, Bundle data, String type) {

    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // Notification notification = new Notification(icon, message, when);
    Notification notification = new Notification.Builder(context)
            .setContentTitle(Utils.nowActivity.getString(R.string.app_name)).setContentText(message)
            .setSmallIcon(icon).setWhen(when).setSound(alarmSound).build();

    // String title = context.getString(R.string.app_name);

    Intent notificationIntent = null;
    if ("CarEvent".equals(type)) {
        notificationIntent = new Intent(context, ContentActivity.class);
    } else {
        return;
    }
    notificationIntent.putExtras(data);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, Utils.nowActivity.getString(R.string.app_name), message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, notification);

}

From source file:com.magnet.mmx.client.MMXWakeupIntentService.java

private void invokeNotificationForPush(GCMPayload payload) {
    // Launch the activity with action=MAIN, category=DEFAULT.  Make sure that
    // it has DEFAULT category declared in AndroidManifest.xml intent-filter.
    PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0,
            new Intent(Intent.ACTION_MAIN).setPackage(this.getPackageName())
                    .addCategory(Intent.CATEGORY_DEFAULT) // it is redundant
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED),
            PendingIntent.FLAG_UPDATE_CURRENT);
    // If title is not specified, use the app name (compatible with iOS push notification)
    String title = (payload.getTitle() == null) ? this.getApplicationInfo().name : payload.getTitle();
    Notification.Builder noteBuilder = new Notification.Builder(this).setContentIntent(intent)
            .setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(title)
            .setContentText(payload.getBody());
    if (payload.getSound() != null) {
        // TODO: cannot handle custom sound yet; use notification ring tone.
        noteBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }//  w w  w .j a  v  a 2  s  .  co m
    if (payload.getIcon() != null) {
        noteBuilder.setSmallIcon(
                this.getResources().getIdentifier(payload.getIcon(), "drawable", this.getPackageName()));
    } else {
        noteBuilder.setSmallIcon(this.getApplicationInfo().icon);
    }
    if (payload.getBadge() != null) {
        noteBuilder.setNumber(payload.getBadge());
    }
    NotificationManager noteMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    noteMgr.notify(sNoteId++, noteBuilder.build());
}

From source file:at.bitfire.davdroid.AccountSettings.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public AccountSettings(@NonNull Context context, @NonNull Account account) throws InvalidAccountException {
    this.context = context;
    this.account = account;

    accountManager = AccountManager.get(context);

    synchronized (AccountSettings.class) {
        String versionStr = accountManager.getUserData(account, KEY_SETTINGS_VERSION);
        if (versionStr == null)
            throw new InvalidAccountException(account);

        int version = 0;
        try {//w  ww.  j  a  v  a  2 s. co m
            version = Integer.parseInt(versionStr);
        } catch (NumberFormatException ignored) {
        }
        App.log.info("Account " + account.name + " has version " + version + ", current version: "
                + CURRENT_VERSION);

        if (version < CURRENT_VERSION) {
            Notification notify = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_new_releases_light).setLargeIcon(App.getLauncherBitmap(context))
                    .setContentTitle(context.getString(R.string.settings_version_update))
                    .setContentText(context.getString(R.string.settings_version_update_settings_updated))
                    .setSubText(context.getString(R.string.settings_version_update_install_hint))
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(context.getString(R.string.settings_version_update_settings_updated)))
                    .setCategory(NotificationCompat.CATEGORY_SYSTEM)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon()
                                    .appendEncodedPath("faq/entry/davdroid-not-working-after-update/").build()),
                            PendingIntent.FLAG_CANCEL_CURRENT))
                    .setLocalOnly(true).build();
            NotificationManagerCompat nm = NotificationManagerCompat.from(context);
            nm.notify(Constants.NOTIFICATION_ACCOUNT_SETTINGS_UPDATED, notify);

            update(version);
        }
    }
}

From source file:ch.fixme.status.Widget.java

protected static void updateWidget(final Context ctxt, int widgetId, AppWidgetManager manager, Bitmap bitmap,
        String text) {//from ww w.jav  a2  s . c  om
    RemoteViews views = new RemoteViews(ctxt.getPackageName(), R.layout.widget);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
    Editor edit = prefs.edit();
    if (prefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)) {
        views.setInt(R.id.widget_image, "setBackgroundResource", 0);
    } else {
        views.setInt(R.id.widget_image, "setBackgroundResource", android.R.drawable.btn_default_small);
    }
    if (bitmap != null) {
        views.setImageViewBitmap(R.id.widget_image, bitmap);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, false); // Don't
        // need
        // to
        // force
    } else {
        views.setImageViewResource(R.id.widget_image, android.R.drawable.ic_popup_sync);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, true); // Something
        // went
        // wrong
    }
    if (text != null) {
        views.setTextViewText(R.id.widget_status, text);
        views.setViewVisibility(R.id.widget_status, View.VISIBLE);
    } else {
        views.setViewVisibility(R.id.widget_status, View.GONE);
    }
    Intent clickIntent = new Intent(ctxt, Main.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
    PendingIntent pendingIntent = PendingIntent.getActivity(ctxt, widgetId, clickIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_image, pendingIntent);
    manager.updateAppWidget(widgetId, views);
    // Is initialized
    edit.putBoolean(Main.PREF_INIT_WIDGET + widgetId, true);
    edit.commit();
}

From source file:de.appplant.cordova.plugin.localnotification.Receiver.java

/**
 * Adds an onclick handler to the notification
 *///from   ww  w. ja  v a2s  .  com
private Builder setClickEvent(Builder notification) {
    Intent intent = new Intent(context, ReceiverActivity.class)
            .putExtra(OPTIONS, options.getJSONObject().toString()).setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

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

    PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    return notification.setContentIntent(contentIntent);
}

From source file:be.vbsteven.bmtodesk.BackgroundSharingService.java

/**
 * shows the progress notification//w  ww  .ja v  a2 s  .c  om
 */
private void showProgress() {
    Notification n = new Notification(R.drawable.icon, "Sending bookmark to server...",
            System.currentTimeMillis());
    Intent i = new Intent(this, MainActivity.class); // contentintent is required. so redirect to mainpage
    PendingIntent contentIntent = PendingIntent.getActivity(this, 1, i, 0);
    n.setLatestEventInfo(this, "Bookmark to Desktop", "Sending bookmark to server...", contentIntent);
    nManager.notify(2, n);
}

From source file:com.cbtec.eliademy.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  www  . ja  va2s . co m*/

private static void generateNotification(Context context, String message) {
    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, Eliademy.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.android.settings.locationprivacy.LocationPrivacyAdvancedSettings.java

private void addNotification(int id, int textID) {
    String text = getResources().getString(textID);
    Intent intent = new Intent(getActivity(), getActivity().getClass());
    intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, LocationPrivacySettings.class.getName());
    intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);

    Notification noti = new Notification.Builder(getActivity())
            .setContentTitle(getResources().getString(R.string.lp_webservice_notification_title))
            .setSmallIcon(R.drawable.ic_settings_locationprivacy)
            .setStyle(new Notification.BigTextStyle().bigText(text)).setContentIntent(pIntent)
            .setAutoCancel(true).build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            getActivity().NOTIFICATION_SERVICE);
    notificationManager.cancel(WEBSERVICE_ERROR);
    notificationManager.cancel(WEBSERVICE_OK);
    notificationManager.cancel(GOOGLE_PLAY);
    notificationManager.notify(id, noti);
}

From source file:com.cloverstudio.spika.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) {

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);/*from w ww.jav  a 2 s . c om*/
        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());
        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent);
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);
    }
}