Example usage for android.os Bundle getString

List of usage examples for android.os Bundle getString

Introduction

In this page you can find the example usage for android.os Bundle getString.

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.manning.androidhacks.hack029.fragment.ColorFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle bundle = getArguments();/*  www  . j  a  v  a 2 s .  co m*/
    if (getArguments() != null) {
        mColor = bundle.getInt(COLOR_KEY);
        mText = bundle.getString(TEXT_KEY);
        mIsLandscape = bundle.getBoolean(LANDSCAPE_KEY);
    }
}

From source file:SMSBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (SMS_RECEIVED.equals(intent.getAction())) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            String format = bundle.getString("format");
            final SmsMessage[] messages = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
                } else {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }//  www  .  java2 s  . com
                Toast.makeText(context, messages[0].getMessageBody(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}

From source file:com.group7.dragonwars.GameActivity.java

@Override
protected final void onStart() {
    super.onStart();
    Bundle b = getIntent().getExtras();
    String mapFileName = b.getString("mapFileName");
    boolean[] isAi = b.getBooleanArray("isAi");
    GameMap map = null;/*from ww w .j a  va2s .com*/

    try {
        map = MapReader.readMapFromFile(mapFileName, this, isAi);
    } catch (JSONException e) {
        Log.d(TAG, "Failed to load the map: " + e.getMessage());
    }

    if (map == null) {
        Log.d(TAG, "map is null");
        System.exit(1);
    }

    setContentView(R.layout.activity_game);
    GameView gameView = (GameView) this.findViewById(R.id.gameView);
    state = new GameState(map, new Logic(), map.getPlayers(), gameView);
    Button menuButton = (Button) this.findViewById(R.id.menuButton);
    menuButton.setOnClickListener(gameView);
    gameView.setState(state, this);
}

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

/**
 * Is called when a Notification is cleared manualy by the User
 *///from   www.ja  va2 s  . co  m
@Override
public void onReceive(Context context, Intent intent) {
    Options options = null;
    Bundle bundle = intent.getExtras();
    JSONObject args;

    try {
        args = new JSONObject(bundle.getString(OPTIONS));
        options = new Options(context).parse(args);
    } catch (JSONException e) {
        return;
    }

    // The context may got lost if the app was not running before
    LocalNotification.setContext(context);

    Date now = new Date();
    if ((options.getInterval() != 0)) {
        options.setInitDate();
        LocalNotification.persist(options.getId(), options.getJSONObject());
    } else if ((new Date(options.getDate()).before(now))) {
        LocalNotification.unpersist(options.getId());
    }

    fireClearEvent(options);
}

From source file:com.mercandalli.android.apps.files.file.text.FileTextActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    mInitialText = savedInstanceState.getString(KEY_SAVED_TEXT);
}

From source file:com.onesignal.example.BackgroundDataBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle dataBundle = intent.getBundleExtra("data");

    try {//from ww  w .  j  a v  a  2  s  .c o m
        Log.i("OneSignalExample", "Notification content: " + dataBundle.getString("alert"));
        Log.i("OneSignalExample", "Notification title: " + dataBundle.getString("title"));
        Log.i("OneSignalExample", "Is Your App Active: " + dataBundle.getBoolean("isActive"));

        JSONObject customJSON = new JSONObject(dataBundle.getString("custom"));
        if (customJSON.has("a"))
            Log.i("OneSignalExample", "additionalData: " + customJSON.getJSONObject("a").toString());
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:kaist.cs492c_2015.washerbrowser.MyGcmListenerService.java

/**
 * Called when message is received.//from www.  j a va  2s  . c om
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    Log.i("MESSAGE", message);
    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        // normal downstream message.
    }

    // [START_EXCLUDE]
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */

    String id = "";
    String floor = "";
    String dorm = "";
    try {
        JSONObject jsonObject = new JSONObject(message);
        id = jsonObject.getString("id");
        floor = jsonObject.getString("floor");
        dorm = jsonObject.getString("dorm");
    } catch (JSONException e) {
        Log.getStackTraceString(e);
    }

    mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = mPref.edit();
    editor.putBoolean(id, false);
    editor.commit();
    String leftRight = "Left";
    if (Integer.parseInt(id) % 2 == 0) {
        leftRight = "Right";
    }
    String msg = dorm.toUpperCase() + " " + floor + "F " + leftRight + " is Available!";
    sendNotification(msg);
    // [END_EXCLUDE]
}

From source file:com.rossier.shclechelles.service.MyGcmListenerService.java

/**
 * Called when message is received./*from w  w  w.  j ava2s  .c  om*/
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    try {
        message = URLDecoder.decode(message, "UTF-8");
    } catch (UnsupportedEncodingException ex) {
        Log.e(TAG, "Fail to convert to UTF-8");
    }

    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);

    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        // normal downstream message.
    }

    // [START_EXCLUDE]
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */
    sendNotification(from, message);
    // [END_EXCLUDE]
}

From source file:com.easyauth.EasyAuth.GCMIntentService.java

private void sendNotification(Bundle extras) {

    String type = extras.getString("type");
    if (type.equals(Constants.EASYAUTH_LOGIN)) {
        String token = extras.getString("token");
        String username = extras.getString("username");

        if (token.isEmpty()) {
            Log.e(TAG, "Empty token received");
        }//from w  ww  .j a  v a2 s . c o m
        if (username.isEmpty()) {
            Log.e(TAG, "Empty username received");
        }

        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.ic_launcher).setContentTitle("EasyAuth Notification")
                .setStyle(new NotificationCompat.BigTextStyle().bigText("EasyAuth Login Performed"))
                .setContentText("EasyAuth Login Performed by " + username);

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

        JSONObject json = new JSONObject();
        try {
            json.put("token", token);
            json.put("username", username);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        new AsyncHttpTask(this.getApplicationContext()).execute("ip", json.toString());
    } else if (type.equals(Constants.EASYAUTH_TOTP_SECRET)) {
        String username = extras.getString("username");
        String secret = extras.getString("secret");

        if (secret.isEmpty()) {
            Log.e(TAG, "Empty secret received");
        }
        if (username.isEmpty()) {
            Log.e(TAG, "Empty username received");
        }

        SharedPreferences prefs = getSharedPreferences(Constants.EASYAUTH_PREFERENCES_KEY,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(Constants.EASYAUTH_TOTP_SECRET_KEY, secret);
        editor.putString(Constants.EASYAUTH_USERNAME_KEY, username);
        editor.commit();
    }
}

From source file:com.mjhram.ttaxi.gcm_client.MyGcmListenerService.java

/**
 * Called when message is received.//  w w  w  .  j  a  va 2  s  . com
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);

    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        try {
            String tag;
            JSONObject msgObj;

            msgObj = new JSONObject(message);
            tag = msgObj.getString("tag");

            if (tag.equalsIgnoreCase("drvId")) {
                int drvId = msgObj.getInt("data");//Integer.parseInt(message);
                EventBus.getDefault().post(new ServiceEvents.TRequestAccepted(drvId));
                message = Integer.toString(drvId);
                /*Intent intent = new Intent(Constants.UPDATE_REQ);
                //put whatever data you want to send, if any
                intent.putExtra("drvId", drvId);
                //send broadcast
                getApplicationContext().sendBroadcast(intent);*/
                // normal downstream message.
            } else if (tag.equalsIgnoreCase("treqState")) {
                String state = msgObj.getString("data");//Integer.parseInt(message);
                EventBus.getDefault().post(new ServiceEvents.TRequestUpdated(state));
                message = getString(R.string.gcmClientReqState) + state;
                /*Intent intent = new Intent(Constants.UPDATE_REQ);
                //put whatever data you want to send, if any
                intent.putExtra("drvId", drvId);
                //send broadcast
                getApplicationContext().sendBroadcast(intent);*/
                // normal downstream message.
            } else if (tag.equalsIgnoreCase("drvLoc")) {
                DriverInfo driverInfo = new DriverInfo();
                driverInfo.driverId = msgObj.getInt("drvId");
                driverInfo.latitude = msgObj.getDouble("lat");
                driverInfo.longitude = msgObj.getDouble("lng");

                EventBus.getDefault().post(new ServiceEvents.DriverLocationUpdate(driverInfo));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    sendNotification(message);
    // [END_EXCLUDE]
}