Intent setDataAndType - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Intent setDataAndType method.

This code example shows how to use the following methods:setDataAndType, resolveActivity
    } 
 
    // @return a ResolveInfo instance for the mime type or null if the type is 
    // not handled by any activity. 
    private ResolveInfo resolveMime(String mime) {
        Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.fromParts("file", MP3_FILE, null);
 
        viewIntent.setDataAndType(uri, mime);
        return mContext.getPackageManager().resolveActivity(
                viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
    } 
 
    // Helper method to check the media playback activity handles the given mime type. 
    // @param mime type to test for 
    private void assertMediaPlaybackActivityHandles(String mime) throws Exception {
        ResolveInfo ri = resolveMime(mime);
 
        assertNotNull(ri);
    } 
8
CodeRank
This code example shows how to use the following methods:setDataAndType
    return(result);
  } 
 
  @Override 
  public void onClick(View v) {
    Intent i=new Intent(getActivity(), Downloader.class);
 
    i.setDataAndType(Uri.parse("http://commonsware.com/Android/excerpt.pdf"),
                     "application/pdf"); 
 
    getActivity().startService(i);
    getActivity().finish(); 
  } 
} 
8
CodeRank
This code example shows how to use the following methods:setDataAndType
    } 
 
    public void startPlayback(String filename){
      String mimetype = "audio/mpeg";
      Uri path = Uri.parse(filename);
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setDataAndType(path, mimetype);
      startActivity(intent);
    } 
 
  public static boolean checkStreamingServer() throws Exception { 
      InetAddress address = InetAddress.getByAddress(MediaNames.STREAM_SERVER);
      return address.isReachable(10000);
  } 
 
  public static void testInvalidateOverlay() { 
      mOverlayView.invalidate();
  } 
 
} 
7
CodeRank
This code example shows how to use the following methods:addFlags, setClassName, setDataAndType
            return "" + size + "B";
    } 
 
    public static void installAPK(Context context, final String url) {
 
        Intent intent = new Intent(Intent.ACTION_VIEW);
        String fileName = FILE_ROOT + NetworkUtils.getFileNameFromUrl(url);
        intent.setDataAndType(Uri.fromFile(new File(fileName)),
                "application/vnd.android.package-archive"); 
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setClassName("com.android.packageinstaller",
                "com.android.packageinstaller.PackageInstallerActivity"); 
        context.startActivity(intent);
    } 
 
    public static boolean delete(File path) {
 
        boolean result = true;
        if (path.exists()) {
            if (path.isDirectory()) {
7
CodeRank
This code example shows how to use the following methods:setDataAndType
  @Override 
  protected void onActivityResult(int requestCode, int resultCode,
                                  Intent data) {
    if (requestCode == CONTENT_REQUEST) {
      if (resultCode == RESULT_OK) {
        Intent i=new Intent(Intent.ACTION_VIEW);
         
        i.setDataAndType(Uri.fromFile(output), "image/jpeg");
        startActivity(i);
        finish();
      } 
    } 
  } 
} 
7
CodeRank
This code example shows how to use the following methods:setDataAndType, resolveActivity
        if (contentDisposition == null
                || !contentDisposition.regionMatches(
                        true, 0, "attachment", 0, 10)) { 
            // query the package manager to see if there's a registered handler 
            //     that matches. 
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(url), mimetype);
            ResolveInfo info = activity.getPackageManager().resolveActivity(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            if (info != null) {
                ComponentName myName = activity.getComponentName();
                // If we resolved to ourselves, we don't want to attempt to 
                // load the url only to try and download it again. 
                if (!myName.getPackageName().equals(
                        info.activityInfo.packageName)
                        || !myName.getClassName().equals(
                                info.activityInfo.name)) {
                    // someone (other than us) knows how to handle this mime 
                    // type with this scheme, don't download. 
                    try { 
7
CodeRank
This code example shows how to use the following methods:setDataAndType, setFlags
        Uri uri = manager.getUriForDownloadedFile(id);
        if (uri == null) {
            // Open the downloads page 
            openDownloadsPage(context);
        } else { 
            Intent launchIntent = new Intent(Intent.ACTION_VIEW);
            launchIntent.setDataAndType(uri, manager.getMimeTypeForDownloadedFile(id));
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try { 
                context.startActivity(launchIntent);
            } catch (ActivityNotFoundException e) {
                openDownloadsPage(context);
            } 
        } 
    } 
 
    /** 
     * Open the Activity which shows a list of all downloads. 
     * @param context 
     */ 
7
CodeRank
This code example shows how to use the following methods:setDataAndType
    } 
 
    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id)
    { 
        Intent intent = new Intent(Intent.ACTION_VIEW);
        mCursor.moveToPosition(position);
        String type = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
        intent.setDataAndType(ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id), type);
         
        startActivity(intent);
    } 
 
    private void MakeCursor() { 
        String[] cols = new String[] {
                MediaStore.Video.Media._ID,
                MediaStore.Video.Media.TITLE,
                MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.MIME_TYPE,
                MediaStore.Video.Media.ARTIST
7
CodeRank
This code example shows how to use the following methods:putExtra, setDataAndType
        if (requestCode == REQUEST_PICK_CONTACT) {
            mContactUri = result.getData();
            // A contact was picked. Launch the cropper to get face detection, the right size, etc. 
            // TODO: get these values from constants somewhere 
            Intent myIntent = getIntent();
            Intent intent = new Intent("com.android.camera.action.CROP", myIntent.getData());
            if (myIntent.getStringExtra("mimeType") != null) {
                intent.setDataAndType(myIntent.getData(), myIntent.getStringExtra("mimeType"));
            } 
            intent.putExtra("crop", "true");
            intent.putExtra("aspectX", 1);
            intent.putExtra("aspectY", 1);
            intent.putExtra("outputX", 96);
            intent.putExtra("outputY", 96);
            intent.putExtra("return-data", true);
            startActivityForResult(intent, REQUEST_CROP_PHOTO);
        } else if (requestCode == REQUEST_CROP_PHOTO) {
            final Bundle extras = result.getExtras();
            if (extras != null) {
                Bitmap photo = extras.getParcelable("data");
6
CodeRank
This code example shows how to use the following methods:setDataAndType
	} 
 
	public void install() throws IOException { 
		 
		File napk = new File(ptdir, "minecraft-cs.apk");
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setDataAndType(Uri.fromFile(napk),
				"application/vnd.android.package-archive"); 
		main.startActivityForResult(intent, 1);
	} 
	 
	public void update() throws IOException{ 
		applyChanges(); 
		 
	} 
	 
	public void addChar(File chrf) throws IOException {
		 
		File tchrf = new File(ptdir, "/temp/assets/mob/char.png");
		tchrf.delete();
5
CodeRank

Related Intent setDataAndType Questions & Answers:

setDataAndType Method Overview
(Usually optional) Set the data for the intent along with an explicit MIME data type.
See Code Examples for other Android Intent Methods: