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:edu.cmu.cs.cloudlet.android.CloudletActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == 0) {
            String ret = data.getExtras().getString("message");
        }//from  www .j a v a  2 s. c  o  m
    }

    // send close VM message
    if (this.connector != null) {
        this.connector.closeRequest();
    }
}

From source file:org.andicar.service.UpdateCheckService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    if (getSharedPreferences(StaticValues.GLOBAL_PREFERENCE_NAME, Context.MODE_MULTI_PROCESS)
            .getBoolean("SendCrashReport", true))
        Thread.setDefaultUncaughtExceptionHandler(
                new AndiCarExceptionHandler(Thread.getDefaultUncaughtExceptionHandler(), this));

    try {//from w ww  . j  ava 2  s .  c om
        Bundle extras = intent.getExtras();
        if (extras == null || extras.getBoolean("setJustNextRun") || !extras.getBoolean("AutoUpdateCheck")) {
            setNextRun();
            stopSelf();
        }

        URL updateURL = new URL(StaticValues.VERSION_FILE_URL);
        URLConnection conn = updateURL.openConnection();
        if (conn == null)
            return;
        InputStream is = conn.getInputStream();
        if (is == null)
            return;
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        /* Convert the Bytes read to a String. */
        String s = new String(baf.toByteArray());
        /* Get current Version Number */
        int curVersion = getPackageManager().getPackageInfo("org.andicar.activity", 0).versionCode;
        int newVersion = Integer.valueOf(s);

        /* Is a higher version than the current already out? */
        if (newVersion > curVersion) {
            //get the whats new message
            updateURL = new URL(StaticValues.WHATS_NEW_FILE_URL);
            conn = updateURL.openConnection();
            if (conn == null)
                return;
            is = conn.getInputStream();
            if (is == null)
                return;
            bis = new BufferedInputStream(is);
            baf = new ByteArrayBuffer(50);
            current = 0;
            while ((current = bis.read()) != -1) {
                baf.append((byte) current);
            }

            /* Convert the Bytes read to a String. */
            s = new String(baf.toByteArray());

            mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notification = null;
            Intent i = new Intent(this, WhatsNewDialog.class);
            i.putExtra("UpdateMsg", s);
            PendingIntent contentIntent = PendingIntent.getActivity(UpdateCheckService.this, 0, i, 0);

            CharSequence title = getText(R.string.Notif_UpdateTitle);
            String message = getString(R.string.Notif_UpdateMsg);
            notification = new Notification(R.drawable.icon_sys_info, message, System.currentTimeMillis());
            notification.flags |= Notification.DEFAULT_LIGHTS;
            notification.flags |= Notification.DEFAULT_SOUND;
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.setLatestEventInfo(UpdateCheckService.this, title, message, contentIntent);
            mNM.notify(StaticValues.NOTIF_UPDATECHECK_ID, notification);
            setNextRun();
        }
        stopSelf();
    } catch (Exception e) {
        Log.i("UpdateService", "Service failed.");
        e.printStackTrace();
    }
}

From source file:com.manning.androidhacks.hack023.authenticator.AuthenticatorActivity.java

private void finishLogin() {
    final Account account = new Account(mUsername, PARAM_ACCOUNT_TYPE);

    if (mRequestNewAccount) {
        mAccountManager.addAccountExplicitly(account, mPassword, null);

        Bundle bundle = new Bundle();
        ContentResolver.addPeriodicSync(account, TodoContentProvider.AUTHORITY, bundle, 300);

    } else {//w  ww  . j av a 2 s  .  c o  m
        mAccountManager.setPassword(account, mPassword);
    }

    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, PARAM_ACCOUNT_TYPE);

    if (mAuthTokenType != null && mAuthTokenType.equals(PARAM_AUTHTOKEN_TYPE)) {
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthToken);
    }

    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}

From source file:most.voip.example.ws_config.MainActivity.java

private void buildParamsFromremoteIntent(Intent data) {
    Bundle b = data.getExtras();
    try {//from   w ww . j ava 2 s  .c  om
        this.accountData = new JSONObject(b.getString("account_data"));
        this.buddiesData = new JSONArray(b.getString("buddies_data"));
        this.updateAccountDetailsInfo();

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:info.semanticsoftware.semassist.android.activity.AuthenticationActivity.java

/** Sends an authentication request when the save button is pushed.
 * @param v view // ww w  . j av  a 2  s  .c o m
 */
public void onSaveClick(View v) {
    TextView tvUsername = (TextView) this.findViewById(R.id.uc_txt_username);
    TextView tvPassword = (TextView) this.findViewById(R.id.uc_txt_password);

    //Qualified username, i.e, user@semanticassistants.com
    String qUsername = tvUsername.getText().toString();
    String username = null;
    if (qUsername.indexOf("@") > 0) {
        username = qUsername.substring(0, qUsername.indexOf("@"));
    } else {
        username = qUsername;
    }
    String password = tvPassword.getText().toString();

    //TODO do client-side validation like password length etc.
    String response = authenicate(username, password);
    if (!response.equals(Constants.AUTHENTICATION_FAIL)) {
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        Editor editor = settings.edit();
        editor.putString("username", username);
        editor.putString("password", password);
        //FIXME replace this with a descent XML parser
        String acctype = "";
        int start = response.indexOf("<accType>");
        int end = response.indexOf("</accType>");
        if (start > -1 && end > -1) {
            acctype = response.substring(start + "<accType>".length(), end);
        }
        editor.putString("acctype", acctype);
        String sessionId = "";
        start = response.indexOf("<sessionId>");
        end = response.indexOf("</sessionId>");
        if (start > -1 && end > -1) {
            sessionId = response.substring(start + "<sessionId>".length(), end);
        }
        editor.putString("sessionId", sessionId);
        String reqNum = "";
        start = response.indexOf("<reqNum>");
        end = response.indexOf("</reqNum>");
        if (start > -1 && end > -1) {
            reqNum = response.substring(start + "<reqNum>".length(), end);
        }
        editor.putString("reqNum", reqNum);
        boolean result = editor.commit();
        if (result) {
            Toast.makeText(this, R.string.authenticationSuccess, Toast.LENGTH_LONG).show();
            String accountType = this.getIntent().getStringExtra("auth.token");
            if (accountType == null) {
                accountType = SemAssistAuthenticator.ACCOUNT_TYPE;
            }

            AccountManager accMgr = AccountManager.get(this);

            // Add the account to the Android Account Manager
            String accountName = username + "@semanticassistants.com";
            final Account account = new Account(accountName, accountType);
            accMgr.addAccountExplicitly(account, password, null);

            // Inform the caller (could be the Android Account Manager or the SA app) that the process was successful
            final Intent intent = new Intent();
            intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
            intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
            intent.putExtra(AccountManager.KEY_AUTHTOKEN, accountType);
            this.setAccountAuthenticatorResult(intent.getExtras());
            this.setResult(RESULT_OK, intent);
            this.finish();
        } else {
            Toast.makeText(this, "Could not write the preferences.", Toast.LENGTH_LONG).show();
        }
    } else {
        Toast.makeText(this, R.string.authenticationFail, Toast.LENGTH_LONG).show();
    }
}

From source file:com.parking.billing.ParkingPayment.java

/** Called when the activity is first created. */
@Override/*from w ww  . j  ava  2s .c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.parkingpayment);

    mHandler = new Handler();
    mParkingPurchaseObserver = new ParkingPurchaseObserver(mHandler);
    mBillingService = new BillingService();
    mBillingService.setContext(this);

    mPurchaseDatabase = new PurchaseDatabase(DashboardActivity.myContext);

    //Get on the spot selected 
    Intent starterIntent = getIntent();
    Bundle bundle = starterIntent.getExtras();

    TextView textAll = (TextView) findViewById(R.id.parkingAllDetailsTextView);

    /** Obtain time object **/
    String timeObj = bundle.getString("time");
    try {
        paidTime = Integer.parseInt(timeObj);
        Log.v(TAG, "Calculated time : " + paidTime);
    } catch (NumberFormatException nfe) {
        Log.v(TAG, "NumberFormatException: " + nfe.getMessage());
    }

    /** Create parkingLocationObj */
    String all = bundle.getString("info");
    parkingLocationObj = LocationUtility.convertStringToObject(all);

    /** Use the object to populate fields */
    String locAddress = "Address unavailable";
    Geocoder geoCoder = new Geocoder(DashboardActivity.myContext, Locale.getDefault());
    GeoPoint gp = new GeoPoint((int) (parkingLocationObj.getLatitude() * 1E6),
            (int) (parkingLocationObj.getLongitude() * 1E6));
    locAddress = LocationUtility.ConvertPointToLocation(gp, geoCoder);
    Log.v(TAG, "Setting address to: " + locAddress);
    parkingLocationObj.setAddress(locAddress);

    String typeToDisplay = parkingLocationObj.getType() == null ? "Not known"
            : "" + parkingLocationObj.getType();

    textAll.setText("\n" + "Address: " + parkingLocationObj.getAddress() + "\n" + "Type:" + typeToDisplay + "\n"
            + "MeterId: " + parkingLocationObj.getMeterID() + "\n"
            + "Number of Parking Spots at this location: " + parkingLocationObj.getQuantity() + "\n");

    setupWidgets();

    // Check if billing is supported.
    ResponseHandler.register(mParkingPurchaseObserver);
    if (!mBillingService.checkBillingSupported()) {
        showDialog(DIALOG_CANNOT_CONNECT_ID);
    }
}

From source file:org.deviceconnect.message.intent.impl.io.IntentHttpMessageWriter.java

@Override
public void write(final HttpMessage message) throws IOException, HttpException {
    mLogger.entering(getClass().getName(), "write");

    DConnectMessage dmessage = HttpMessageFactory.getMessageFactory().newDConnectMessage(message);
    Intent intent = IntentMessageFactory.getMessageFactory().newPackagedMessage(dmessage);

    // put intent optional extras
    Header host = message.getFirstHeader(HttpHeaders.HOST);
    if (host != null) {
        intent.setComponent(ComponentName.unflattenFromString(host.getValue()));
    }/* w  w w  .  java 2s.  c o m*/
    intent.putExtra(DConnectMessage.EXTRA_RECEIVER, new ComponentName(mContext, IntentResponseReceiver.class));

    // send broadcast
    mLogger.fine("send request broadcast: " + intent);
    mLogger.fine("send request extra: " + intent.getExtras());
    mContext.sendBroadcast(intent);

    mLogger.exiting(getClass().getName(), "write");
}

From source file:cm.aptoide.pt.ManageRepo.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        Bundle b = data.getExtras();
        String a = b.getString("URI");
        db.addServer(a);/* w  w  w.  j a  v a2 s  . c  o  m*/
        change = true;
        redraw();
    }
}

From source file:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java

private void finishLogin(String authToken) {
    Log.i(TAG, "finishLogin()");

    final Account account = new Account(nickname, mdConstants.ACCOUNT_TYPE);
    if (request_new_account) {
        account_manager.addAccountExplicitly(account, authToken, null);
        account_manager.setUserData(account, "hostname", hostname);
        account_manager.setUserData(account, "username", username);

        // Set system info sync for this account.
        final Bundle extras = new Bundle();
        ContentResolver.setSyncAutomatically(account, mdContentProvider.AUTHORITY, true);
        if (android.os.Build.VERSION.SDK_INT >= 8) {
            ContentResolver.addPeriodicSync(account, mdContentProvider.AUTHORITY, extras, 10);
        }//from  www  .ja  v  a  2  s  . com
    } else
        account_manager.setPassword(account, authToken);

    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, nickname);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, mdConstants.ACCOUNT_TYPE);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);

    ContentResolver.requestSync(account, mdContentProvider.AUTHORITY, new Bundle());

    finish();
}

From source file:com.chexiaoya.gaodemapdemo.SpeechSearchActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_UI) {
        if (resultCode == RESULT_OK) {
            onResults(data.getExtras());
        }/*from   ww w  .  j ava 2s . c  o m*/

    }
}