Example usage for android.content Intent setDataAndType

List of usage examples for android.content Intent setDataAndType

Introduction

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

Prototype

public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type) 

Source Link

Document

(Usually optional) Set the data for the intent along with an explicit MIME data type.

Usage

From source file:com.amaze.filemanager.utils.files.FileUtils.java

/**
 * Open a file not supported by Amaze/*from  w  w w.  j a  v  a2  s .c om*/
 *
 * @param f the file
 * @param forcechooser force the chooser to show up even when set default by user
 */
public static void openunknown(File f, Context c, boolean forcechooser, boolean useNewStack) {
    Intent chooserIntent = new Intent();
    chooserIntent.setAction(Intent.ACTION_VIEW);

    String type = MimeTypes.getMimeType(f.getPath(), f.isDirectory());
    if (type != null && type.trim().length() != 0 && !type.equals("*/*")) {
        Uri uri = fileToContentUri(c, f);
        if (uri == null)
            uri = Uri.fromFile(f);
        chooserIntent.setDataAndType(uri, type);

        Intent activityIntent;
        if (forcechooser) {
            if (useNewStack)
                applyNewDocFlag(chooserIntent);
            activityIntent = Intent.createChooser(chooserIntent, c.getString(R.string.openwith));
        } else {
            activityIntent = chooserIntent;
            if (useNewStack)
                applyNewDocFlag(activityIntent);
        }

        try {
            c.startActivity(activityIntent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show();
            openWith(f, c, useNewStack);
        }
    } else {
        // failed to load mime type
        openWith(f, c, useNewStack);
    }
}

From source file:org.wso2.app.catalog.api.ApplicationManager.java

/**
 * Installs an application to the device.
 *
 * @param fileUri - File URI should be passed in as a String.
 *//*from w  w w .j a v a 2s.c om*/
public void startInstallerIntent(Uri fileUri) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(fileUri, resources.getString(R.string.application_mgr_mime));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:com.fanfou.app.opensource.service.DownloadService.java

@SuppressWarnings("unused")
private PendingIntent getInstallPendingIntent(final String fileName) {
    final String mimeType = MimeTypeMap.getSingleton()
            .getMimeTypeFromExtension(CommonHelper.getExtension(fileName));
    if (mimeType != null) {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(fileName)), mimeType);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        final PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
        return pi;
    }//from  w w w . j av a2s .co m
    return null;
}

From source file:com.media.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        // move position to first element
        mCursor.moveToFirst();//from www .j  a  va  2 s . c om

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            mGalleryModelList.add(new MediaModel(url, false));
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:com.dazone.crewchat.libGallery.fragment.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        //move position to first element
        mCursor.moveToFirst();/*  www  . j  av a  2  s .com*/

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            mGalleryModelList.add(new MediaModel(url, false));
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:com.example.ridemedriver.SignupStepTwoActivity.java

/**
 * ?/*w w w .  ja va  2 s .  c o m*/
 * @param uri
 */
public void cropPhoto(Uri uri) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    // aspectX aspectY 
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    // outputX outputY ?
    intent.putExtra("outputX", 150);
    intent.putExtra("outputY", 150);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, 3);
}

From source file:com.example.de.taomi2.mediachooser.fragment.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        //move position to first element
        mCursor.moveToFirst();// w  ww. j av a 2 s.co m

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            mGalleryModelList.add(new MediaModel(url, false));
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                /*
                if((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)){
                if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                 Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + "  " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show();
                 return;
                } else {
                 Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + "  " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show();
                 return;
                }
                }
                */
            }
            /*
            // inverse the status
            galleryModel.status = ! galleryModel.status;
            adapter.notifyDataSetChanged();
            */
            int i = 0;
            for (; i < adapter.getCount(); i++) {
                if (i != position) {
                    adapter.getItem(i).status = false;
                }
            }
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();
            mSelectedItems.clear();
            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                //MediaChooserConstants.SELECTED_MEDIA_COUNT ++;

            } else {
                /*
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT --;
                */
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:cn.xcom.helper.activity.AuthorizedActivity.java

/**
 * ?// w  ww  . ja  va 2 s.c  o  m
 *
 * @param uri
 */
public void startPhotoZoom(Uri uri) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    // ?
    intent.putExtra("crop", "true");
    // aspectX aspectY 
    intent.putExtra("aspectX", 4);
    intent.putExtra("aspectY", 3);
    // outputX outputY ?
    intent.putExtra("outputX", 400);
    intent.putExtra("outputY", 300);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, PHOTO_REQUEST_CUT);
}

From source file:com.example.ridemedriver.SignupStepTwoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup_step_two);
    getActionBar().hide();//from   w  w  w  .ja  v a  2  s  .  co  m

    Bundle extras = getIntent().getExtras();
    phone = extras.getString(EXTRA_PHONE);
    password = extras.getString(EXTRA_PHONE);
    name = extras.getString(EXTRA_PHONE);
    alipay = extras.getString(EXTRA_PHONE);

    signup_steptwo_signup = (Button) findViewById(R.id.signup_steptwo_signup);
    signup_steptwo_signup.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            new sign_up().execute();
        }
    });
    signup_steptwo_btn_back = (ImageButton) findViewById(R.id.signup_steptwo_btn_back);
    signup_steptwo_govid_edit = (EditText) findViewById(R.id.signup_steptwo_govid_edit);
    signup_steptwo_stuid_edit = (EditText) findViewById(R.id.signup_steptwo_stuid_edit);
    signup_steptwo_model_edit = (EditText) findViewById(R.id.signup_steptwo_model_edit);
    signup_steptwo_vid_edit = (EditText) findViewById(R.id.signup_steptwo_vid_edit);
    signup_steptwo_avatar_imgview = (ImageView) findViewById(R.id.signup_steptwo_avatar_imgview);
    signup_steptwo_avatar_imgview.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent1 = new Intent(Intent.ACTION_PICK, null);
            intent1.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
            startActivityForResult(intent1, 1);
        }
    });
}

From source file:de.rwthaachen.rz.rwthapp.plugins.fileopener.FileOpener.java

private boolean openFile(String url) throws IOException {
    // Create URI
    Uri uri = Uri.parse(url);/*w  w  w.j  a v a2  s  .com*/

    Intent intent;
    // Check what kind of file you are trying to open, by comparing the url with extensions.
    // When the if condition is matched, plugin sets the correct intent (mime) type,
    // so Android knew what application to use to open the file

    String mimeType = URLConnection.guessContentTypeFromName(url);
    intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mimeType);

    try {
        this.cordova.getActivity().startActivity(intent);
        return true;
    } catch (Exception e) {
        return false;
    }
}