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:com.swisscom.safeconnect.utils.gcm.GcmBroadcastReceiver.java

private void sendNotification(String title, String msg, Context ctx) {
    mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancelAll();/*from   w w w.  ja  v a  2s  .c  om*/

    Intent intentSubscriptions = new Intent(ctx, DashboardActivity.class);
    intentSubscriptions.putExtra(DashboardActivity.KEY_OPEN_SUBSCRIPTIONS, true);

    // without FLAG_CANCEL_CURRENT the parameters don't arrive
    PendingIntent subscriptionsIntent = PendingIntent.getActivity(ctx, 0, intentSubscriptions,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            //.setDefaults(Notification.DEFAULT_ALL) // with DEFAULT_ALL it requires VIBRATE permissions! (on HTC One S 4.1.1)
            .setSmallIcon(R.drawable.ic_notif).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .addAction(R.drawable.ic_subscription_shoppingcart, ctx.getString(R.string.push_extend),
                    subscriptionsIntent);

    mBuilder.setContentIntent(subscriptionsIntent);
    mBuilder.setAutoCancel(true);

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:heartware.com.heartware_master.MainActivity.java

@Override
public void onResume() {
    super.onResume();

    if (!notification) {
        //prepare intent that is triggered when notification is selected
        Intent intent = new Intent(this, MeetupsFragment.class);
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

        //build notification
        Notification n = new Notification.Builder(this).setContentTitle("Heartware")
                .setContentText("Reminder: You have a Meetup today!").setContentIntent(pIntent)
                .setSmallIcon(R.mipmap.ic_launcher).build();

        notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        notificationManager.notify(noteID, n);

        //HeartwareApplication app = (HeartwareApplication) this.getApplication();
        //final ArrayList<HashMap<String, String>> meetups = mDBAdapter.getAllMeetups(app.getCurrentProfileId());

    }/*  w  ww .  java 2 s . com*/

    // Call the 'activateApp' method to log an app event for use in analytics and advertising
    // reporting.  Do so in the onResume methods of the primary Activities that an app may be
    // launched into.
    AppEventsLogger.activateApp(this);
}

From source file:com.android.settings.aokpstats.ReportingService.java

private void promptUser() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Intent nI = new Intent();
    nI.setComponent(new ComponentName(getPackageName(), Settings.AnonymousStatsActivity.class.getName()));
    PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0);
    Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_aokp_stats_notif)
            .setAutoCancel(true).setTicker(getString(R.string.anonymous_statistics_title)).setContentIntent(pI)
            .setWhen(0).setContentTitle(getString(R.string.anonymous_statistics_title))
            .setContentText(getString(R.string.anonymous_notification_desc));
    nm.notify(1, builder.getNotification());
}

From source file:com.pushnotificationsapp.app.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, DemoActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:ch.christofbuechi.testgcm.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    MyWrapper myWrapper = null;/*from  w  w w  .  ja  va  2 s. c o m*/

    ObjectMapper objectMapper = new ObjectMapper();
    try {
        myWrapper = objectMapper.readValue(new String(msg), MyWrapper.class);
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(this.getClass().getName(), "Message: " + myWrapper.getData().getMsg());
    Log.d(this.getClass().getName(), "Message: " + myWrapper.getRegistration_id());
    Log.d(this.getClass().getName(), "Message: " + myWrapper.getData().getCt());
    Log.d(this.getClass().getName(), "Message: " + myWrapper.getData().getV());

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(myWrapper.getData().getMsg()))
            .setContentText(myWrapper.getData().getMsg());

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.tcity.android.sync.SyncService.java

private void notify(@NotNull String buildConfigurationId, @NotNull String parentProjectId, int size) {
    Notification.Builder builder = new Notification.Builder(this);

    String title = size + " new build" + (size == 1 ? "" : "s");
    String projectName = myDB.getProjectName(parentProjectId);
    String buildConfigurationName = myDB.getBuildConfigurationName(buildConfigurationId);

    Intent activityIntent = new Intent(this, BuildConfigurationOverviewActivity.class);
    activityIntent.putExtra(BuildConfigurationOverviewActivity.ID_INTENT_KEY, buildConfigurationId);
    activityIntent.setAction(Long.toString(System.currentTimeMillis()));

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);

    //noinspection deprecation
    Notification notification = builder.setSmallIcon(R.drawable.ic_launcher).setContentTitle(title)
            .setContentText(projectName + " - " + buildConfigurationName).setContentIntent(contentIntent)
            .setAutoCancel(true).getNotification();

    myManager.notify(buildConfigurationId.hashCode(), notification);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    try {//  www.jav  a 2 s.com
        String packageName = obj.getString(PACKAGE_NAME);
        String feedName = obj.getString("sharedFeedName");
        JSONArray ids = obj.getJSONArray(PARTICIPANTS);
        Intent launch = new Intent();
        launch.setAction(Intent.ACTION_MAIN);
        launch.addCategory(Intent.CATEGORY_LAUNCHER);
        launch.putExtra("type", "invite_app_feed");
        launch.putExtra("creator", false);
        launch.putExtra("sender", from.id);
        launch.putExtra("sharedFeedName", feedName);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        long[] idArray = new long[ids.length()];
        for (int i = 0; i < ids.length(); i++) {
            idArray[i] = ids.getLong(i);
        }
        launch.putExtra("participants", idArray);
        launch.setPackage(packageName);
        final PackageManager mgr = context.getPackageManager();
        List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0);
        if (resolved.size() == 0) {
            Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show();
            return;
        }
        ActivityInfo info = resolved.get(0).activityInfo;
        launch.setComponent(new ComponentName(info.packageName, info.name));
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
                PendingIntent.FLAG_CANCEL_CURRENT);

        (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name,
                "Invitation received from " + from.name, "Click to launch application: " + packageName,
                contentIntent);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:com.SmartDial.ForegroundService.java

/**
 * Create a notification as the visible part to be able to put the service
 * in a foreground state./*  w w w .j  a v  a  2s .c om*/
 *
 * @return
 *      A local ongoing notification which pending intent is bound to the
 *      main activity.
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private Notification makeNotification() {
    JSONObject settings = BackgroundMode.getSettings();
    Context context = getApplicationContext();
    String pkgName = context.getPackageName();
    Intent intent = context.getPackageManager().getLaunchIntentForPackage(pkgName);

    Notification.Builder notification = new Notification.Builder(context)
            .setContentTitle(settings.optString("title", "")).setContentText(settings.optString("text", ""))
            .setTicker(settings.optString("ticker", "")).setOngoing(true).setSmallIcon(getIconResId());

    if (intent != null && settings.optBoolean("resume")) {

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

        notification.setContentIntent(contentIntent);
    }

    if (Build.VERSION.SDK_INT < 16) {
        // Build notification for HoneyComb to ICS
        return notification.getNotification();
    } else {
        // Notification for Jellybean and above
        return notification.build();
    }
}

From source file:com.amaze.filemanager.services.ExtractService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Bundle b = new Bundle();
    b.putInt("id", startId);
    epath = PreferenceManager.getDefaultSharedPreferences(this).getString("extractpath", "");
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String file = intent.getStringExtra("zip");
    eentries = intent.getBooleanExtra("entries1", false);
    if (eentries) {
        entries = intent.getStringArrayListExtra("entries");
    }//from   w  w w.  j  a v a2  s.com
    b.putString("file", file);
    DataPackage intent1 = new DataPackage();
    intent1.setName(file);
    intent1.setTotal(0);
    intent1.setDone(0);
    intent1.setId(startId);
    intent1.setP1(0);
    intent1.setCompleted(false);
    hash1.put(startId, intent1);
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.putExtra("openprocesses", true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mBuilder = new NotificationCompat.Builder(cd);
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setContentTitle(getResources().getString(R.string.extracting))
            .setContentText(new File(file).getName()).setSmallIcon(R.drawable.ic_doc_compressed);
    hash.put(startId, true);
    new Doback().execute(b);
    return START_STICKY;
}

From source file:com.example.week04.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.hummingbird_icon_small).setAutoCancel(true)
            .setVibrate(new long[] { 0, 500, 200, 500 }).setContentTitle("Hummingbird")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}