Example usage for android.app Activity startActivityForResult

List of usage examples for android.app Activity startActivityForResult

Introduction

In this page you can find the example usage for android.app Activity startActivityForResult.

Prototype

public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) 

Source Link

Document

Same as calling #startActivityForResult(Intent,int,Bundle) with no options.

Usage

From source file:io.valuesfeng.picker.Picker.java

/**
 * Start to select photo./*from   w w  w.j av  a  2s  .  co  m*/
 *
 * @param requestCode identity of the requester activity.
 */
public void forResult(int requestCode) {
    if (engine == null)
        throw new ExceptionInInitializerError(LoadEngine.INITIALIZE_ENGINE_ERROR);

    Activity activity = getActivity();
    if (activity == null) {
        return; // cannot continue;
    }
    mSelectionSpec.setMimeTypeSet(mMimeType);
    mSelectionSpec.setEngine(engine);
    Intent intent = new Intent(activity, ImageSelectActivity.class);
    intent.putExtra(ImageSelectActivity.EXTRA_SELECTION_SPEC, mSelectionSpec);
    //        intent.putExtra(ImageSelectActivity.EXTRA_ENGINE, (Serializable) engine);
    intent.putParcelableArrayListExtra(ImageSelectActivity.EXTRA_RESUME_LIST,
            (ArrayList<? extends android.os.Parcelable>) mResumeList);

    Fragment fragment = getFragment();
    if (fragment != null) {
        fragment.startActivityForResult(intent, requestCode);
    } else {
        activity.startActivityForResult(intent, requestCode);
    }
    hasInitPicker = false;
}

From source file:at.flack.activity.NewFbContactActivity.java

public void openMessageActivity(Activity activity, int arg2) {
    if (arg2 < 0 || activity == null || fbcontacts == null)
        return;/*w  ww .  j a v  a 2  s .  c o m*/
    Intent smsIntent = new Intent(activity, FbMessageOverview.class);
    smsIntent.putExtra("CONTACT_ID", fbcontacts.get(arg2).getFbId());
    smsIntent.putExtra("MY_ID", MainActivity.fb_api.getMyID());
    smsIntent.putExtra("CONTACT_NAME", fbcontacts.get(arg2).getName());
    smsIntent.putExtra("CONTACT_TID", fbcontacts.get(arg2).getFbId());
    smsIntent.putExtra("isGroupChat", false);
    try {
        KeyEntity key = KeySafe.getInstance(this).get(fbcontacts.get(arg2).getTid());
        if (key != null)
            smsIntent.putExtra("CONTACT_KEY", key);
    } catch (NullPointerException e) {
    }
    activity.startActivityForResult(smsIntent, 2);
}

From source file:com.google.plus.wigwamnow.social.GoogleProvider.java

/**
 * Share an interactive post using the native dialog.
 *///from  ww  w .j a v  a2 s . c o  m
@Override
public boolean share(Wigwam wigwam, Activity activity) {
    if (!(activity instanceof PlusClientHostActivity)) {
        throw new IllegalArgumentException("Activity must host a PlusClient!");
    }

    PlusClientHostActivity hostActivity = (PlusClientHostActivity) activity;

    String host = activity.getResources().getString(R.string.external_host);
    Uri wigwamLink = Uri.parse(host + "/wigwams/" + wigwam.getId());
    String title = "Check out " + wigwam.getName() + "!";
    Intent shareIntent = new PlusShare.Builder(activity, hostActivity.getPlusClient()).setType("text/plain")
            .setText(title).addCallToAction("RESERVE", wigwamLink, "/wigwams/" + wigwam.getId())
            .setContentDeepLinkId("/wigwams/" + wigwam.getId(), title, wigwam.getDescription(), wigwamLink)
            .setContentUrl(wigwamLink).getIntent();
    activity.startActivityForResult(shareIntent, 0);
    return false;
}

From source file:com.nuvolect.securesuite.data.ExportVcf.java

public static void emailVcf(Activity act, long contact_id) {

    String messageTitle = "vCard for ";
    String messageBody = "\n\n\nContact from SecureSuite, a secure contact manager";

    try {/*w  w  w. ja v  a2 s . c  om*/
        String displayName = SqlCipher.get(contact_id, ATab.display_name);
        String fileName = displayName.replaceAll("\\W+", "");
        if (fileName.isEmpty())
            fileName = "contact";
        fileName = fileName + ".vcf";

        new File(act.getFilesDir() + CConst.SHARE_FOLDER).mkdirs();
        File vcf_file = new File(act.getFilesDir() + CConst.SHARE_FOLDER + fileName);

        writeContactVcard(contact_id, vcf_file);

        // Must match "authorities" in Manifest provider definition
        String authorities = act.getResources().getString(R.string.app_authorities) + ".provider";

        Uri uri = null;
        try {
            uri = FileProvider.getUriForFile(act, authorities, vcf_file);
        } catch (IllegalArgumentException e) {
            LogUtil.logException(act, LogType.EXPORT_VCF, e);
        }

        //convert from paths to Android friendly Parcelable Uri's
        ArrayList<Uri> uris = new ArrayList<Uri>();
        uris.add(uri);

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle + displayName);
        intent.putExtra(Intent.EXTRA_TEXT, messageBody);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("path", vcf_file.getAbsolutePath());

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        act.startActivityForResult(Intent.createChooser(intent, "Share with..."),
                CConst.RESPONSE_CODE_SHARE_VCF);

    } catch (Exception e) {
        LogUtil.logException(act, LogType.EXPORT_VCF, e);
    }
}

From source file:com.tct.mail.browse.MessageAttachmentBar.java

private void saveAttachmentWithLocationSelectable() {
    if (mAttachment == null) {
        Utility.showToast(this.getContext(), R.string.attachment_not_saved);
        return;/* ww  w . j ava  2 s . c o m*/
    }
    Activity activity = (Activity) getContext();
    Intent intent = new Intent(activity, com.tct.mail.browse.AttachmentDownloadSetting.class);
    intent.putExtra(AttachmentDownloadSetting.ATTACHMENT_KEY, mAttachment);
    activity.startActivityForResult(intent, 0);
    AttachmentDownloadSetting.setAttachmentActionHandler(mActionHandler);
    AttachmentDownloadSetting.setMessageAttachmentBar(this);
}

From source file:com.microsoft.rightsmanagement.ui.PolicyPickerActivity.java

/**
 * Show UI./*w w  w . ja v  a 2  s. c o  m*/
 * 
 * @param requestCode the request code
 * @param parentActivity the activity
 * @param templateDescriptorList the template descriptor list
 * @param originalTemplateDescriptor the original template descriptor
 * @param pickerCompletionCallback the picker completion callback
 */
public static void show(int requestCode, Activity parentActivity,
        List<TemplateDescriptor> templateDescriptorList, TemplateDescriptor originalTemplateDescriptor,
        CompletionCallback<PolicyPickerActivityResult> pickerCompletionCallback) {
    Logger.ms(TAG, "show");
    parentActivity = validateActivityInputParameter(parentActivity);
    templateDescriptorList = validateTemplateDescriptorListInputParameter(templateDescriptorList);
    pickerCompletionCallback = validateCompletionCallbackInputParameter(pickerCompletionCallback);
    int requestCallbackId = pickerCompletionCallback.hashCode();
    TemplateDescriptor[] templateDescriptorArray = new TemplateDescriptor[templateDescriptorList.size()];
    templateDescriptorList.toArray(templateDescriptorArray); // fill the array
    sCallbackManager.putWaitingRequest(requestCallbackId, pickerCompletionCallback, templateDescriptorArray);
    Intent intent = new Intent(parentActivity, PolicyPickerActivity.class);
    // translate MSIPC SDK object model to UI model
    TemplateDescriptorModel[] templateDescriptorItemArray = TemplateDescriptorModel
            .create(templateDescriptorArray);
    TemplateDescriptorModel originalTemplateDescriptorItem = null;
    if (originalTemplateDescriptor != null) {
        originalTemplateDescriptorItem = new TemplateDescriptorModel(originalTemplateDescriptor);
    }
    // start activity
    intent.putExtra(REQUEST_CALLBACK_ID, requestCallbackId);
    intent.putExtra(REQUEST_TEMPLATE_DESCRIPTOR_ITEM_ARRAY, templateDescriptorItemArray);
    intent.putExtra(REQUEST_ORIGINAL_TEMPLATE_DESCRIPTOR_ITEM, originalTemplateDescriptorItem);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    parentActivity.startActivityForResult(intent, requestCode);
    Logger.me(TAG, "show");
}

From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java

/**
 * take picture//from  w w w .java2s  .co  m
 */
public void takePicture(Activity act, int requestCode) throws IOException {

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(act.getPackageManager()) != null) {
        // Create the File where the photo should go
        //File photoFile = createImageFile();
        File photoFile = createImageSaveFile(act);
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        }
    }
    act.startActivityForResult(takePictureIntent, requestCode);

}

From source file:com.android.launcher3.Utilities.java

public static void openSettings(Activity activity) {
    activity.startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void openFileChooser(Activity activity, String mimeType, int requestCode) {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(mimeType);//ww  w .  j  a va  2  s .com
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // special intent for Samsung file manager
    Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");

    sIntent.putExtra("CONTENT_TYPE", mimeType);
    sIntent.addCategory(Intent.CATEGORY_DEFAULT);

    Intent chooserIntent;
    if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) {
        chooserIntent = Intent.createChooser(sIntent, "Open file");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent });
    } else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    if (chooserIntent != null) {
        try {
            activity.startActivityForResult(chooserIntent, requestCode);
            return;
        } catch (android.content.ActivityNotFoundException ex) {
        }
    }
    Toast.makeText(activity.getApplicationContext(),
            activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show();
}

From source file:ru.otdelit.astrid.opencrx.sync.OpencrxSyncProvider.java

/**
 * If user isn't already signed in, show sign in dialog. Else perform sync.
 *//*w  ww . j  av  a 2  s .  c o m*/
@Override
protected void initiateManual(Activity activity) {
    String authToken = preferences.getToken();
    OpencrxUtilities.INSTANCE.stopOngoing();

    // check if we have a token & it works
    if (authToken == null) {
        // display login-activity
        Intent intent = new Intent(activity, OpencrxLoginActivity.class);
        activity.startActivityForResult(intent, 0);
    } else {
        activity.startService(new Intent(null, null, activity, OpencrxBackgroundService.class));
    }
}