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:Main.java

/**
 * Enables the NFC foreground dispatch system for the given Activity.
 * //  w w w. j a  v  a  2s  .c  om
 * @param targetActivity The Activity that is in foreground and wants to have NFC Intents.
 * @see #disableNfcForegroundDispatch(android.app.Activity)
 */
public static void enableNfcForegroundDispatch(Activity targetActivity) {
    if (mNfcAdapter != null && mNfcAdapter.isEnabled()) {

        Intent intent = new Intent(targetActivity, targetActivity.getClass())
                .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(targetActivity, 0, intent, 0);
        mNfcAdapter.enableForegroundDispatch(targetActivity, pendingIntent, null,
                new String[][] { new String[] { NfcA.class.getName() } });
    }
}

From source file:HomescreenWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    for (int count = 0; count < appWidgetIds.length; count++) {
        RemoteViews appWidgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget);
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        appWidgetLayout.setOnClickPendingIntent(R.id.analogClock, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds[count], appWidgetLayout);
    }/*from  ww w. j  a  v  a 2  s . c  o  m*/
}

From source file:MainActivity.java

@Deprecated
public void showNotification(View view) {
    Intent activityIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);

    Notification notification;/*from   w ww  . ja va 2s .c  o  m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC)
                .setSmallIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_previous), "Previous",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_pause), "Pause",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_next), "Next", pendingIntent)
                                .build())
                .setContentTitle("Music").setContentText("Now playing...")
                .setLargeIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .setStyle(new Notification.MediaStyle()
                        //.setMediaSession(mMediaSession.getSessionToken())
                        .setShowActionsInCompactView(1))
                .build();
    } else {
        notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC)
                .setSmallIcon(R.mipmap.ic_launcher)
                .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_previous, "Previous",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_pause, "Pause",
                        pendingIntent).build())
                .addAction(
                        new Notification.Action.Builder(android.R.drawable.ic_media_next, "Next", pendingIntent)
                                .build())
                .setContentTitle("Music").setContentText("Now playing...")
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setStyle(new Notification.MediaStyle()
                        //.setMediaSession(mMediaSession.getSessionToken())
                        .setShowActionsInCompactView(1))
                .build();
    }
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * PendingIntent for OneShot Notification
 *
 * @param context//from  w  w  w  .j  a  v a 2s.  com
 * @return
 */
public static PendingIntent createOneShotPendingIntent(Context context) {
    int requestCode = 0; // Private request code for the sender (currently not used).
    Intent intent = new Intent();
    return PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
}

From source file:net.eledge.android.europeana.gui.notification.receiver.UrlButtonReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    int notificationId = intent.getIntExtra(PARAM_NOTIFICATIONID, Config.NOTIFICATION_NEWBLOG);
    String url = intent.getStringExtra(PARAM_URL);

    if (StringUtils.isNoneBlank(url)) {
        try {// w w w. ja v a2  s . c om
            PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(url)),
                    PendingIntent.FLAG_UPDATE_CURRENT).send();
        } catch (PendingIntent.CanceledException e) {
            Log.e(UrlButtonReceiver.class.getSimpleName(), e.getMessage(), e);
        }
    }

    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(notificationId);
}

From source file:com.parse.ParsePushUnityHelper.java

/**
 * A helper method that provides default behavior for handling ParsePushNotificationReceived.
 *//*from  w  ww  . j a va  2 s .  com*/
public static void handleParsePushNotificationReceived(Context context, String pushPayloadString) {
    try {
        JSONObject pushData = new JSONObject(pushPayloadString);

        if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) {
            return;
        }

        ManifestInfo info = new ManifestInfo(context);
        String title = pushData.optString("title", info.getDisplayName());
        String alert = pushData.optString("alert", "Notification received.");
        String tickerText = title + ": " + alert;

        Random random = new Random();
        int contentIntentRequestCode = random.nextInt();

        Intent activityIntent = info.getLauncherIntent();
        PendingIntent pContentIntent = PendingIntent.getActivity(context, contentIntentRequestCode,
                activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
                .setContentText(alert).setTicker(tickerText).setSmallIcon(info.getPushIconId())
                .setContentIntent(pContentIntent).setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);

        Notification notification = builder.build();
        NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        int notificationId = (int) System.currentTimeMillis();

        try {
            manager.notify(notificationId, notification);
        } catch (SecurityException se) {
            // Some phones throw exception for unapproved vibration.
            notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
            manager.notify(notificationId, notification);
        }
    } catch (JSONException e) {
        // Do nothing.
    }
}

From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.Utils.java

public static PendingIntent createNavigateToUrlPendingIntent(PwsResult pwsResult, Context context) {
    Intent intent = createNavigateToUrlIntent(pwsResult);
    int requestID = (int) System.currentTimeMillis();
    return PendingIntent.getActivity(context, requestID, intent, 0);
}

From source file:cn.com.flashman.cordova.xpush.Baidu.java

static public void pushCallback(JSONObject r) {
    //???// w ww . ja v  a 2s .co  m
    if (isActive && !webview.isFinishing()) {
        webview.sendJavascript("cordova.plugins.XPush.Baidu.pushCheck()");

        //?????
    } else {
        try {
            if (r.getString("type") == "message") {
                JSONObject info = new JSONObject(r.getString("message"));
                String title = info.getString("title");
                String desc = info.getString("description");
                NotificationManager nm = (NotificationManager) webview
                        .getSystemService(webview.NOTIFICATION_SERVICE);
                Notification notification = new Notification(icon, title, System.currentTimeMillis());
                notification.defaults = Notification.DEFAULT_ALL;
                PendingIntent pt = PendingIntent.getActivity(webview, 0,
                        new Intent(webview, webview.getClass()), 0);
                notification.setLatestEventInfo(webview, title, desc, pt);
                nm.notify(nitify_id, notification);
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:at.wada811.dayscounter.view.activity.SettingsActivity.java

public static PendingIntent createPendingIntent(Context context, int appWidgetId) {
    Intent intent = new Intent(context, SettingsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    return PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:com.bluelinelabs.logansquare.typeconverters.PendingIntentConverter.java

@Override
public PendingIntent parse(JsonParser jsonParser) throws IOException {
    SimplePendingIntent simplePendingIntent = SimplePendingIntent$$JsonObjectMapper._parse(jsonParser);

    PendingIntent pendingIntent = null;//from w  w w .j  a v  a  2  s  .co m

    if (simplePendingIntent.getActivity != null && simplePendingIntent.getActivity) {
        android.util.Log.d("json2notification", "getActivity:" + simplePendingIntent.getActivity);
        pendingIntent = PendingIntent.getActivity(context,
                simplePendingIntent.requestCode == null ? 0 : simplePendingIntent.requestCode,
                simplePendingIntent.intent,
                simplePendingIntent.flags == null ? PendingIntent.FLAG_UPDATE_CURRENT
                        : simplePendingIntent.flags);
    } else if (simplePendingIntent.getService != null && simplePendingIntent.getService) {
        android.util.Log.d("json2notification", "getService:" + simplePendingIntent.getService);
        pendingIntent = PendingIntent.getService(context,
                simplePendingIntent.requestCode == null ? 0 : simplePendingIntent.requestCode,
                simplePendingIntent.intent,
                simplePendingIntent.flags == null ? PendingIntent.FLAG_UPDATE_CURRENT
                        : simplePendingIntent.flags);
    }
    android.util.Log.d("json2notification", "intent:" + simplePendingIntent.intent);
    android.util.Log.d("json2notification", "requestCode:" + simplePendingIntent.requestCode);
    android.util.Log.d("json2notification", "flags:" + simplePendingIntent.flags);
    return pendingIntent;
}