Example usage for android.webkit MimeTypeMap getMimeTypeFromExtension

List of usage examples for android.webkit MimeTypeMap getMimeTypeFromExtension

Introduction

In this page you can find the example usage for android.webkit MimeTypeMap getMimeTypeFromExtension.

Prototype

@Nullable
public String getMimeTypeFromExtension(String extension) 

Source Link

Document

Return the MIME type for the given extension.

Usage

From source file:cl.gisred.android.InspActivity.java

private void cerrarFormCrear(boolean bSave, View v, int idR) {
    if (bSave) {//from   w  w  w.  ja  v a  2  s .c o  m
        if (!validarForm(v)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {

            Resources res = getResources();
            InputStream in_s = res.openRawResource(R.raw.index);
            try {
                View vAction = getLayoutValidate(v);
                byte[] b = new byte[in_s.available()];
                in_s.read(b);
                String sHtml = new String(b);
                HtmlUtils oHtml = new HtmlUtils(getApplicationContext(), sHtml);

                String sValueNumMed = "null";

                for (View view : vAction.getTouchables()) {

                    if (view.getClass().getGenericSuperclass().equals(EditText.class)) {
                        EditText oText = (EditText) view;
                        if (!oText.getText().toString().trim().isEmpty()) {
                            String sMapvalue = HtmlUtils.getMapvalue(oText.getId());
                            String sValorChr = oText.getText().toString();
                            oHtml.setValueById(sMapvalue, "txt", sValorChr);
                            if (oText.getId() == R.id.txtOT) {
                                sValueNumMed = sValorChr;
                            }

                            if (sMapvalue != null && sMapvalue.contains("txt_trabajo_cant")) {
                                try {
                                    double dValue = Double.valueOf(sValorChr);
                                    oHtml.sumHH += dValue;
                                } catch (Exception ex) {
                                    Log.e("Double Convert", "error: " + ex.getMessage());
                                }
                            }
                        }
                    } else if (view.getClass().getGenericSuperclass().equals(CheckBox.class)) {
                        CheckBox oCheck = (CheckBox) view;
                        String sCheck = HtmlUtils.getMapvalue(oCheck.getId());
                        sCheck += oCheck.isChecked() ? "si" : "no";
                        oHtml.setValueById(sCheck, "chk", "");
                    } else if (view.getClass().getGenericSuperclass().equals(Spinner.class)) {
                        Spinner oSpinner = (Spinner) view;
                        oHtml.setValueById(HtmlUtils.getMapvalue(oSpinner.getId()), "txt",
                                oSpinner.getSelectedItem().toString());
                    } else if (view.getClass().getGenericSuperclass().equals(RadioButton.class)) {
                        RadioButton oRadioButton = (RadioButton) view;
                        if (oRadioButton.isChecked()) {
                            String sRadio = HtmlUtils
                                    .getMapvalue(((RadioGroup) oRadioButton.getParent()).getId());
                            sRadio += oRadioButton.getText().toString().toLowerCase().replace(" ", "");
                            oHtml.setValueById(sRadio, "rad", "");
                        }
                    } else if (view.getClass().getGenericSuperclass().equals(ImageView.class)) {
                    }
                }

                //SUMA TOTAL HH
                oHtml.setValueById("txt_trabajo_cant_tot", "txt", "" + oHtml.sumHH);

                //VALIDAR FIRMAS
                if (valImage(vAction, R.id.imgFirmaIns))
                    oHtml.setValueById("firm_prop", "img", String.format("%s.jpg", R.id.imgFirmaIns));
                if (valImage(vAction, R.id.imgFirmaTec))
                    oHtml.setValueById("firm_tecn", "img", String.format("%s.jpg", R.id.imgFirmaTec));

                if (valImage(vAction, R.id.imgPhoto1))
                    oHtml.setValueById("foto_1", "img", "foto1.jpg");
                if (valImage(vAction, R.id.imgPhoto2))
                    oHtml.setValueById("foto_2", "img", "foto2.jpg");
                if (valImage(vAction, R.id.imgPhoto3))
                    oHtml.setValueById("foto_3", "img", "foto3.jpg");

                oHtml.setTitleHtml(sValueNumMed);

                String sHtmlFinal = oHtml.getHtmlFinal();

                //guardar en disco
                oHtml.createHtml(sHtmlFinal);

                //VIA CustomTabs
                /*String url = oHtml.getPathHtml();
                CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
                CustomTabsIntent customTabsIntent = builder.build();
                customTabsIntent.launchUrl(this, Uri.parse(url));*/

                //VIA CHROME scheme
                if (Util.isPackageExisted("com.android.chrome", this)) {
                    String url = oHtml.getPathHtml();

                    File f = new File(url);

                    MimeTypeMap mime = MimeTypeMap.getSingleton();
                    String ext = f.getName().substring(f.getName().lastIndexOf(".") + 1);
                    String type = mime.getMimeTypeFromExtension(ext);

                    Uri uri = Uri.parse("googlechrome://navigate?url=" + url);

                    Intent in = new Intent(Intent.ACTION_VIEW);
                    //in.setDataAndType(uri, "text/html");

                    in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    in.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

                    //Uri uriExternal = FileProvider.getUriForFile(getApplicationContext(), "cl.gisred.android", f);

                    in.setDataAndType(uri, type);

                    //startActivity(in);
                    startActivity(Intent.createChooser(in, "Escoja Chrome"));
                } else {
                    Toast.makeText(this, "Debe instalar Chrome, solo preview disponible", Toast.LENGTH_LONG)
                            .show();
                    Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(oHtml.getPathHtml()));
                    startActivity(myIntent);
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    menuMultipleActions.setVisibility(View.VISIBLE);
    menuInspeccionActions.setVisibility(View.VISIBLE);
    fabShowForm.setVisibility(View.GONE);
    formCrear.dismiss();
}

From source file:com.codename1.impl.android.AndroidImplementation.java

private String getMimeType(String url) {
    String type = null;//from ww w  .  ja  v  a  2 s.  co m
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();

        type = mime.getMimeTypeFromExtension(extension);
    }
    if (type == null) {
        try {
            Uri uri = Uri.parse(url);
            ContentResolver cr = getContext().getContentResolver();
            type = cr.getType(uri);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    return type;
}