Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

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

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Starts the uploading experience//from w  ww .  j a  v  a 2s . c  o  m
 * @param requestCode The request code that will be used to choose simple/chunked uploading
 */
private void upload(final int requestCode) {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType(ACCEPTED_UPLOAD_MIME_TYPES);
    startActivityForResult(intent, requestCode);
}

From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

/**
 * /*w  w  w.j a v  a2 s .com*/
 */
public void startShareResultsIntent() {
    try {
        JSONObject resultListItem = testResult.getJSONObject(0);
        final String shareText = resultListItem.getString("share_text");
        final String shareSubject = resultListItem.getString("share_subject");

        final Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, shareText);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubject);
        sendIntent.setType("text/plain");
        activity.startActivity(Intent.createChooser(sendIntent, null));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.java2s.intents4.IntentsDemo4Activity.java

private Intent createIntentFromEditTextFields() {
    String theAction = actionText.getText().toString().trim();
    String theUri = uriText.getText().toString().trim();
    String theMimeType = mimeTypeText.getText().toString().trim();

    Intent intent = new Intent();
    if (theAction.length() != 0) {
        intent.setAction(theAction);//from   ww  w.ja v  a 2s . co m
    }
    intentHasBothUriAndType = false;
    if (theUri.length() != 0 && theMimeType.length() != 0) {
        intentHasBothUriAndType = true;
        intent.setDataAndType(Uri.parse(theUri), theMimeType);
    } else if (theUri.length() != 0) {
        intent.setData(Uri.parse(theUri));
    } else if (theMimeType.length() != 0) {
        intent.setType(theMimeType);
    }

    if (intentCategoriesLayout != null) {
        int count = intentCategoriesLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            String cat = ((EditText) ((ViewGroup) intentCategoriesLayout.getChildAt(i)).getChildAt(1)).getText()
                    .toString().trim();
            if (cat.length() != 0) {
                intent.addCategory(cat);
            }
        }
    }
    Log.i(CLASSNAME, intent.toString());
    return intent;
}

From source file:babybear.akbquiz.ConfigActivity.java

/**
 * // w  w  w . j a v a  2s . c  om
 */
protected void customBgImage() {
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int width = dm.widthPixels;
    int height = dm.heightPixels;

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
    intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*"); // 
    intent.putExtra("crop", "circle"); // ?
    intent.putExtra("aspectX", width); // ? 
    intent.putExtra("aspectY", height); // ? .
    intent.putExtra("output", Uri.fromFile(customBgImage));// 
    intent.putExtra("outputFormat", "PNG");// ?
    intent.putExtra("noFaceDetection", true); // ?
    intent.putExtra("return-data", false); // ??Intent
    startActivityForResult(intent, REQUESTCODE_IMAGE);
}

From source file:li.barter.fragments.EditProfileFragment.java

@Override
public void onDialogClick(final DialogInterface dialog, final int which) {

    if ((mChoosePictureDialogFragment != null) && mChoosePictureDialogFragment.getDialog().equals(dialog)) {

        if (which == 0) { // Pick from camera
            final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraImageCaptureUri);

            try {
                startActivityForResult(Intent.createChooser(intent, getString(R.string.complete_action_using)),
                        PICK_FROM_CAMERA);
            } catch (final ActivityNotFoundException e) {
                e.printStackTrace();/*from  w  w w  .ja v  a  2  s. c  om*/
            }

        } else if (which == 1) { // pick from file
            final Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, getString(R.string.complete_action_using)),
                    PICK_FROM_FILE);
        }
    } else {
        super.onDialogClick(dialog, which);
    }
}

From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java

/**
 * Send the content using a built-in Android activity which can handle the
 * content type.//from   www .j  a v  a  2  s.c  o m
 * 
 * @param position
 */
public void shareContent(int position) {
    final NodeRef ref = getItem(position);
    downloadContent(ref, new Handler() {
        public void handleMessage(Message msg) {
            Context context = getContext();
            boolean done = msg.getData().getBoolean("done");

            if (done) {
                dismissProgressDlg();

                File file = (File) mDlThread.getResult();

                if (file != null) {
                    Resources res = context.getResources();
                    Uri uri = Uri.fromFile(file);
                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, ref.getName());
                    emailIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.email_text));
                    emailIntent.setType(ref.getContentType());

                    try {
                        context.startActivity(
                                Intent.createChooser(emailIntent, res.getString(R.string.email_title)));
                    } catch (ActivityNotFoundException e) {
                        String text = "No suitable applications registered to send " + ref.getContentType();
                        int duration = Toast.LENGTH_SHORT;
                        Toast toast = Toast.makeText(context, text, duration);
                        toast.show();
                    }
                }
            } else {
                int value = msg.getData().getInt("progress");
                if (value > 0) {
                    mProgressDlg.setProgress(value);
                }
            }
        }
    });
}

From source file:com.github.gorbin.asne.instagram.InstagramSocialNetwork.java

/**
 * Post photo to social network/*from  w  w w.  j  a  v  a2  s.  c  o  m*/
 * @param photo photo that should be shared
 * @param message message that should be shared with photo
 * @param onPostingCompleteListener listener for posting request
 */
@Override
public void requestPostPhoto(File photo, String message, OnPostingCompleteListener onPostingCompleteListener) {
    super.requestPostPhoto(photo, message, onPostingCompleteListener);
    String instagramPackage = "com.instagram.android";
    String errorMessage = "You should install Instagram app first";
    if (isPackageInstalled(instagramPackage, mSocialNetworkManager.getActivity())) {
        Intent normalIntent = new Intent(Intent.ACTION_SEND);
        normalIntent.setType("image/*");
        normalIntent.setPackage(instagramPackage);
        File media = new File(photo.getAbsolutePath());
        Uri uri = Uri.fromFile(media);
        normalIntent.putExtra(Intent.EXTRA_STREAM, uri);
        normalIntent.putExtra(Intent.EXTRA_TEXT, message);
        mSocialNetworkManager.getActivity().startActivity(normalIntent);
    } else {
        mLocalListeners.get(REQUEST_POST_PHOTO).onError(getID(), REQUEST_POST_PHOTO, errorMessage, null);
    }
    mLocalListeners.remove(REQUEST_POST_PHOTO);
}

From source file:com.googlecode.CallerLookup.Main.java

public void doSubmit() {
    String entry = "";
    if (mLookup.getSelectedItemPosition() != 0) {
        entry = mLookup.getSelectedItem().toString() + "\n";
    }/*  w  ww .  ja  va  2  s .  c  o  m*/

    entry += mURL.getText().toString() + "\n";
    entry += mRegExp.getText().toString() + "\n";

    try {
        String[] mailto = { EMAIL_ADDRESS };
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
        sendIntent.putExtra(Intent.EXTRA_TEXT, entry);
        sendIntent.setType("message/rfc822");
        startActivity(sendIntent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.SubmitFailureTitle);
        alert.setMessage(R.string.SubmitFailureMessage);
        alert.setPositiveButton(android.R.string.ok, null);
        alert.show();
    }
}

From source file:com.slim.turboeditor.activity.MainActivity.java

public void saveTheFile(final boolean saveAs) {
    if (!saveAs && mFile != null && mFile.exists()) {
        Observable<Boolean> saveFile = getSaveFileObservable(getApplicationContext(), mFile,
                pageSystem.getAllText(mEditor.getText().toString()), currentEncoding)
                        .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).cache();

        saveFile.subscribe(new Action1<Boolean>() {
            @Override/*  ww w .  ja  v a2  s.co m*/
            public void call(Boolean aBoolean) {
                Log.d("call(" + aBoolean + ")");
                savedAFile(aBoolean);
            }
        });
    } else {
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.setType("*/*");
        intent.putExtra(Intent.EXTRA_TITLE, mFile.getName());
        startActivityForResult(intent, SAVE_AS_REQUEST_CODE);
    }
}

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

public void shareImage() {

    String path = Environment.getExternalStorageDirectory().toString();
    File file = new File(path, "/" + TEMP_WALLPAPER_DIR + "/" + TEMP_WALLPAPER_NAME + ".png");

    Uri imageUri = Uri.fromFile(file);/*w  w  w  . jav  a 2s .c  o  m*/
    if (file.exists()) {
        ;
        Log.e("FILE - ", file.getAbsolutePath());
    } else {
        Log.e("ERROR - ", file.getAbsolutePath());
    }

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "Mood Wallpaper");
    intent.putExtra(Intent.EXTRA_STREAM, imageUri);
    intent.setType("image/*");
    startActivity(intent);
}