Example usage for android.content Intent replaceExtras

List of usage examples for android.content Intent replaceExtras

Introduction

In this page you can find the example usage for android.content Intent replaceExtras.

Prototype

public @NonNull Intent replaceExtras(@Nullable Bundle extras) 

Source Link

Document

Completely replace the extras in the Intent with the given Bundle of extras.

Usage

From source file:Main.java

static void displayMessage(Context context, Intent in) {

    Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
    intent.replaceExtras(in);

    context.sendBroadcast(intent);//from  www  .  j av  a 2 s .c o m
}

From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java

/**
 * Set the theme of the Activity, and restart it by creating a new Activity of the same type.
 *//*w w  w  .ja va 2s  .c o  m*/

public static void changeToTheme(Activity activity, Intent originalIntent) {
    activity.finish();
    Intent newIntent = new Intent(activity, activity.getClass());
    newIntent.replaceExtras(originalIntent);
    activity.startActivity(newIntent);
}

From source file:com.enadein.carlogbook.core.AppMediator.java

protected void startActivity(Class<?> cls, Bundle extras) {
    Intent intent = new Intent(activity, cls);

    if (extras != null) {
        intent.replaceExtras(extras);
    }/* w w  w  .ja  v  a 2  s  . com*/

    activity.startActivity(intent);
}

From source file:com.enadein.carlogbook.core.AppMediator.java

protected void startActivityForResult(Class<?> cls, Bundle extras, int requestCode) {
    Intent intent = new Intent(activity, cls);

    if (extras != null) {
        intent.replaceExtras(extras);
    }/*from w  w w  .ja  va2 s  .  c o m*/

    (activity).startActivityForResult(intent, requestCode);
}

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);/*  w w  w . ja v a  2 s.c o  m*/
        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);
    }
}

From source file:com.snappy.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras,
        String messageData) {/*from w  ww .j  a v a  2  s .com*/

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);

        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), messageData, pendingIntent);

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);

    }

    Log.i(LOG_TAG, message);
    Log.i(LOG_TAG, fromName);

}

From source file:com.snappy.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from   w  ww  .  j a  v  a 2 s.co m
private void generateNotification(Context context, String message, String fromName, Bundle pushExtras,
        String body) {

    db = new LocalDB(context);
    List<LocalMessage> myMessages = db.getAllMessages();

    // Open a new activity called GCMMessageView
    Intent intento = new Intent(this, SplashScreenActivity.class);
    intento.replaceExtras(pushExtras);
    // Pass data to the new activity
    intento.putExtra(Const.PUSH_INTENT, true);
    intento.setAction(Long.toString(System.currentTimeMillis()));
    intento.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

    // Starts the activity on notification click
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the notification with a notification builder
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis())
            .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message))
            .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
            .setContentText(body).setContentIntent(pIntent);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message));

    for (int i = 0; i < myMessages.size(); i++) {

        inboxStyle.addLine(myMessages.get(i).getMessage());
    }

    notification.setStyle(inboxStyle);

    // Remove the notification on click
    //notification.flags |= Notification.FLAG_AUTO_CANCEL;
    //notification.defaults |= Notification.DEFAULT_VIBRATE;
    //notification.defaults |= Notification.DEFAULT_SOUND;
    //notification.defaults |= Notification.DEFAULT_LIGHTS;

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(R.string.app_name, notification.build());
    {
        // Wake Android Device when notification received
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

        final PowerManager.WakeLock mWakelock = pm
                .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
        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.github.michalbednarski.intentslab.valueeditors.framework.EditorLauncher.java

void openEditorFragment(Class<? extends ValueEditorFragment> editorFragment, Bundle args) {
    args.putString(SingleEditorActivity.EXTRA_FRAGMENT_CLASS_NAME, editorFragment.getName());
    Intent intent = new Intent(mHelperFragment.getActivity(), SingleEditorActivity.class);
    intent.replaceExtras(args);
    ChildFragmentWorkaround.startActivityForResultFromFragment(mHelperFragment, intent,
            REQUEST_CODE_INTERNAL_EDITOR);
}

From source file:org.enbyted.android.zseinfo.view.activity.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    InfoApp.getContext().setInFront(true);
    InfoApp.getContext().notifyConfigChanged();
    InfoApp.getContext().notifyDataChanged();

    Intent intent = getIntent();
    String tab;/*from  ww  w  . ja  va 2  s .  co  m*/
    if (intent != null) {
        if (intent.hasExtra("TYPE"))
            NotificationManager.removeNotify(intent.getIntExtra("TYPE", 0));

        if ((tab = intent.getStringExtra("tab")) != null) {
            //                InfoApp.getContext().notifyConfigChanged();
            //                InfoApp.getContext().notifyDataChanged();
            switch (tab) {
            case "TAB_REPLACEMENTS": {
                getSupportActionBar().setSelectedNavigationItem(1);
                if (intent.getBooleanExtra("my_class", false)) {
                    ((ReplacementsSection) pagerAdapter.getSection(1)).showMyClass();
                }
                break;
            }
            }
        }
        intent.replaceExtras(new Bundle());
    }
}

From source file:it.openyoureyes.test.panoramio.Panoramio.java

public List<GeoItem> examinePanoramio(Location current, double distance, Drawable myImage, Intent intent) {
    ArrayList<GeoItem> result = new ArrayList<GeoItem>();

    /*/*ww w . j a va  2s.c o  m*/
     * var requiero_fotos = new Json.Remote(
     * "http://www.panoramio.com/map/get_panoramas.php?order=popularity&
     * set=
     * full&from=0&to=10&minx=-5.8&miny=42.59&maxx=-5.5&maxy=42.65&size=
     * medium "
     */
    Location loc1 = new Location("test");
    Location loc2 = new Location("test_");
    AbstractGeoItem.calcDestination(current.getLatitude(), current.getLongitude(), 225, distance / 2, loc1);
    AbstractGeoItem.calcDestination(current.getLatitude(), current.getLongitude(), 45, distance / 2, loc2);
    try {
        URL url = new URL(
                "http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=full&from=0&to=10&minx="
                        + loc1.getLongitude() + "&miny=" + loc1.getLatitude() + "&maxx=" + loc2.getLongitude()
                        + "&maxy=" + loc2.getLatitude() + "&size=thumbnail");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();

        String line;
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuffer buf = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            buf.append(line + " ");
        }
        reader.close();
        is.close();
        conn.disconnect();
        // while (is.read(buffer) != -1);
        String jsontext = buf.toString();
        Log.d("Json Panoramio", jsontext);
        JSONObject entrie = new JSONObject(jsontext);
        JSONArray arr = entrie.getJSONArray("photos");
        for (int i = 0; i < arr.length(); i++) {
            JSONObject panoramioObj = arr.getJSONObject(i);
            double longitude = panoramioObj.getDouble("longitude");
            double latitude = panoramioObj.getDouble("latitude");
            String urlFoto = panoramioObj.getString("photo_file_url");
            String idFoto = panoramioObj.getString("photo_id");
            Bundle bu = intent.getExtras();
            if (bu == null)
                bu = new Bundle();
            bu.putString("id", idFoto);
            intent.replaceExtras(bu);
            BitmapDrawable bb = new BitmapDrawable(downloadFile(urlFoto));
            PanoramioItem item = new PanoramioItem(latitude, longitude, false, bb, intent);
            result.add(item);
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return result;

}