Example usage for android.content Intent getExtras

List of usage examples for android.content Intent getExtras

Introduction

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

Prototype

public @Nullable Bundle getExtras() 

Source Link

Document

Retrieves a map of extended data from the intent.

Usage

From source file:de.evilbrain.sendtosftp.Main.java

@SuppressLint("NewApi")
private void handlePushFromApp() {
    // Push to this app
    Intent intent = getIntent();
    String type = intent.getType();

    if (type != null) {

        // Set all visible
        fileNameText.setVisibility(View.VISIBLE);
        fileName.setVisibility(View.VISIBLE);
        imagePreview.setVisibility(View.VISIBLE);
        buttonSend.setVisibility(View.VISIBLE);

        // get Content
        String contentString = "";
        Object content = null;/*from  w  w  w .java  2s.c o  m*/

        if (android.os.Build.VERSION.SDK_INT > 16) {
            content = intent.getClipData().getItemAt(0).getUri();
            contentString = content.toString();
        } else {
            content = intent.getExtras().get(Intent.EXTRA_STREAM);
            contentString = content.toString();
        }

        // set filename
        fileName.setText(contentString);

        // Preview Image
        if (type.contains("image")) {
            imagePreview.setImageURI((Uri) content);
        }
    }
}

From source file:com.moonpi.swiftnotes.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Bundle mBundle = data.getExtras();

        if (mBundle != null) {
            // If new note was saved
            if (requestCode == NEW_NOTE_REQUEST) {
                try {
                    // Add new note to array
                    JSONObject newNote = new JSONObject();
                    newNote.put("title", mBundle.getString("title"));
                    newNote.put("body", mBundle.getString("body"));
                    newNote.put("colour", mBundle.getString("colour"));
                    newNote.put("favoured", false);
                    newNote.put("fontSize", mBundle.getInt("fontSize"));

                    notes.put(newNote);//from  w w w .  j  a  v a2 s  . c o  m
                    adapter.notifyDataSetChanged();

                    writeToJSON();

                    // If no notes, show 'Press + to add new note' text, invisible otherwise
                    if (notes.length() == 0)
                        noNotes.setVisibility(View.VISIBLE);
                    else
                        noNotes.setVisibility(View.INVISIBLE);

                    Toast toast = Toast.makeText(getApplicationContext(),
                            getResources().getString(R.string.toast_new_note), Toast.LENGTH_SHORT);
                    toast.show();

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            // If existing note was saved
            else {
                try {
                    // Update array with new data
                    JSONObject newNote = notes.getJSONObject(requestCode);
                    newNote.put("title", mBundle.getString("title"));
                    newNote.put("body", mBundle.getString("body"));
                    newNote.put("colour", mBundle.getString("colour"));
                    newNote.put("fontSize", mBundle.getInt("fontSize"));

                    // Update note at position
                    notes.put(requestCode, newNote);
                    adapter.notifyDataSetChanged();

                    writeToJSON();

                    Toast toast = Toast.makeText(getApplicationContext(),
                            getResources().getString(R.string.toast_note_saved), Toast.LENGTH_SHORT);
                    toast.show();

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    else if (resultCode == RESULT_CANCELED) {
        Bundle mBundle = null;

        if (data != null && data.hasExtra("request"))
            mBundle = data.getExtras();

        if (requestCode == NEW_NOTE_REQUEST) {
            if (mBundle != null) {
                // If new note discarded, show toast
                if (mBundle.getString("request").equals("discard")) {
                    Toast toast = Toast.makeText(getApplicationContext(),
                            getResources().getString(R.string.toast_empty_note_discarded), Toast.LENGTH_SHORT);
                    toast.show();
                }
            }
        }

        else {
            if (mBundle != null) {
                // If delete pressed in EditActivity, call deleteNote method with
                // requestCode as position
                if (mBundle.getString("request").equals("delete"))
                    deleteNote(this, requestCode);
            }
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.mikecorrigan.trainscorekeeper.MainActivity.java

private String getSpecFromIntent(final Intent intent, String defaultSpec) {
    Log.vc(VERBOSE, TAG, "getSpecFromIntent: intent=" + intent + ", defaultSpec=" + defaultSpec);

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this /* context */);

    // Attempt to read the game spec from shared preferences.
    // If the preference does not exist, use the default spec passed in as a parameter.
    defaultSpec = sp.getString(Preferences.PREFS_KEY_GAME_SPEC, defaultSpec);

    if (intent == null) {
        Log.d(TAG, "getSpecFromIntent: no intent");
        return defaultSpec;
    }//from w w w .java 2s  . com

    Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.d(TAG, "getSpecFromIntent: no extras");
        return defaultSpec;
    }

    String spec = extras.getString(KEY_GAME_SPEC);
    Log.d(TAG, "getSpecFromIntent: spec=" + spec);

    if (TextUtils.isEmpty(spec)) {
        Log.d(TAG, "getSpecFromIntent: no spec");
        return defaultSpec;
    }

    // Save the game spec to shared preferences.
    // This is only necessary if the activity was launched with an explicit game spec.
    sp.edit().putString(Preferences.PREFS_KEY_GAME_SPEC, spec).commit();

    return spec;
}

From source file:com.bonsai.btcreceive.WalletService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    WalletApplication wallapp = (WalletApplication) getApplicationContext();

    // Establish our SyncState
    Bundle bundle = intent.getExtras();
    String syncStateStr = bundle.getString("SyncState");
    if (syncStateStr == null)
        syncStateStr = "STARTUP";
    mSyncState = syncStateStr.equals("CREATED") ? SyncState.CREATED
            : syncStateStr.equals("RESTORE") ? SyncState.RESTORE
                    : syncStateStr.equals("STARTUP") ? SyncState.STARTUP
                            : syncStateStr.equals("RESCAN") ? SyncState.RESCAN
                                    : syncStateStr.equals("RERESCAN") ? SyncState.RERESCAN : SyncState.STARTUP;

    mKeyCrypter = wallapp.mKeyCrypter;/* w  ww.j  av a  2s .c o  m*/
    mAesKey = wallapp.mAesKey;

    // Set any new key's creation time to now.
    long now = Utils.now().getTime() / 1000;

    mTask = new SetupWalletTask();
    mTask.execute(now);

    mLogger.info("WalletService started");

    showStatusNotification();

    mIsRunning = true;

    return Service.START_STICKY;
}

From source file:de.geithonline.abattlwp.billinghelper.IabHelper.java

int getResponseCodeFromIntent(final Intent i) {
    final Object o = i.getExtras().get(RESPONSE_CODE);
    if (o == null) {
        logError("Intent with no response code, assuming OK (known issue)");
        return BILLING_RESPONSE_RESULT_OK;
    } else if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else if (o instanceof Long) {
        return (int) ((Long) o).longValue();
    } else {//  w w w. jav a  2 s.  co m
        logError("Unexpected type for intent response code.");
        logError(o.getClass().getName());
        throw new RuntimeException("Unexpected type for intent response code: " + o.getClass().getName());
    }
}

From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java

/************
 *  PURPOSE: Handles the primary thread in the service
 *  ARGUMENTS: Intent intent/*from  w  w  w.j av  a 2  s.  c  o m*/
 *  RETURNS: VOID
 *  AUTHOR: Devin Collins <agent14709@gmail.com>
 *************/
@Override
protected void onHandleIntent(Intent intent) {
    // Get our stored data from the intent
    username = intent.getStringExtra("username");
    password = intent.getStringExtra("password");
    messenger = (Messenger) intent.getExtras().get("handler");
    calID = intent.getIntExtra("calendarID", -1);

    String url = getApplicationContext().getResources().getString(R.string.url);

    // Create variables to be used through the application
    List<String[]> workDays = null;
    ConnectionManager conn = ConnectionManager.newConnection();

    /************
     * Once we verify that we have a valid token, we get the actual schedule
     *************/
    updateStatus("Logging in...");
    String tempToken = conn.getData(url + "/etm/login.jsp");
    if (tempToken != null) {
        loginToken = parseToken(tempToken);
    } else {
        showError("Error connecting to MyTLC, make sure you have a valid network connection");
        return;
    }

    String postResults = null;
    // This creates our login information
    List<NameValuePair> parameters = createParams();
    if (loginToken != null) {
        // Here we send the information to the server and login
        postResults = conn.postData(url + "/etm/login.jsp", parameters);
    } else {
        showError("Error retrieving your login token");
        return;
    }

    if (postResults != null && postResults.toLowerCase().contains("etmmenu.jsp")
            && !postResults.toLowerCase().contains("<font size=\"2\">")) {
        updateStatus("Retrieving schedule...");
        postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp");
    } else {
        String error = parseError(postResults);
        if (error != null) {
            showError(error);
        } else {
            showError("Error logging in, please verify your username and password");
        }
        return;
    }

    // If we successfully got the information, then parse out the schedule to read it properly
    String secToken = null;
    if (postResults != null) {
        updateStatus("Parsing schedule...");
        workDays = parseSchedule(postResults);
        secToken = parseSecureToken(postResults);
        wbat = parseWbat(postResults);
    } else {
        showError("Could not obtain user schedule");
        return;
    }

    if (secToken != null) {
        parameters = createSecondParams(secToken);
        postResults = conn.postData(url + "/etm/time/timesheet/etmTnsMonth.jsp", parameters);
    } else {
        String error = parseError(postResults);
        if (error != null) {
            showError(error);
        } else {
            showError("Error retrieving your security token");
        }
        return;
    }

    List<String[]> secondMonth = null;
    if (postResults != null) {
        secondMonth = parseSchedule(postResults);
    } else {
        showError("Could not obtain user schedule");
        return;
    }

    if (secondMonth != null) {
        if (workDays == null) {
            workDays = secondMonth;
        } else {
            workDays.addAll(secondMonth);
        }
        finalDays = workDays;
    } else {
        String error = parseError(postResults);
        if (error != null) {
            showError(error);
        } else {
            showError("There was an error retrieving your schedule");
        }
        return;
    }

    // Add our shifts to the calendar
    updateStatus("Adding shifts to calendar...");
    int numShifts = addDays();

    if (finalDays != null && numShifts > -1) {
        // Report back that we're successful!
        Message msg = Message.obtain();
        Bundle b = new Bundle();
        b.putString("status", "DONE");
        b.putInt("count", numShifts);
        msg.setData(b);
        try {
            messenger.send(msg);
        } catch (Exception e) {
            // Nothing
        }
    } else {
        showError("Couldn't add your shifts to your calendar");
    }

}

From source file:babybear.akbquiz.ConfigActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUESTCODE_IMAGE) {
        if (resultCode == RESULT_OK) {
            Bundle d = data.getExtras();
            Set<String> keys = d.keySet();
            for (String key : keys) {
                Log.d(TAG, "key : " + key + " values : " + d.get(key));
            }//from   ww w  .java 2  s.c o m
            cfgEditor.putBoolean(Database.KEY_use_custom_background, true);
            cfgEditor.commit();
            cfgflipper.setBackgroundDrawable(Drawable.createFromPath(customBgImage.getPath()));
        }
        return;
    }

    if (weiboSsoHandler != null) {
        weiboSsoHandler.authorizeCallBack(requestCode, resultCode, data);
    }
}

From source file:li.barter.fragments.EditProfileFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {

    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != Activity.RESULT_OK) {
        return;/*from  w  w w .j av  a2s .  c  om*/
    }

    switch (requestCode) {
    case PICK_FROM_CAMERA:
        // doCrop(PICK_FROM_CAMERA);
        setAndSaveImage(mCameraImageCaptureUri, PICK_FROM_CAMERA);
        break;

    case PICK_FROM_FILE:
        mGalleryImageCaptureUri = data.getData();
        setAndSaveImage(mGalleryImageCaptureUri, PICK_FROM_FILE);
        // doCrop(PICK_FROM_FILE);
        break;

    case CROP_FROM_CAMERA:
        final Bundle extras = data.getExtras();
        if (extras != null) {
            mCompressedPhoto = extras.getParcelable("data");
            mProfileImageView.setImageBitmap(mCompressedPhoto);
        }
        PhotoUtils.saveImage(mCompressedPhoto, "barterli_avatar_small.png");
        break;

    case AppConstants.RequestCodes.EDIT_PREFERRED_LOCATION: {
        loadPreferredLocation();
        break;
    }

    }
}

From source file:org.ohmage.auth.AuthenticatorActivity.java

private void finishAccountAdd(String accountName, String authToken, String password) {
    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AuthUtil.ACCOUNT_TYPE);
    if (authToken != null)
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, authToken);
    intent.putExtra(AccountManager.KEY_PASSWORD, password);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);//from ww  w . j  av  a2 s  .  com
    finish();

    if (!calledByAuthenticator())
        startActivity(new Intent(getBaseContext(), MainActivity.class));
}

From source file:com.pax.pay.PaymentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_null);

    Intent intent = getIntent();
    ActivityStack.getInstance().push(this);

    // check if neptune is installed
    isInstalledNeptune = Component.neptuneInstalled(this, new DialogInterface.OnDismissListener() {

        @Override/*from w  ww  .jav a2s. c  o m*/
        public void onDismiss(DialogInterface arg0) {
            transFinish(new ActionResult(TransResult.ERR_ABORTED, null));
        }
    });

    if (!isInstalledNeptune) {
        return;
    }
    FinancialApplication.mApp.initManagers();
    Device.enableStatusBar(false);
    Device.enableHomeRecentKey(false);

    try {
        String jsonStr = intent.getExtras().getString(REQUEST);
        json = new JSONObject(jsonStr);
    } catch (Exception e) {
        transFinish(new ActionResult(TransResult.ERR_PARAM, null));
        return;
    }

    initDev();
}