Example usage for android.content Intent setData

List of usage examples for android.content Intent setData

Introduction

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

Prototype

public @NonNull Intent setData(@Nullable Uri data) 

Source Link

Document

Set the data this intent is operating on.

Usage

From source file:com.andrewshu.android.reddit.profile.ProfileActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    Intent i;

    switch (item.getItemId()) {
    case Constants.DIALOG_COMMENT_CLICK:
        i = new Intent(getApplicationContext(), CommentsListActivity.class);
        i.setData(Util.createCommentUri(mVoteTargetThingInfo, 0));
        i.putExtra(Constants.EXTRA_SUBREDDIT, mVoteTargetThingInfo.getSubreddit());
        i.putExtra(Constants.EXTRA_TITLE, mVoteTargetThingInfo.getTitle());
        startActivity(i);/*from   w  w  w  .  j av a  2  s . com*/
        return true;
    case Constants.DIALOG_THREAD_CLICK:
        // Launch an Intent for CommentsListActivity
        CacheInfo.invalidateCachedThread(getApplicationContext());
        i = new Intent(getApplicationContext(), CommentsListActivity.class);
        i.setData(Util.createThreadUri(mVoteTargetThingInfo));
        i.putExtra(Constants.EXTRA_SUBREDDIT, mVoteTargetThingInfo.getSubreddit());
        i.putExtra(Constants.EXTRA_TITLE, mVoteTargetThingInfo.getTitle());
        i.putExtra(Constants.EXTRA_NUM_COMMENTS, Integer.valueOf(mVoteTargetThingInfo.getNum_comments()));
        startActivity(i);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.money.manager.ex.home.HomeFragment.java

@Subscribe
public void onEvent(AmountEnteredEvent event) {
    QueryAccountBills account = this.getAccountBeingBalanced();
    Money currentBalance = MoneyFactory.fromDouble(account.getTotal());

    // calculate the diff.
    Money newBalance = event.amount;//from   w w  w . j  a  v a  2s.c o m
    if (newBalance.compareTo(currentBalance) == 0)
        return;

    Money difference;
    TransactionTypes transactionType;

    if (newBalance.compareTo(currentBalance) > 0) {
        // new balance > current balance
        difference = newBalance.subtract(currentBalance);
        transactionType = TransactionTypes.Deposit;
    } else {
        // new balance < current balance
        difference = currentBalance.subtract(newBalance);
        transactionType = TransactionTypes.Withdrawal;
    }

    // open a new transaction screen to create a transaction to balance to the entered amount.
    Intent intent = new Intent(getContext(), CheckingTransactionEditActivity.class);
    intent.setAction(Intent.ACTION_INSERT);
    // add balance and transaction type and payee
    IntentDataParameters params = new IntentDataParameters();
    params.accountName = account.getAccountName();
    params.transactionType = transactionType;
    params.payeeName = getContext().getString(R.string.balance_adjustment);
    params.amount = difference;
    params.categoryName = getContext().getString(R.string.cash);
    intent.setData(params.toUri());

    getContext().startActivity(intent);
}

From source file:com.ifeel.healthy.SelectionFragment.java

private void startPracticePartnerActivity(Uri data, int requestCode) {
    Intent intent = new Intent();
    intent.setData(data);
    intent.setClass(getActivity(), ContactsListActivity.class);
    startActivityForResult(intent, requestCode);
}

From source file:com.ifeel.healthy.SelectionFragment.java

private void startHistoryGraphActivity(Uri data, int requestCode) {
    Intent intent = new Intent();
    intent.setData(data);
    intent.setClass(getActivity(), HistoryGraphActivity3.class);
    startActivityForResult(intent, requestCode);
}

From source file:com.ifeel.healthy.SelectionFragment.java

private void startMindfulBreadingActivity(Uri data, int requestCode) {
    Intent intent = new Intent();
    intent.setData(data);
    intent.setClass(getActivity(), com.agustinprats.myhrv.MainActivity.class);
    startActivityForResult(intent, requestCode);
}

From source file:com.ifeel.healthy.SelectionFragment.java

private void startSessionActivity(Uri data, int requestCode) {
    Intent intent = new Intent();
    intent.setData(data);
    intent.putExtra("PracticeSession", true);
    intent.setClass(getActivity(), com.agustinprats.myhrv.MainActivity.class);
    startActivityForResult(intent, requestCode);
}

From source file:com.irccloud.android.activity.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_RESOLVE_ERROR) {
        mResolvingError = false;//from   w ww.  j a  va2 s .co  m
        if (resultCode == RESULT_OK) {
            if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
                mGoogleApiClient.connect();
            }
        }
    } else if (requestCode == REQUEST_RESOLVE_CREDENTIALS) {
        if (resultCode == RESULT_OK && data.hasExtra(Credential.EXTRA_KEY)) {
            Credential c = data.getParcelableExtra(Credential.EXTRA_KEY);
            name.setText(c.getName());
            email.setText(c.getId());
            password.setText(c.getPassword());
            loading.setVisibility(View.GONE);
            login.setVisibility(View.VISIBLE);
            loginHintClickListener.onClick(null);
            new LoginTask().execute((Void) null);
        } else {
            loading.setVisibility(View.GONE);
            login.setVisibility(View.VISIBLE);
        }
    } else if (requestCode == REQUEST_RESOLVE_SAVE_CREDENTIALS) {
        if (resultCode == RESULT_OK) {
            Log.e("IRCCloud", "Credentials result: OK");
        }
        Intent i = new Intent(LoginActivity.this, MainActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        if (getIntent() != null) {
            if (getIntent().getData() != null)
                i.setData(getIntent().getData());
            if (getIntent().getExtras() != null)
                i.putExtras(getIntent().getExtras());
        }
        startActivity(i);
        finish();
    }
}

From source file:com.abc.driver.TruckActivity.java

private void doCrop() {
    Log.d(TAG, "doCrop()");
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0);

    int size = list.size();

    if (size == 0) {
        Log.d(TAG, " Crop activity is not found.  List size is zero.");
        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        trcukLicenseBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false);

        mTLPiv.setImageBitmap(trcukLicenseBmp);
        isPortraitChanged = true;//from  ww w. j  a va 2 s  . c om

        Log.d(TAG, "set bitmap");

        return;
    } else {
        Log.d(TAG, "found the crop activity.");
        intent.setData(imageUri);

        intent.putExtra("outputX", IMAGE_WIDTH);
        intent.putExtra("outputY", IMAGE_HEIGHT);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        if (size == 1) {
            Log.d(TAG, "Just one as choose it as crop activity.");
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);
            i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CellSiteConstants.CROP_PICTURE);
        } else {
            Log.d(TAG, "More that one activity for crop  is found . will chooose one");
            for (ResolveInfo res : list) {
                final CropOption co = new CropOption();

                co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo);
                co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo);
                co.appIntent = new Intent(intent);

                co.appIntent
                        .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

                cropOptions.add(co);
            }

            CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Crop App");

            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE);
                }
            });

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                // @Override
                public void onCancel(DialogInterface dialog) {
                    if (imageUri != null) {
                        getContentResolver().delete(imageUri, null, null);
                        imageUri = null;
                        isPortraitChanged = false;
                    }
                }
            });
            AlertDialog alert = builder.create();

            alert.show();
        }
    }
}

From source file:in.shick.diode.user.ProfileActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    Intent i;

    switch (item.getItemId()) {
    case Constants.DIALOG_COMMENT_CLICK:
        i = new Intent(getApplicationContext(), CommentsListActivity.class);
        i.setData(Util.createCommentUri(mVoteTargetThingInfo, 3));
        i.putExtra(Constants.EXTRA_SUBREDDIT, mVoteTargetThingInfo.getSubreddit());
        i.putExtra(Constants.EXTRA_TITLE, mVoteTargetThingInfo.getTitle());
        startActivity(i);//  w  ww .jav  a2  s.c om
        return true;
    case Constants.DIALOG_THREAD_CLICK:
        // Launch an Intent for CommentsListActivity
        CacheInfo.invalidateCachedThread(getApplicationContext());
        i = new Intent(getApplicationContext(), CommentsListActivity.class);
        i.putExtra(Constants.EXTRA_SUBREDDIT, mVoteTargetThingInfo.getSubreddit());
        i.putExtra(Constants.EXTRA_TITLE, mVoteTargetThingInfo.getTitle());
        // Thread things are handled differently than comment things.
        if (mVoteTargetThingInfo.isThreadKind()) {
            i.setData(Util.createThreadUri(mVoteTargetThingInfo));
            i.putExtra(Constants.EXTRA_NUM_COMMENTS, Integer.valueOf(mVoteTargetThingInfo.getNum_comments()));
        } else {
            // Should only get to this point if the Thing is a Comment, and link_id is valid.
            i.setData(Util.createThreadUri(mVoteTargetThingInfo.getSubreddit(),
                    Util.nameToId(mVoteTargetThingInfo.getLink_id())));
        }
        startActivity(i);
        return true;
    case Constants.DIALOG_LINKS:
        Common.showLinksDialog(ProfileActivity.this, mSettings, mVoteTargetThingInfo);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}