Example usage for android.net Uri toString

List of usage examples for android.net Uri toString

Introduction

In this page you can find the example usage for android.net Uri toString.

Prototype

public abstract String toString();

Source Link

Document

Returns the encoded string representation of this URI.

Usage

From source file:com.example.cuisoap.agrimac.machineRegister.driverInfoFragment.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri license_uri = data.getData();
        Log.e("uri", license_uri.toString());
        ContentResolver cr = context.getContentResolver();
        try {//from  ww  w .  j  av a  2 s . c  o  m
            Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(license_uri));
            if (requestCode == 1) {
                //String path=getRealPathFromURI(uri);
                //System.out.println(path);
                bitmap = ImageUtils.comp(bitmap);
                license_path = ImageUtils.saveMyBitmap(bitmap, "driver");
                license_pic.setImageBitmap(bitmap);
                license_pic.setVisibility(View.VISIBLE);
                license.setVisibility(View.GONE);
                license_pic.setOnClickListener(myOnClickListener);
            }

        } catch (FileNotFoundException e) {
            Log.e("Exception", e.getMessage(), e);
        }
    } else {
        Toast.makeText(context, "?", Toast.LENGTH_SHORT).show();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:org.blanco.techmun.android.cproviders.TechMunContentProvider.java

@Override
public String getType(Uri uri) {
    //User wants to retrieve mesa objects
    if (uri.toString().equalsIgnoreCase(MESAS_REST_SERVICE_BSAE_URI)
            || uri.toString().matches(MESA_CONENT_PETION_REG_EXP)) {
        return "org.blanco.techmun.entities.Mesa";
        //User wants to retrieve 
    } else if (uri.toString().matches(MESA_CONTENT_EVENTOS_PETITION_REG_EXP)) {
        return "org.blanco.techmun.entities.Evento";
    } else if (uri.toString().matches(MESA_CONTENT_COMENTARIOS_PETITION_REG_EXP)) {
        Comentario.class.getCanonicalName();
    }/*w  w  w . j  av a 2  s .  c o  m*/
    //Petition not recognized, return object as default.
    return "java.lang.Object";
}

From source file:eu.alefzero.owncloud.authenticator.AuthenticationRunnable.java

@Override
public void run() {
    Uri uri;
    uri = Uri.parse(mUrl.toString());/*  w ww.j  av  a2  s  . co m*/
    int login_result = WebdavClient.tryToLogin(uri, mUsername, mPassword);
    switch (login_result) {
    case HttpStatus.SC_OK:
        postResult(true, uri.toString());
        break;
    case HttpStatus.SC_UNAUTHORIZED:
        postResult(false, "Invalid login or/and password");
        break;
    case HttpStatus.SC_NOT_FOUND:
        postResult(false, "Wrong path given");
        break;
    default:
        postResult(false, "Internal server error, code: " + login_result);
    }
}

From source file:de.petermoesenthin.alarming.util.FileUtil.java

/**
 * Copies a file to the Alarming directory in the external storage
 *
 * @param context Application context/*w ww . j  a  v a  2  s  .c  om*/
 * @param uri     Uri of file to copy
 */
public static void saveFileToExtAppStorage(final Context context, final Uri uri,
        final OnCopyFinishedListener op) {
    final File applicationDirectory = getApplicationDirectory();
    if (!applicationDirectory.exists()) {
        applicationDirectory.mkdirs();
    }
    File noMedia = new File(applicationDirectory.getPath() + File.separatorChar + ".nomedia");
    if (!noMedia.exists()) {
        try {
            noMedia.createNewFile();
            Log.e(DEBUG_TAG, "Created .nomedia file in: " + noMedia.getAbsolutePath());
        } catch (IOException e) {
            Log.e(DEBUG_TAG, "Unable to create .nomedia file", e);
        }
    }

    String fileName = getFilenameFromUriNoSpace(uri);
    final File destinationFile = new File(applicationDirectory.getPath() + File.separatorChar + fileName);

    Log.d(DEBUG_TAG, "Source file name: " + fileName);
    Log.d(DEBUG_TAG, "Source file uri: " + uri.toString());
    Log.d(DEBUG_TAG, "Destination file: " + destinationFile.getPath());

    Thread copyThread = new Thread(new Runnable() {
        @Override
        public void run() {
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            if (isExternalStorageWritable()) {
                try {
                    InputStream uriStream = context.getContentResolver().openInputStream(uri);
                    bis = new BufferedInputStream(uriStream);
                    bos = new BufferedOutputStream(new FileOutputStream(destinationFile.getPath(), false));
                    byte[] buf = new byte[1024];
                    while (bis.read(buf) != -1) {
                        bos.write(buf);
                    }
                } catch (IOException e) {
                    Log.e(DEBUG_TAG, "Unable to copy file from URI", e);

                } finally {
                    try {
                        if (bis != null)
                            bis.close();
                        if (bos != null)
                            bos.close();
                    } catch (IOException e) {
                        Log.e(DEBUG_TAG, "Unable to close buffers", e);
                    }
                }
            }
            if (op != null) {
                op.onOperationFinished();
            }
        }
    });
    copyThread.start();
}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

/**
 * @param mediaDir media directory path on SD card
 * @return path converted to file URL, properly UTF-8 URL encoded
 *///from w  ww  . j a v  a 2s . c om
public static String getBaseUrl(String mediaDir) {
    // Use android.net.Uri class to ensure whole path is properly encoded
    // File.toURL() does not work here, and URLEncoder class is not directly usable
    // with existing slashes
    if (mediaDir.length() != 0 && !mediaDir.equalsIgnoreCase("null")) {
        Uri mediaDirUri = Uri.fromFile(new File(mediaDir));

        return mediaDirUri.toString() + "/";
    }
    return "";
}

From source file:io.github.pwlin.cordova.plugins.fileopener2.FileOpener2.java

private void _open(String fileArg, String contentType, CallbackContext callbackContext) throws JSONException {
    String fileName = "";
    try {/*from   ww  w .j  a va2s. c  o m*/
        CordovaResourceApi resourceApi = webView.getResourceApi();
        Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg));
        fileName = this.stripFileProtocol(fileUri.toString());
    } catch (Exception e) {
        fileName = fileArg;
    }
    File file = new File(fileName);
    if (file.exists()) {
        try {
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            if (Build.VERSION.SDK_INT >= 24) {

                Context context = cordova.getActivity().getApplicationContext();
                path = FileProvider.getUriForFile(context,
                        cordova.getActivity().getPackageName() + ".opener.provider", file);
                intent.setDataAndType(path, contentType);
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                List<ResolveInfo> infoList = context.getPackageManager().queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : infoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    context.grantUriPermission(packageName, path,
                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            } else {
                intent.setDataAndType(path, contentType);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            }
            /*
             * @see
             * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin
             */
            cordova.getActivity().startActivity(intent);
            //cordova.getActivity().startActivity(Intent.createChooser(intent,"Open File in..."));
            callbackContext.success();
        } catch (android.content.ActivityNotFoundException e) {
            JSONObject errorObj = new JSONObject();
            errorObj.put("status", PluginResult.Status.ERROR.ordinal());
            errorObj.put("message", "Activity not found: " + e.getMessage());
            callbackContext.error(errorObj);
        }
    } else {
        JSONObject errorObj = new JSONObject();
        errorObj.put("status", PluginResult.Status.ERROR.ordinal());
        errorObj.put("message", "File not found");
        callbackContext.error(errorObj);
    }
}

From source file:com.eyekabob.EventInfo.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.artist_info);
    findViewById(R.id.findLiveMusicButton).setOnClickListener(linksListener);
    findViewById(R.id.aboutButton).setOnClickListener(linksListener);
    findViewById(R.id.contactButton).setOnClickListener(linksListener);
    findViewById(R.id.infoTicketsButton).setOnClickListener(linksListener);
    Event event = (Event) getIntent().getExtras().get("event");
    Map<String, String> params = new HashMap<String, String>();
    params.put("event", event.getId());
    Uri uri = EyekabobHelper.LastFM.getUri("event.getInfo", params);
    new RequestTask().execute(uri.toString());
}

From source file:eu.thecoder4.gpl.pleftdroid.HandleLinksActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView tv = new TextView(this);

    tv.setText("Verifying Link...");
    setContentView(tv);/*  w w w .  j  ava  2  s .  c o  m*/

    Intent intent = getIntent();
    if (intent.getAction().equals("android.intent.action.VIEW")) {
        try {
            Uri uri = getIntent().getData();
            theurl = uri.toString();

        } catch (Exception e) {
            Toast.makeText(this, R.string.toast_couldnotopenurl, Toast.LENGTH_LONG).show();
        }
    } else if (Intent.ACTION_SEND.equals(intent.getAction())) {

        Bundle extras = intent.getExtras();
        theurl = extras.getCharSequence(Intent.EXTRA_TEXT).toString();
    } else {
        theurl = "";
    }
    //Toast.makeText(this, "The URL  =  "+theurl, Toast.LENGTH_LONG).show();

    // Parse the URL
    // VERIFICATION: verify?id=&u=&p=
    // INVITATION: a?id=&u=&p=
    if (theurl.indexOf("?") < 0 && theurl.indexOf("/verify?") < 0 && theurl.indexOf("/a?") < 0) {
        Toast.makeText(this, R.string.toast_linknotsupp, Toast.LENGTH_LONG).show();
        finish();
    } else {
        Map<String, String> arr = PleftBroker.getParamsFromURL(theurl);

        pserver = arr.get("pserver");
        if (arr.get("id") != null) {
            aid = Integer.parseInt(arr.get("id"));
        } else {
            aid = 0;
        }
        vcode = arr.get("p");
        user = arr.get("u");
        if (aid == 0 || vcode == null || user == null) {
            Toast.makeText(this, R.string.toast_shlinknotvalid, Toast.LENGTH_LONG).show();
            finish();
        } else { // we have a valid Link

            handleLnk = new Runnable() {
                @Override
                public void run() {
                    handleLink();
                }
            };
            Thread thread = new Thread(null, handleLnk, "Handlethrd");
            thread.start();
        } // End - if Link is Valid
    }
}

From source file:com.example.cuisoap.agrimac.machineRegister.machineInfoFragment.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri uri = data.getData();
        Log.e("uri", uri.toString());
        ContentResolver cr = context.getContentResolver();
        try {// w  w  w  . j  a  v a 2  s  . c  o  m
            Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
            bitmap = ImageUtils.comp(bitmap);
            switch (requestCode) {
            case 1:
                license_pic1.setImageBitmap(bitmap);
                license_path1 = ImageUtils.saveMyBitmap(bitmap, "machineinfo");
                license_pic1.setVisibility(View.VISIBLE);
                license1.setVisibility(View.GONE);
                license_pic1.setOnClickListener(myOnClickListener);
                break;
            case 2:
                license_pic2.setImageBitmap(bitmap);
                license_path2 = ImageUtils.saveMyBitmap(bitmap, "machineinfo");
                license_pic2.setVisibility(View.VISIBLE);
                license2.setVisibility(View.GONE);
                license_pic2.setOnClickListener(myOnClickListener);
                break;
            }
        } catch (FileNotFoundException e) {
            Log.e("Exception", e.getMessage(), e);
        }
    } else {
        Toast.makeText(context, "?", Toast.LENGTH_SHORT).show();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.ofalvai.bpinfo.api.NoticeClient.java

public void fetchNotice(@NonNull final NoticeListener noticeListener, @NonNull final String languageCode) {
    final Uri url = Uri.parse(Config.BACKEND_URL).buildUpon().appendEncodedPath(Config.BACKEND_NOTICE_PATH)
            .build();/*from w  w w.  ja v a 2s.  com*/

    final JsonArrayRequest request = new JsonArrayRequest(url.toString(), new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            onResponseCallback(response, noticeListener, languageCode);
        }
    }, this);

    // Invalidating Volley's cache for this URL to always get the latest notice
    mRequestQueue.getCache().remove(url.toString());
    mRequestQueue.add(request);
}