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.phonegap.plugins.pdfViewer.PdfViewer.java

public String showPdf(String fileName) {

    File file = new File(fileName);

    if (file.exists()) {
        try {/*  w ww  .j av a  2s  . co  m*/
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            //intent.setData(Uri.parse(fileName));
            this.ctx.startActivity(intent);
            return "";
        } catch (android.content.ActivityNotFoundException e) {
            System.out.println("PdfViewer: Error loading url " + fileName + ":" + e.toString());
            return e.toString();
        }

    } else {
        return "file not found";
    }
}

From source file:com.target.plugins.PdfViewer.java

public String showPdf(String fileName) {

    File file = new File(fileName);

    if (file.exists()) {
        try {/*from   ww w.ja va  2s  .c o  m*/
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            //intent.setData(Uri.parse(fileName));
            this.ctx.startActivity(intent);
            return "";
        } catch (android.content.ActivityNotFoundException e) {
            System.out.println("PdfViewer: Error loading url " + fileName + ":" + e.toString());
            return e.toString();
        }

    } else {
        return "file not found";
    }

}

From source file:com.polyvi.xface.extension.video.XVideoExt.java

private void play(String filePath, XCallbackContext callbackCtx) {
    XPathResolver pathResolver = new XPathResolver(filePath, mWebContext.getWorkSpace());
    String path = pathResolver.resolve();
    XPathResolver.Scheme scheme = pathResolver.getSchemeType();
    Boolean isPathValid = false;/*ww w .  j  a  va2s. co m*/

    //?
    if (null != path) {
        if (scheme == XPathResolver.Scheme.NONE || scheme == XPathResolver.Scheme.FILE
                || scheme == XPathResolver.Scheme.CONTENT) {//?
            File file = new File(path);
            if (file.exists()) {
                //??
                XFileUtils.setPermission(XFileUtils.READABLE_BY_OTHER, path);
                isPathValid = true;
            }
        } else {//?
            isPathValid = true;
        }
    }

    if (isPathValid) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(pathResolver.getUri(), "video/*");
        mExtensionContext.getSystemContext().startActivityForResult(new XVideoActResultListener(callbackCtx),
                intent, PLAY_VIDEO_REQUEST_CODE);
    } else {
        callbackCtx.error("video file not found error");
    }
}

From source file:com.mappn.gfan.common.util.Utils.java

/**
 * Android //  w ww. j a va  2 s .  c  om
 * 
 * @param context Application Context
 * @param filePath APK
 */
public static void installApk(Context context, File file) {
    if (file.exists()) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        ((ContextWrapper) context).startActivity(i);
    } else {
        makeEventToast(context, context.getString(R.string.install_fail_file_not_exist), false);
    }
}

From source file:com.jumpbyte.mobile.plugin.PdfViewer.java

public String showPdf(String fileName) {

    File file = new File(fileName);

    Log.i("PdfViewer", "open file " + fileName);
    //        if (file.exists()) {
    Log.i("PdfViewer", "file exist");
    try {/*from   ww w. j  a v  a2  s. c  o  m*/
        Uri path = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        //intent.setData(Uri.parse(fileName));
        this.ctx.startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        System.out.println("PdfViewer: Error loading url " + fileName + ":" + e.toString());
        return e.toString();
    }
    /*
            }else{
               Log.i("PdfViewer", "file not exist");
               return "file not found";
            }
      */

}

From source file:com.commonsware.android.foredown.Downloader.java

private void raiseNotification(Intent inbound, File output, Exception e) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);

    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis());

    if (e == null) {
        b.setContentTitle(getString(R.string.download_complete)).setContentText(getString(R.string.fun))
                .setSmallIcon(android.R.drawable.stat_sys_download_done)
                .setTicker(getString(R.string.download_complete));

        Intent outbound = new Intent(Intent.ACTION_VIEW);

        outbound.setDataAndType(Uri.fromFile(output), inbound.getType());

        b.setContentIntent(PendingIntent.getActivity(this, 0, outbound, 0));
    } else {/*w  ww.  j a  va  2s.  c  o  m*/
        b.setContentTitle(getString(R.string.exception)).setContentText(e.getMessage())
                .setSmallIcon(android.R.drawable.stat_notify_error).setTicker(getString(R.string.exception));
    }

    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mgr.notify(NOTIFY_ID, b.build());
}

From source file:piramide.multimodal.client.tester.ApplicationDownloader.java

void install() {
    final Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(
            Uri.parse("file://" + this.activity.getFilesDir().getAbsolutePath() + "/" + APK_FILENAME),
            "application/vnd.android.package-archive");
    this.activity.startActivity(intent);
}

From source file:piramide.multimodal.downloader.client.ApplicationDownloader.java

void install() {
    final Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(
            Uri.parse("file://" + this.context.getFilesDir().getAbsolutePath() + "/" + APK_FILENAME),
            "application/vnd.android.package-archive");
    this.context.startActivity(intent);
}

From source file:com.aengbee.android.leanback.ui.VideoDetailsActivity.java

public void intent2mxplayer(Uri videoUri, String dataType) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(videoUri, dataType);
    intent.setPackage("com.mxtech.videoplayer.pro");
    byte DECODER_SW = 2;
    intent.putExtra("decode_mode", DECODER_SW);
    startActivity(intent);// w  w  w  .j a va  2s. c  o m
}

From source file:com.amaze.carbonfilemanager.utils.files.Futils.java

public static void openWith(final File f, final Context c) {
    MaterialDialog.Builder a = new MaterialDialog.Builder(c);
    a.title(c.getResources().getString(R.string.openas));
    String[] items = new String[] { c.getResources().getString(R.string.text),
            c.getResources().getString(R.string.image), c.getResources().getString(R.string.video),
            c.getResources().getString(R.string.audio), c.getResources().getString(R.string.database),
            c.getResources().getString(R.string.other) };

    a.items(items).itemsCallback(new MaterialDialog.ListCallback() {
        @Override//from  w w  w  .  j a  v  a  2 s .c  om
        public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
            Uri uri = fileToContentUri(c, f);
            if (uri == null)
                uri = Uri.fromFile(f);
            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_VIEW);
            switch (i) {
            case 0:
                intent.setDataAndType(uri, "text/*");
                break;
            case 1:
                intent.setDataAndType(uri, "image/*");
                break;
            case 2:
                intent.setDataAndType(uri, "video/*");
                break;
            case 3:
                intent.setDataAndType(uri, "audio/*");
                break;
            case 4:
                intent = new Intent(c, DbViewer.class);
                intent.putExtra("path", f.getPath());
                break;
            case 5:
                intent.setDataAndType(uri, "*/*");
                break;
            }
            try {
                c.startActivity(intent);
            } catch (Exception e) {
                Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show();
                openWith(f, c);
            }
        }
    });
    try {
        a.build().show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}