Example usage for android.content Intent getStringExtra

List of usage examples for android.content Intent getStringExtra

Introduction

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

Prototype

public String getStringExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:edu.cmu.plugins.PhoneListener.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * //from   w w  w .  ja  v  a 2 s  . co  m
 * @param ctx The context of the main Activity.
 */
public void setContext(PhonegapActivity ctx) {
    super.setContext(ctx);
    this.phoneListenerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");

    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent == null) {
                    return;
                }
                String state = "";
                if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
                    state = "SMS_RECEIVED";
                    Log.i(LOG_TAG, state);
                }
                if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;

                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                }
                updatePhoneState(state, true);
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        ctx.registerReceiver(this.receiver, intentFilter);
    }
}

From source file:com.daon.identityx.uaf.UafClientUtils.java

/**
 * {@inheritDoc}/*ww  w.  j a  va 2 s. com*/
 */
@Override
public String getUafClientResponse(FidoOperation fidoOpType, Intent resultIntent) {
    // Check response intent from UAF client for errors. If it's OK send the response message created by the client to the server.
    Log.d(LogUtils.TAG, "processClientResultIntent called.");
    UafClientLogUtils.logClientResultIntent(resultIntent, fidoOpType);
    short errorCode = resultIntent.getShortExtra("errorCode", (short) -1);
    if (errorCode != ErrorCode.NO_ERROR.getValue()) {
        throw new UafProcessingException(
                "FIDO Client Processing Error: " + ErrorCode.getByValue(errorCode).getDescription());
    } else {
        String intentType = resultIntent.getStringExtra("UAFIntentType");
        if (intentType != null) {
            switch (intentType) {
            case "UAF_OPERATION_RESULT":
                String fidoUafMessage = resultIntent.getStringExtra("message");
                if (fidoUafMessage != null) {
                    Gson gson = new Gson();
                    //UAFMessage uafMessage = gson.fromJson(fidoUafMessage, UAFMessage.class);
                    //String uafResponseJson = uafMessage.getUafProtocolMessage();
                    //return uafMessage.getUafProtocolMessage();
                    return fidoUafMessage;
                } else {
                    return null;
                }
            case "DISCOVER_RESULT":
                return resultIntent.getStringExtra("discoveryData");
            case "CHECK_POLICY_RESULT":
                Log.d(LogUtils.TAG, "checking policy result.");
                return null;
            default:
                throw new UafProcessingException("Unrecognised UAF client response intent type: " + intentType);
            }
        } else {
            throw new UafProcessingException("UAF client response intent is missing the UAFIntentType extra.");
        }
    }
}

From source file:com.scigames.slidegame.ReviewActivity.java

/** Called with the activity is first created. */
@Override//from  ww  w  . j av a  2  s  .  c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    Log.d(TAG, "super.OnCreate");
    Intent i = getIntent();
    Log.d(TAG, "getIntent");
    rfidIn = i.getStringExtra("rfid");
    //       photoUrl = i.getStringExtra("photo");
    //       photoUrl = "http://mysweetwebsite.com/" + photoUrl;
    Log.d(TAG, "...getStringExtra");
    // Inflate our UI from its XML layout description.
    setContentView(R.layout.review_page);
    mAnimationView = (ReviewAnimationView) findViewById(R.id.review);
    mAnimationThread = mAnimationView.getThread();

    //load fonts
    ExistenceLightOtf = Typeface.createFromAsset(getAssets(), "fonts/Existence-Light.ttf");
    Museo300Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo300-Regular.otf");
    Museo500Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo500-Regular.otf");
    Museo700Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo700-Regular.otf");

    Log.d(TAG, "...setContentView");
    resultImgNum = 0;
    scoreImgNum = 0;

    //resultImg[0] = "http://mysweetwebsite.com/narrative_images/Level0/results/_0012_Layer-Comp-13.png";
    //resultImg[1] = "http://mysweetwebsite.com/narrative_images/Level0/results/_0012_Layer-Comp-13.png";

    alertDialog = new AlertDialog.Builder(ReviewActivity.this).create();
    alertDialog.setTitle("alert title");
    alertDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
            finish();
        }
    });

    infoDialog = new AlertDialog.Builder(ReviewActivity.this).create();
    infoDialog.setTitle("Debug Info");
    infoDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            //Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
        }
    });

    needSlideDataDialog = new AlertDialog.Builder(ReviewActivity.this).create();
    needSlideDataDialog.setTitle("Debug Info");
    needSlideDataDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            //Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
            Intent i = new Intent(ReviewActivity.this, LoginActivity.class);
            Log.d(TAG, "new LoginActivity Intent");
            i.putExtra("page", "login");
            Log.d(TAG, "startActivity...");
            ReviewActivity.this.startActivity(i);
            Log.d(TAG, "...startActivity");
        }
    });

    //display name and profile info
    Resources res = getResources();
    title = (TextView) findViewById(R.id.title);
    mLevel = (TextView) findViewById(R.id.level);
    mScore = (TextView) findViewById(R.id.score);
    //mScoreFinal = (TextView)findViewById(R.id.score_final);
    mFabric = (TextView) findViewById(R.id.fabric);
    mAttempt = (TextView) findViewById(R.id.attempt);
    //set their font
    setTextViewFont(Museo700Regular, title);
    setTextViewFont(Museo500Regular, mLevel, mScore, mFabric);
    //make them invisible to start
    title.setVisibility(View.INVISIBLE);
    mLevel.setVisibility(View.INVISIBLE);
    mScore.setVisibility(View.INVISIBLE);
    //mScoreFinal.setVisibility(View.INVISIBLE);
    mFabric.setVisibility(View.INVISIBLE);
    mAttempt.setVisibility(View.INVISIBLE);
    Log.d(TAG, "...Profile Info");

    reviewBtnNext = (Button) findViewById(R.id.btn_next);
    reviewBtnNext.setOnClickListener(mNext);
    reviewBtnNext.setVisibility(View.INVISIBLE);
    reviewBtnBack = (Button) findViewById(R.id.btn_back);
    reviewBtnBack.setOnClickListener(mBack);
    reviewBtnBack.setVisibility(View.INVISIBLE);
    btnContinue = (Button) findViewById(R.id.btn_continue);
    btnContinue.setOnClickListener(mContinue);

    if (isNetworkAvailable()) {
        task.cancel(true);
        //create a new async task for every time you hit login (each can only run once ever)
        task = new SciGamesHttpPoster(ReviewActivity.this, "http://mysweetwebsite.com/pull/slide_results.php");
        //set listener
        task.setOnResultsListener(ReviewActivity.this);
        //prepare key value pairs to send
        String[] keyVals = { "rfid", rfidIn };
        //create AsyncTask, then execute
        AsyncTask<String, Void, JSONObject> serverResponse = null;
        serverResponse = task.execute(keyVals);
    } else {
        alertDialog.setMessage(
                "You're not connected to the internet. Make sure this tablet is logged into a working Wifi Network.");
        alertDialog.show();
    }
}

From source file:com.ledger.android.u2f.bridge.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w  ww .  j a  v  a2 s.  com
    mCancelButton = (Button) findViewById(R.id.cancel_button);
    mCancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mAuthThread != null) {
                mAuthThread.markStopped();
            }
            finish();
        }
    });

    TypefaceHelper.applyFonts((ViewGroup) getWindow().getDecorView());

    Intent intent = getIntent();

    if (!intent.getAction().equals(ACTION_GOOGLE) && !intent.getAction().equals(ACTION_LEDGER)) {
        Toast.makeText(MainActivity.this, R.string.unsupported_intent, Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    String request = intent.getStringExtra(TAG_REQUEST);
    if (request == null) {
        Log.e(TAG, "Request missing");
        finish();
        return;
    }

    mU2FContext = parseU2FContext(request);
    if (mU2FContext == null) {
        finish();
        return;
    }

    if (mAuthThread != null) {
        mAuthThread.markStopped();
    }
    mAuthThread = new U2FAuthRunner(mU2FContext);
    mAuthThread.start();
}

From source file:com.scigames.slidereview.ReviewActivity.java

/** Called with the activity is first created. */
@Override/*from  w  w  w.  j  ava 2  s .c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    Log.d(TAG, "super.OnCreate");
    Intent i = getIntent();
    Log.d(TAG, "getIntent");
    rfidIn = i.getStringExtra("rfid");
    //       photoUrl = i.getStringExtra("photo");
    //       photoUrl = "http://mysweetwebsite.com/" + photoUrl;
    Log.d(TAG, "...getStringExtra");
    // Inflate our UI from its XML layout description.
    setContentView(R.layout.review_page);
    mAnimationView = (ReviewAnimationView) findViewById(R.id.review);
    mAnimationThread = mAnimationView.getThread();

    //load fonts
    ExistenceLightOtf = Typeface.createFromAsset(getAssets(), "fonts/Existence-Light.ttf");
    Museo300Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo300-Regular.otf");
    Museo500Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo500-Regular.otf");
    Museo700Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo700-Regular.otf");

    Log.d(TAG, "...setContentView");
    resultImgNum = 0;
    scoreImgNum = 0;

    //resultImg[0] = "http://mysweetwebsite.com/narrative_images/Level0/results/_0012_Layer-Comp-13.png";
    //resultImg[1] = "http://mysweetwebsite.com/narrative_images/Level0/results/_0012_Layer-Comp-13.png";

    alertDialog = new AlertDialog.Builder(ReviewActivity.this).create();
    alertDialog.setTitle("alert title");
    alertDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
            finish();
        }
    });

    infoDialog = new AlertDialog.Builder(ReviewActivity.this).create();
    infoDialog.setTitle("Debug Info");
    infoDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            //Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
        }
    });

    needSlideDataDialog = new AlertDialog.Builder(ReviewActivity.this).create();
    needSlideDataDialog.setTitle("Debug Info");
    needSlideDataDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            //Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
            Intent i = new Intent(ReviewActivity.this, LoginActivity.class);
            Log.d(TAG, "new LoginActivity Intent");
            i.putExtra("page", "login");
            Log.d(TAG, "startActivity...");
            ReviewActivity.this.startActivity(i);
            Log.d(TAG, "...startActivity");
        }
    });

    //display name and profile info
    Resources res = getResources();
    title = (TextView) findViewById(R.id.title);
    mLevel = (TextView) findViewById(R.id.level);
    mScore = (TextView) findViewById(R.id.score);
    //mScoreFinal = (TextView)findViewById(R.id.score_final);
    mFabric = (TextView) findViewById(R.id.fabric);
    mAttempt = (TextView) findViewById(R.id.attempt);
    //set their font
    setTextViewFont(Museo700Regular, title);
    setTextViewFont(Museo500Regular, mLevel, mScore, mFabric);
    //make them invisible to start
    title.setVisibility(View.INVISIBLE);
    mLevel.setVisibility(View.INVISIBLE);
    mScore.setVisibility(View.INVISIBLE);
    //mScoreFinal.setVisibility(View.INVISIBLE);
    mFabric.setVisibility(View.INVISIBLE);
    mAttempt.setVisibility(View.INVISIBLE);
    Log.d(TAG, "...Profile Info");

    reviewBtnNext = (Button) findViewById(R.id.btn_next);
    reviewBtnNext.setOnClickListener(mNext);
    reviewBtnNext.setVisibility(View.INVISIBLE);
    reviewBtnBack = (Button) findViewById(R.id.btn_back);
    reviewBtnBack.setOnClickListener(mBack);
    reviewBtnBack.setVisibility(View.INVISIBLE);
    btnContinue = (Button) findViewById(R.id.btn_continue);
    btnContinue.setOnClickListener(mContinue);

    if (isNetworkAvailable()) {
        task.cancel(true);
        //create a new async task for every time you hit login (each can only run once ever)
        task = new SciGamesHttpPoster(ReviewActivity.this, "http://db.scigam.es/pull/slide_results.php");
        //set listener
        task.setOnResultsListener(ReviewActivity.this);
        //prepare key value pairs to send
        String[] keyVals = { "rfid", rfidIn };
        //create AsyncTask, then execute
        AsyncTask<String, Void, JSONObject> serverResponse = null;
        serverResponse = task.execute(keyVals);
    } else {
        alertDialog.setMessage(
                "You're not connected to the internet. Make sure this tablet is logged into a working Wifi Network.");
        alertDialog.show();
    }
}

From source file:com.commonsware.android.EMusicDownloader.SingleBook.java

/** Called when the activity is first created. */
@Override//from ww  w.ja  va2s .  c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.singlebook);

    Intent myIntent = getIntent();
    albumId = myIntent.getStringExtra("keyalbumid");
    emusicURL = myIntent.getStringExtra("keyexturl");
    album = myIntent.getStringExtra("keyalbum");
    artist = myIntent.getStringExtra("keyartist");

    thisActivity = this;

    nameTextView = (TextView) findViewById(R.id.tname);
    authorTextView = (TextView) findViewById(R.id.tauthor);
    editionTextView = (TextView) findViewById(R.id.tedition);
    genreTextView = (TextView) findViewById(R.id.tgenre);
    bioBlurb = (WebView) findViewById(R.id.blurb);
    ratingBar = (RatingBar) findViewById(R.id.rbar);
    albumArt = (ImageView) findViewById(R.id.albumart);
    authorLayout = (LinearLayout) findViewById(R.id.llauthor);

    version = android.os.Build.VERSION.SDK_INT;

    Resources res = getResources();

    if (version < 11) {
        authorLayout.setBackgroundDrawable(res.getDrawable(android.R.drawable.list_selector_background));
    } else {
        authorLayout.setBackgroundResource(R.drawable.list_selector_holo_dark);
    }

    authorLayout.setFocusable(true);

    bioBlurb.setBackgroundColor(0);

    urlAddress = "http://api.emusic.com/book/info?" + Secrets.apikey + "&bookId=" + albumId
            + "&include=bookEditorial,bookRating&&imageSize=small";
    Log.d("EMD - ", urlAddress);

    getInfoFromXML();
}

From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_details);
    mActivity = this;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mDialog = new ProgressDialog(mActivity);
    mDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mDialog.setIndeterminate(true);/*from ww  w . ja  va2 s.  c om*/
    mDialog.show();
    mButtonAvailability = (Button) findViewById(R.id.id_btn_avail_next_7);
    if (savedInstanceState != null) {
        mDetails = savedInstanceState.getParcelable("LIST");
        if (mDetails == null) {
            return;
        }
        mFrameLayout = null;
        mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_details);
        if (mDetails.getAction().equals(TrainEnquiry.FARE)) {
            getSupportActionBar().setTitle("Fare Details");
            mButtonAvailability.setVisibility(View.GONE);
            createTableLayoutTrainFare();
        }
        if (mDetails.getAction().equals(TrainEnquiry.AVAILABILITY)) {
            getSupportActionBar().setTitle("Availability Details");
            mButtonAvailability.setVisibility(View.VISIBLE);
            mButtonAvailability.setOnClickListener(this);
            createTableLayoutTrainAvailability();
        }
        return;
    }
    mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_details);
    Intent intent = getIntent();
    mAction = intent.getStringExtra(TrainEnquiry.ACTION);
    if (mAction.equals(TrainEnquiry.FARE)) {
        getSupportActionBar().setTitle("Fare Details");
        mButtonAvailability.setVisibility(View.GONE);
        mTrainNumber = intent.getStringExtra(TrainEnquiry.TRAIN);
        mSrc = intent.getStringExtra(TrainEnquiry.SRC);
        mDst = intent.getStringExtra(TrainEnquiry.DST);
        mDay = intent.getStringExtra(TrainEnquiry.DAY_TRAVEL);
        mMonth = intent.getStringExtra(TrainEnquiry.MONTH_TRAVEL);
        mCls = intent.getStringExtra(TrainEnquiry.CLS);
        mAge = intent.getStringExtra(TrainEnquiry.AGE);
        new GetFare().execute();
        mDialog.setMessage("Fetching train fare . . .");
    }
    if (mAction.equals(TrainEnquiry.AVAILABILITY)) {
        getSupportActionBar().setTitle("Availability Details");
        mButtonAvailability.setVisibility(View.VISIBLE);
        mButtonAvailability.setOnClickListener(this);
        mTrainNumber = intent.getStringExtra(TrainEnquiry.TRAIN);
        mSrc = intent.getStringExtra(TrainEnquiry.SRC);
        mDst = intent.getStringExtra(TrainEnquiry.DST);
        mDay = intent.getStringExtra(TrainEnquiry.DAY_TRAVEL);
        mMonth = intent.getStringExtra(TrainEnquiry.MONTH_TRAVEL);
        mCls = intent.getStringExtra(TrainEnquiry.CLS);
        new GetAvail().execute();
        mDialog.setMessage("Fetching train availability . . .");
    }
}

From source file:dk.ciid.android.infobooth.activities.IntroductionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    /* Variables received through Intent */
    Intent openActivity = getIntent(); // this is just for example purpose
    isInDebugMode = openActivity.getBooleanExtra("isInDebugMode", true); // should the app send a welcome sms after subscribing?
    voice1 = openActivity.getStringExtra("voice1"); // path to voice file 1
    voice2 = openActivity.getStringExtra("voice2"); // path to voice file 2
    voice3 = openActivity.getStringExtra("voice3"); // path to voice file 3
    voice4 = openActivity.getStringExtra("voice4"); // path to voice file 4
    voice5 = openActivity.getStringExtra("voice5"); // path to voice file 5   
    voice6 = openActivity.getStringExtra("voice6"); // path to voice file 6
    /* Variables received through Intent */

    super.onCreate(savedInstanceState);

    /* ARDUINO COMMUNICATION STUFF ********************************************/
    // a reference to the USB system service is obtained so that you can call its methods later on
    mUsbManager = UsbManager.getInstance(this);
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, filter);

    if (getLastNonConfigurationInstance() != null) {
        mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
        openAccessory(mAccessory);//from w ww.  jav a  2s  . c o  m
    }
    /* ARDUINO COMMUNICATION STUFF ********************************************/

    gestureScanner = new GestureDetector(this);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_introduction);

    // Set up sound playback
    initMediaPlayer();

    runOnUiThread(new Runnable() {
        public void run() {
            if (isInDebugMode)
                Toast.makeText(getApplicationContext(), "Debug mode is ON", Toast.LENGTH_SHORT).show();
        }
    });

}

From source file:bolts.AppLinkTest.java

public void testGeneralMeasurementEventsBroadcast() throws Exception {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    i.putExtra("foo", "bar");
    ArrayList<String> arr = new ArrayList<>();
    arr.add("foo2");
    arr.add("bar2");
    i.putExtra("foobar", arr);
    Map<String, String> other = new HashMap<>();
    other.put("yetAnotherFoo", "yetAnotherBar");

    final CountDownLatch lock = new CountDownLatch(1);
    final String[] receivedStrings = new String[5];
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext());
    manager.registerReceiver(new BroadcastReceiver() {
        @Override/*w w  w  .j  ava2 s. c o  m*/
        public void onReceive(Context context, Intent intent) {
            String eventName = intent.getStringExtra("event_name");
            Bundle eventArgs = intent.getBundleExtra("event_args");
            receivedStrings[0] = eventName;
            receivedStrings[1] = eventArgs.getString("foo");
            receivedStrings[2] = eventArgs.getString("foobar");
            receivedStrings[3] = eventArgs.getString("yetAnotherFoo");
            receivedStrings[4] = eventArgs.getString("intentData");
            lock.countDown();
        }
    }, new IntentFilter("com.parse.bolts.measurement_event"));

    MeasurementEvent.sendBroadcastEvent(getInstrumentation().getTargetContext(), "myEventName", i, other);
    lock.await(2000, TimeUnit.MILLISECONDS);

    assertEquals("myEventName", receivedStrings[0]);
    assertEquals("bar", receivedStrings[1]);
    assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]);
    assertEquals("yetAnotherBar", receivedStrings[3]);
    assertEquals("http://www.example.com", receivedStrings[4]);
}

From source file:com.twitterdev.rdio.app.RdioApp.java

/*************************
 * Activity overrides// w  ww.  j av a2  s  .  c  o m
 *************************/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
            Log.v(TAG, "Login success");
            if (data != null) {
                accessToken = data.getStringExtra("token");
                accessTokenSecret = data.getStringExtra("tokenSecret");
                onRdioAuthorised(accessToken, accessTokenSecret);
                rdio.setTokenAndSecret(accessToken, accessTokenSecret);
            }
        } else if (resultCode == RESULT_CANCELED) {
            if (data != null) {
                String errorCode = data.getStringExtra(OAuth1WebViewActivity.EXTRA_ERROR_CODE);
                String errorDescription = data.getStringExtra(OAuth1WebViewActivity.EXTRA_ERROR_DESCRIPTION);
                Log.v(TAG, "ERROR: " + errorCode + " - " + errorDescription);
            }
            accessToken = null;
            accessTokenSecret = null;
        }
        rdio.prepareForPlayback();
    }
}