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:com.cloudbees.gasp.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    // When an intent is received by this Service, this method
    // is called on a new thread.

    Uri action = intent.getData();//from   w w  w. ja  v a  2 s . c o m
    Bundle extras = intent.getExtras();

    if (extras == null || action == null || !extras.containsKey(EXTRA_RESULT_RECEIVER)) {
        // Extras contain our ResultReceiver and data is our REST action.  
        // So, without these components we can't do anything useful.
        Log.e(TAG, "You did not pass extras or data with the Intent.");

        return;
    }

    // We default to GET if no verb was specified.
    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    ResultReceiver receiver = extras.getParcelable(EXTRA_RESULT_RECEIVER);

    try {
        // Here we define our base request object which we will
        // send to our REST service via HttpClient.
        HttpRequestBase request = null;

        // Let's build our request based on the HTTP verb we were
        // given.
        switch (verb) {
        case GET: {
            request = new HttpGet();
            attachUriWithQuery(request, action, params);
        }
            break;

        case DELETE: {
            request = new HttpDelete();
            attachUriWithQuery(request, action, params);
        }
            break;

        case POST: {
            request = new HttpPost();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary. Note: some REST APIs
            // require you to POST JSON. This is easy to do, simply use
            // postRequest.setHeader('Content-Type', 'application/json')
            // and StringEntity instead. Same thing for the PUT case 
            // below.
            HttpPost postRequest = (HttpPost) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                postRequest.setEntity(formEntity);
            }
        }
            break;

        case PUT: {
            request = new HttpPut();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary.
            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        if (request != null) {
            HttpClient client = new DefaultHttpClient();

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Log.d(TAG, "Executing request: " + verbToString(verb) + ": " + action.toString());

            // Finally, we send our request using HTTP. This is the synchronous
            // long operation that we need to run on this thread.
            HttpResponse response = client.execute(request);

            HttpEntity responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            // Our ResultReceiver allows us to communicate back the results to the caller. This
            // class has a method named send() that can send back a code and a Bundle
            // of data. ResultReceiver and IntentService abstract away all the IPC code
            // we would need to write to normally make this work.
            if (responseEntity != null) {
                Bundle resultData = new Bundle();
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                receiver.send(statusCode, resultData);
            } else {
                receiver.send(statusCode, null);
            }
        }
    } catch (URISyntaxException e) {
        Log.e(TAG, "URI syntax was incorrect. " + verbToString(verb) + ": " + action.toString(), e);
        receiver.send(0, null);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "A UrlEncodedFormEntity was created with an unsupported encoding.", e);
        receiver.send(0, null);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "There was a problem when sending the request.", e);
        receiver.send(0, null);
    } catch (IOException e) {
        Log.e(TAG, "There was a problem when sending the request.", e);
        receiver.send(0, null);
    }
}

From source file:com.qubittech.feelknit.app.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();//ww w .  j a va2s  .  com
        return;
    }
    int switchNum = 0;
    Intent intent = getIntent();
    //boolean isRegister = false;
    intentBundle = intent.getExtras();
    Feeling feeling = null;
    String feelingId = null;
    if (intentBundle != null) {
        switchNum = intentBundle.getInt("From");
        feeling = (Feeling) intentBundle.get("feeling");
        feelingId = (String) intentBundle.get("feelingId");
    }
    //  isRegister = bundle == null ? false : bundle.getBoolean("IsFromRegister");

    ImageView userIconImageView = (ImageView) findViewById(R.id.leftDrawerUserIcon);
    if (ApplicationHelper.getAvatar(getApplicationContext()) != null)
        ImageHelper.setBitMap(userIconImageView, getApplicationContext(),
                ApplicationHelper.getAvatar(getApplicationContext()), 100, 100);

    TextView usrTextView = (TextView) findViewById(com.qubittech.feelknit.app.R.id.usrName);
    usrTextView.setText(ApplicationHelper.getUserName(getApplicationContext()));
    Button btnSignout = (Button) findViewById(com.qubittech.feelknit.app.R.id.signout);

    btnSignout.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String username = ApplicationHelper.getUserName(getApplicationContext());
            ApplicationHelper.setUserName(getApplicationContext(), "");
            ApplicationHelper.setAvatar(getApplicationContext(), "");

            ApplicationHelper.setUserEmail(getApplicationContext(), "");
            App.close();
            startActivity(new Intent(MainActivity.this, LoginActivity.class));
            new ClearUserGcmKeyTask().execute(username);
        }
    });

    switch (switchNum) {
    case 0:
        ShowCurrentFeelingsFragment();
        break;
    //Registration
    case 1:
        getSupportFragmentManager().beginTransaction()
                .replace(com.qubittech.feelknit.app.R.id.content_frame, new AddFeelingFragment(), "Add Feeling")
                .addToBackStack("Add Feeling").commit();
        break;
    case 2:
        getSupportFragmentManager().beginTransaction()
                .replace(com.qubittech.feelknit.app.R.id.content_frame, new ForgotFragment(), "Forgot Password")
                .commit();
        break;
    case 3:
        ShowCommentsFragment(feeling, feelingId, null, null);
        break;
    case 4:
        String avatar = intentBundle.getString("Avatar", "");
        ShowProfileFragment(avatar);
        break;
    case 5:
        ShowRelatedFeelingFragment();
        break;
    default:
        break;
    }
}

From source file:com.marcosedo.lagramola.MainActivity.java

@Override
//si cuando se lanza el intent la app estaba abierta se viene aqui porque hemos puesto FLAG_ACTIVITY_SINGLE_TOP
protected void onNewIntent(Intent intent) {
    Log.i(TAG, "onNewIntent");

    Bundle extras = intent.getExtras();
    if (extras != null) {
        String msg = extras.getString("msg");
        String idevent = extras.getString("idevento");
        String titulo = extras.getString("titulo");

        if (idevent != null) {//if the message has an event id then
            if ((msg != null) && (titulo != null)) {//show Dialog with a message
                showDialogMsgArrived(titulo, msg);
            }//from   ww w . j a  v a 2s.  co m
            openViewDetail(idevent);
        }
    }

    super.onNewIntent(intent);
}

From source file:edu.mines.letschat.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.v(TAG, "In on new intent");
    Bundle extras = intent.getExtras();
    if (extras != null) {
        string = extras.getString(EXTRA_NOTIFICATION_RETRIEVE);
        if (string != null) {
            //            users.clear();
            //            new GetUsers(new OnTaskCompleted() {
            //               @Override
            //               public void onTaskCompleted() {
            Intent tent = new Intent(MainActivity.this, MessageActivity.class);
            tent.putExtra(MainActivity.EXTRA_DEVICE_ID, string);
            tent.putExtra(MainActivity.EXTRA_SENDER_ID, regid);
            for (Entry<String, String> entry : map.entrySet()) {
                if (string.equals(entry.getValue())) {
                    String username = entry.getKey();
                    Log.v(TAG, username);
                    tent.putExtra(MainActivity.EXTRA_USER_NAME, username);
                }//  w w  w .j a v a  2 s.  co  m
            }
            startActivity(tent);
            //               }
            //            }).execute();
        }
    }
}

From source file:edu.cloud.iot.reception.ocr.FaceRecognitionActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0) {
        Bitmap img = (Bitmap) data.getExtras().get("data");
        imageResult.setImageBitmap(img);
    }/*from   w  w w  . ja va 2  s .  c  o  m*/
    if (requestCode == SET_COMPARE_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        Bitmap compImg = BitmapFactory.decodeFile(picturePath);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        compImg.compress(Bitmap.CompressFormat.JPEG, 100, bos);
        compareImageBytes = bos.toByteArray();

        // ImageView imageView = (ImageView) findViewById(R.id.imgView);
        // imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
    }
}

From source file:eu.thecoder4.gpl.pleftdroid.PleftDroidActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && data != null) {
        super.onActivityResult(requestCode, resultCode, data);
        Bundle extras = data.getExtras();
        switch (requestCode) {
        case ACT_CREATE:
            int SC = extras.getInt(SC_CREATE, 500);
            switch (SC) {
            case HttpStatus.SC_OK:
                new AlertDialog.Builder(this).setTitle(R.string.dialog_title_apptcreated)
                        .setMessage(R.string.dialog_msg_apptcreated)
                        .setPositiveButton("OK", new OnClickListener() {
                            public void onClick(DialogInterface arg0, int arg1) {

                            }//  w  ww  . j av  a  2 s  . c o m
                        }).show();
                //Toast.makeText(this, R.string.toast_apptcreated, Toast.LENGTH_SHORT).show();
                break;
            case PleftBroker.SC_CLIREDIR:
                Toast.makeText(this, R.string.toast_createapptfailredir, Toast.LENGTH_SHORT).show();
                break;
            default:
                Toast.makeText(this, R.string.toast_createapptfail, Toast.LENGTH_LONG).show();
            }

            break;
        }
    }
}

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

private void finishConfirmCredentials(boolean result, String authToken) {
    Log.i(TAG, "finishConfirmCredentials()");
    final Account account = new Account(nickname, mdConstants.ACCOUNT_TYPE);

    if (result)//www . ja v  a  2s. c o  m
        account_manager.setPassword(account, authToken);

    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT, result);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}

From source file:com.allmycode.flags.MyActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from ww  w .  j  a v  a 2 s.c om
    targetActivity = (AutoCompleteTextView) findViewById(R.id.editText1);
    ArrayAdapter<String> targetsAdapter = new ArrayAdapter<String>(this, R.layout.list_item, TARGETS_LIST);
    targetActivity.setAdapter(targetsAdapter);
    flags = (AutoCompleteTextView) findViewById(R.id.editText2);
    ArrayAdapter<String> flagsAdapter = new ArrayAdapter<String>(this, R.layout.list_item, FLAGS_LIST_CONCISE);
    flags.setAdapter(flagsAdapter);
    cheatSheet = (EditText) findViewById(R.id.editText3);
    for (String item : FLAGS_LIST) {
        cheatSheet.append(item);
        cheatSheet.append("\n");
    }
    Intent whoCalled = getIntent();
    helloView = ((TextView) findViewById(R.id.textView3));
    helloView.setTextColor(android.graphics.Color.WHITE);
    helloView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    helloView.setText("Flags: 0x" + Integer.toHexString(whoCalled.getFlags()));
    if (whoCalled.getExtras() != null) {
        boolean areErrors = whoCalled.getExtras().getBoolean("existErrors", false);
        if (areErrors) {
            helloView.append(" There were errors!");
            helloView.setTextColor(android.graphics.Color.RED);
            helloView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
        }
    }

    ActivityManager am = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processes;
    processes = am.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo info : processes) {
        Log.i("Process:", info.processName);
    }
}

From source file:com.rukman.emde.smsgroups.authenticator.GMSAuthenticatorActivity.java

/**
 * Called when response is received from the server for confirm credentials
 * request. See onAuthenticationResult(). Sets the
 * AccountAuthenticatorResult which is sent back to the caller.
 *
 * @param result the confirmCredentials result.
 *//*from w w w . j a va 2 s.  c  o m*/
private void finishConfirmCredentials(boolean result) {
    Log.i(TAG, "finishConfirmCredentials()");
    final Account account = new Account(mUsername, GMSApplication.ACCOUNT_TYPE);
    mAccountManager.setPassword(account, mPassword);
    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT, result);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    intent = handleMessageIntent(intent, extras);
    MFPPushBroadcastReceiver.completeWakefulIntent(intent);
}