Example usage for android.net Uri getScheme

List of usage examples for android.net Uri getScheme

Introduction

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

Prototype

@Nullable
public abstract String getScheme();

Source Link

Document

Gets the scheme of this URI.

Usage

From source file:com.teclib.flyvemdm.MainActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);

    if (result.getContents() == null) {
        Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
    } else {//  w  w  w  .  j  a  v  a  2  s. c  o  m
        String contents = result.getContents();
        FlyveLog.d(contents);
        try {
            JSONObject jsonObj = new JSONObject(contents);
            if (jsonObj.has("url")) {
                Uri uri = Uri.parse(jsonObj.getString("url"));
                apiUrl = jsonObj.getString("url");
                apiUserToken = jsonObj.getString("user_token");
                String protocol = uri.getScheme();
                msharedPreferenceSettings.saveProtocol(getBaseContext(), protocol);
            }

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

        Intent LoginIntent = new Intent(this.getBaseContext(), LoginActivity.class);
        LoginIntent.putExtra("link", contents);
        startActivity(LoginIntent);
        finish();
    }
}

From source file:org.amahi.anywhere.service.UploadService.java

private String queryImagePath(Uri imageUri) {
    String filePath = null;//from  w w  w  .  ja  va  2s. co m
    if ("content".equals(imageUri.getScheme())) {
        Cursor cursor = this.getContentResolver().query(imageUri, null, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
            filePath = cursor.getString(columnIndex);
            cursor.close();
        }
    } else {
        filePath = imageUri.toString();
    }
    return filePath;
}

From source file:de.schildbach.wallet.ui.backup.BackupWalletDialogFragment.java

private @Nullable String uriToTarget(final Uri uri) {
    if (!uri.getScheme().equals("content"))
        return null;
    final String host = uri.getHost();
    if ("com.google.android.apps.docs.storage".equals(host))
        return "Google Drive";
    if ("com.android.providers.downloads.documents".equals(host))
        return "internal storage";
    return null;/*from  ww  w.j a  v a2 s.  c  om*/
}

From source file:com.commonsware.android.tte.DocumentStorageService.java

private void load(Uri document) {
    try {/*w  w  w  .j a v a 2  s.  com*/
        boolean weHavePermission = false;
        boolean isContent = ContentResolver.SCHEME_CONTENT.equals(document.getScheme());

        if (isContent) {
            int perms = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION;

            getContentResolver().takePersistableUriPermission(document, perms);

            for (UriPermission perm : getContentResolver().getPersistedUriPermissions()) {
                if (perm.getUri().equals(document)) {
                    weHavePermission = true;
                }
            }
        } else {
            weHavePermission = true;
        }

        if (weHavePermission) {
            try {
                InputStream is = getContentResolver().openInputStream(document);

                try {
                    String text = slurp(is);
                    DocumentFile docFile;

                    if (isContent) {
                        docFile = DocumentFile.fromSingleUri(this, document);
                    } else {
                        docFile = DocumentFile.fromFile(new File(document.getPath()));
                    }

                    EventBus.getDefault().post(
                            new DocumentLoadedEvent(document, text, docFile.getName(), docFile.canWrite()));
                } finally {
                    is.close();
                }
            } catch (Exception e) {
                Log.e(getClass().getSimpleName(), "Exception loading " + document.toString(), e);
                EventBus.getDefault().post(new DocumentLoadErrorEvent(document, e));
            }
        } else {
            Log.e(getClass().getSimpleName(), "We failed to get permissions for " + document.toString());
            EventBus.getDefault().post(new DocumentPermissionFailureEvent(document));
        }
    } catch (SecurityException e) {
        Log.e(getClass().getSimpleName(), "Exception getting permissions for " + document.toString(), e);
        EventBus.getDefault().post(new DocumentPermissionFailureEvent(document));
    }
}

From source file:com.redoceanred.unity.android.RORAudioPlayer.java

/**
 * ???.// w ww.  ja va  2 s  .c o  m
 */
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
    case REQUEST_PICK_AUDIO:
        if (resultCode != Activity.RESULT_OK) {
            // ????.
            return false;
        }
        Uri dataUri = data.getData();
        String scheme = dataUri.getScheme();
        mAudioFilePath = "";
        if (scheme.startsWith("content")) {
            mAudioFilePath = getRealPathFromURI(dataUri);
            Log.d(TAG, "content -> " + mAudioFilePath);
        } else if (scheme.startsWith("file")) {
            mAudioFilePath = dataUri.toString().substring("file://".length());
            Log.d(TAG, "file -> " + mAudioFilePath);
        } else {
            Log.e(TAG, "scheme do not know. " + scheme);
            return false;
        }
        setDataSource();
        return true;
    }
    return false;
}

From source file:com.weiboa.activity.SignInActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Uri uri = intent.getData();
    if (uri != null) {

        if (OAuthConntect.CALLBACK_URL.getScheme().equals(uri.getScheme())) {

            getIntent().setData(null);//from w  w  w .  j  a  va  2s.  com
            boolean isAuthenticated = mOAuthConntect.getAccessToken(uri, mDb);
            if (isAuthenticated) {
                new VerifyCredentialTask().execute();
            }
        }
    }

    super.onNewIntent(intent);
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.MainActivity.java

@Override
public void onLevelstateChange(Levelstate new_state, int level) {
    Uri data = getIntent().getData();
    if (new_state == Levelstate.finished && data != null && data.getScheme().equals("phishedu")) {
        Bundle args = new Bundle();
        args.putInt(Constants.ARG_LEVEL, level);
        switchToFragment(LevelFinishedActivity.class, args);
    }/*from   www  .j  a v  a2  s  .  co  m*/
}

From source file:com.github.guwenk.smuradio.SignInDialog.java

public String getFileName(Uri uri) {
    String result = null;//from  w w w  .  ja v a2 s . c o m
    if (uri.getScheme().equals("content")) {
        Cursor cursor = getActivity().getContentResolver().query(uri, null, null, null, null);
        try {
            if (cursor != null && cursor.moveToFirst()) {
                result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
            }
        } finally {
            cursor.close();
        }
    }
    if (result == null) {
        result = uri.getPath();
        int cut = result.lastIndexOf('/');
        if (cut != -1) {
            result = result.substring(cut + 1);
        }
    }
    return result;
}

From source file:mobisocial.musubi.util.UriImage.java

private InputStream openInputStream(Uri uri) throws IOException {
    String scheme = uri.getScheme();
    if ("content".equals(scheme)) {
        return mContext.getContentResolver().openInputStream(mUri);
    } else if (scheme.startsWith("http")) {
        if (mByteCache == null) {
            DefaultHttpClient c = new DefaultHttpClient();
            HttpGet get = new HttpGet(uri.toString());
            HttpResponse response = c.execute(get);
            mByteCache = IOUtils.toByteArray(response.getEntity().getContent());
        }/*from   w w  w .  j a va 2 s . co m*/
        return new ByteArrayInputStream(mByteCache);
    } else if (scheme.equals("file")) {
        return new FileInputStream(uri.getPath());
    } else {
        throw new IOException("Unmatched uri scheme " + scheme);
    }
}

From source file:com.galois.qrstream.MainActivity.java

private Job buildJobFromIntent(Intent intent) throws IllegalArgumentException {
    String type = intent.getType();
    Bundle extras = intent.getExtras();//from   w  ww  . j  av  a 2s .  c  o m
    Log.d(Constants.APP_TAG, "** received type " + type);

    String name = "";
    byte[] bytes = null;

    Uri dataUrl = (Uri) intent.getExtras().getParcelable(Intent.EXTRA_STREAM);
    if (dataUrl != null) {
        name = getNameFromURI(dataUrl);
        if (dataUrl.getScheme().equals("content") || dataUrl.getScheme().equals("file")) {
            try {
                bytes = readFileUri(dataUrl);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            Log.d(Constants.APP_TAG, "unsupported url: " + dataUrl);
        }
    } else {
        // fall back to content in extras (mime type dependent)
        if (type.equals("text/plain")) {
            String subject = extras.getString(Intent.EXTRA_SUBJECT);
            String text = extras.getString(Intent.EXTRA_TEXT);
            if (subject == null) {
                bytes = text.getBytes();
            } else {
                bytes = encodeSubjectAndText(subject, text);
                type = Constants.MIME_TYPE_TEXT_NOTE;
            }
        }
    }
    return new Job(name, bytes, type);
}