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.breadwallet.presenter.activities.MainActivity.java

private void setUrlHandler(Intent intent) {
    Uri data = intent.getData();
    if (data == null)
        return;/*  www. jav  a 2 s  .c  om*/
    String scheme = data.getScheme();
    if (scheme != null && (scheme.startsWith("bitcoin") || scheme.startsWith("bitid"))) {
        String str = intent.getDataString();
        RequestHandler.processRequest(this, str);
    }
}

From source file:com.ttxgps.zoom.GestureImageView.java

@Override
public void setImageURI(Uri mUri) {
    if ("content".equals(mUri.getScheme())) {
        try {//from w w w .  jav  a 2  s .  co m
            String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION };

            Cursor cur = getContext().getContentResolver().query(mUri, orientationColumn, null, null, null);

            if (cur != null && cur.moveToFirst()) {
                imageOrientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
            }

            InputStream in = null;

            try {
                in = getContext().getContentResolver().openInputStream(mUri);
                Bitmap bmp = BitmapFactory.decodeStream(in);

                if (imageOrientation != 0) {
                    Matrix m = new Matrix();
                    m.postRotate(imageOrientation);
                    Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
                    bmp.recycle();
                    setImageDrawable(new BitmapDrawable(getResources(), rotated));
                } else {
                    setImageDrawable(new BitmapDrawable(getResources(), bmp));
                }
            } finally {
                if (in != null) {
                    in.close();
                }

                if (cur != null) {
                    cur.close();
                }
            }
        } catch (Exception e) {
            Log.w("GestureImageView", "Unable to open content: " + mUri, e);
        }
    } else {
        setImageDrawable(Drawable.createFromPath(mUri.toString()));
    }

    if (drawable == null) {
        Log.e("GestureImageView", "resolveUri failed on bad bitmap uri: " + mUri);
        // Don't try again.
        mUri = null;
    }
}

From source file:com.tandong.sa.sherlock.widget.SuggestionsAdapter.java

/**
 * Gets a drawable by URI, without using the cache.
 * /*  w w  w.  j ava  2  s . com*/
 * @return A drawable, or {@code null} if the drawable could not be loaded.
 */
private Drawable getDrawable(Uri uri) {
    try {
        String scheme = uri.getScheme();
        if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) {
            // Load drawables through Resources, to get the source density
            // information
            try {
                return getTheDrawable(uri);
            } catch (Resources.NotFoundException ex) {
                throw new FileNotFoundException("Resource does not exist: " + uri);
            }
        } else {
            // Let the ContentResolver handle content and file URIs.
            InputStream stream = mProviderContext.getContentResolver().openInputStream(uri);
            if (stream == null) {
                throw new FileNotFoundException("Failed to open " + uri);
            }
            try {
                return Drawable.createFromStream(stream, null);
            } finally {
                try {
                    stream.close();
                } catch (IOException ex) {
                    Log.e(LOG_TAG, "Error closing icon stream for " + uri, ex);
                }
            }
        }
    } catch (FileNotFoundException fnfe) {
        Log.w(LOG_TAG, "Icon not found: " + uri + ", " + fnfe.getMessage());
        return null;
    }
}

From source file:com.android.packageinstaller.PackageInstallerActivity.java

private void processPackageUri(final Uri packageUri) {
    mPackageURI = packageUri;//from   w  ww.  j  a  v  a  2  s .com

    final String scheme = packageUri.getScheme();
    final PackageUtil.AppSnippet as;

    switch (scheme) {
    case SCHEME_PACKAGE: {
        try {
            mPkgInfo = mPm.getPackageInfo(packageUri.getSchemeSpecificPart(),
                    PackageManager.GET_PERMISSIONS | PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (NameNotFoundException e) {
        }
        if (mPkgInfo == null) {
            Log.w(TAG, "Requested package " + packageUri.getScheme()
                    + " not available. Discontinuing installation");
            showDialogInner(DLG_PACKAGE_ERROR);
            setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK);
            return;
        }
        as = new PackageUtil.AppSnippet(mPm.getApplicationLabel(mPkgInfo.applicationInfo),
                mPm.getApplicationIcon(mPkgInfo.applicationInfo));
    }
        break;

    case SCHEME_FILE: {
        File sourceFile = new File(packageUri.getPath());
        PackageParser.Package parsed = PackageUtil.getPackageInfo(sourceFile);

        // Check for parse errors
        if (parsed == null) {
            Log.w(TAG, "Parse error when parsing manifest. Discontinuing installation");
            showDialogInner(DLG_PACKAGE_ERROR);
            setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK);
            return;
        }
        mPkgInfo = PackageParser.generatePackageInfo(parsed, null, PackageManager.GET_PERMISSIONS, 0, 0, null,
                new PackageUserState());
        as = PackageUtil.getAppSnippet(this, mPkgInfo.applicationInfo, sourceFile);
    }
        break;

    case SCHEME_CONTENT: {
        mStagingAsynTask = new StagingAsyncTask();
        mStagingAsynTask.execute(packageUri);
        return;
    }

    default: {
        Log.w(TAG, "Unsupported scheme " + scheme);
        setPmResult(PackageManager.INSTALL_FAILED_INVALID_URI);
        clearCachedApkIfNeededAndFinish();
        return;
    }
    }

    PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet);

    initiateInstall();
}

From source file:net.sourceforge.servestream.fragment.UrlListFragment.java

private boolean processUri(String input) {
    Uri uri = TransportFactory.getUri(input);

    if (uri == null) {
        return false;
    }//from  w  w  w.ja v a 2s  .  c  om

    UriBean uriBean = TransportFactory.findUri(mStreamdb, uri);
    if (uriBean == null) {
        uriBean = TransportFactory.getTransport(uri.getScheme()).createUri(uri);

        AbsTransport transport = TransportFactory.getTransport(uriBean.getProtocol());
        transport.setUri(uriBean);
        if (mPreferences.getBoolean(PreferenceConstants.AUTOSAVE, true)) {
            mStreamdb.saveUri(uriBean);
            updateList();
        }
    }

    showDialog(LOADING_DIALOG);
    mDetermineActionTask = new DetermineActionTask(getActivity(), uriBean, this);
    mDetermineActionTask.execute();

    return true;
}

From source file:com.andrew.apollo.utils.MusicUtils.java

/**
 * @param uri The source of the file/*from  w ww. j  a v  a  2  s . c  om*/
 */
public static void playFile(final Uri uri) {
    // TODO: Check for PHONE_STATE Permissions here.

    if (uri == null || mService == null) {
        return;
    }

    // If this is a file:// URI, just use the path directly instead
    // of going through the open-from-file descriptor code path.
    String filename;
    String scheme = uri.getScheme();
    if ("file".equals(scheme)) {
        filename = uri.getPath();
    } else {
        filename = uri.toString();
    }

    try {
        mService.stop();
        mService.openFile(filename);
        mService.play();
    } catch (final RemoteException ignored) {
    }
}

From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java

/**
 * Get a {@link InputStream} from {@link Uri}.
 * //from   www  .ja va 2 s  .com
 * @param cr
 *            {@link ContentResolver}
 * @param uri
 *            {@link Uri}
 * @return {@link InputStream}
 */
private InputStream getStream(final ContentResolver cr, final Uri uri) {
    if (uri.toString().startsWith("import")) {
        String url;
        if (uri.getScheme().equals("imports")) {
            url = "https:/";
        } else {
            url = "http:/";
        }
        url += uri.getPath();
        final HttpGet request = new HttpGet(url);
        Log.d(TAG, "url: " + url);
        try {
            final HttpResponse response = new DefaultHttpClient().execute(request);
            int resp = response.getStatusLine().getStatusCode();
            if (resp != HttpStatus.SC_OK) {
                return null;
            }
            return response.getEntity().getContent();
        } catch (IOException e) {
            Log.e(TAG, "error in reading export: " + url, e);
            return null;
        }
    } else if (uri.toString().startsWith("content://") || uri.toString().startsWith("file://")) {
        try {
            return cr.openInputStream(uri);
        } catch (IOException e) {
            Log.e(TAG, "error in reading export: " + uri.toString(), e);
            return null;
        }
    }
    Log.d(TAG, "getStream() returns null, " + uri.toString());
    return null;
}

From source file:in.shick.diode.submit.SubmitLinkActivity.java

private boolean lastDitchExtractProperties(Bundle extras, SubmissionProperties properties) {
    if (extras != null) {
        // find the most likely submission URL since some
        // programs share more than the URL
        // the most likely is considered to be the longest
        // string token with a URI scheme of http or https
        StringBuilder titleBuilder = new StringBuilder();
        String rawText = extras.getString(Intent.EXTRA_TEXT);
        StringTokenizer extraTextTokenizer = new StringTokenizer(rawText);
        Uri bestUri = Uri.parse("");
        while (extraTextTokenizer.hasMoreTokens()) {
            Uri uri = Uri.parse(extraTextTokenizer.nextToken());
            if (!"http".equalsIgnoreCase(uri.getScheme()) && !"https".equalsIgnoreCase(uri.getScheme())) {
                titleBuilder.append(uri.toString()).append(' ');
                continue;
            }/*from  w w w .  ja v  a2  s . c o  m*/
            if (uri.toString().length() > bestUri.toString().length()) {
                bestUri = uri;
            }
        }

        properties = new SubmissionProperties();
        properties.url = bestUri.toString();
        properties.title = titleBuilder.toString();

        return true;
    }

    return false;
}

From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @return              "" if ok, or error message.
 */// w  w  w.jav a 2 s.  c  om
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url " + url + ":" + e.toString());
        return e.toString();
    }
}

From source file:com.xabber.android.ui.activity.ContactList.java

@Override
protected void onResume() {
    super.onResume();
    barPainter.setDefaultColor();/*www  .  j  av a 2s  .c o  m*/
    rebuildAccountToggle();
    Application.getInstance().addUIListener(OnAccountChangedListener.class, this);

    if (action != null) {
        switch (action) {
        case ContactList.ACTION_ROOM_INVITE:
        case Intent.ACTION_SEND:
        case Intent.ACTION_CREATE_SHORTCUT:
            if (Intent.ACTION_SEND.equals(action)) {
                sendText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
            }
            Toast.makeText(this, getString(R.string.select_contact), Toast.LENGTH_LONG).show();
            break;
        case Intent.ACTION_VIEW: {
            action = null;
            Uri data = getIntent().getData();
            if (data != null && "xmpp".equals(data.getScheme())) {
                XMPPUri xmppUri;
                try {
                    xmppUri = XMPPUri.parse(data);
                } catch (IllegalArgumentException e) {
                    xmppUri = null;
                }
                if (xmppUri != null && "message".equals(xmppUri.getQueryType())) {
                    ArrayList<String> texts = xmppUri.getValues("body");
                    String text = null;
                    if (texts != null && !texts.isEmpty()) {
                        text = texts.get(0);
                    }
                    openChat(xmppUri.getPath(), text);
                }
            }
            break;
        }
        case Intent.ACTION_SENDTO: {
            action = null;
            Uri data = getIntent().getData();
            if (data != null) {
                String path = data.getPath();
                if (path != null && path.startsWith("/")) {
                    openChat(path.substring(1), null);
                }
            }
            break;
        }

        case ContactList.ACTION_MUC_PRIVATE_CHAT_INVITE:
            action = null;
            showMucPrivateChatDialog();
            break;

        case ContactList.ACTION_CONTACT_SUBSCRIPTION:
            action = null;
            showContactSubscriptionDialog();
            break;

        case ContactList.ACTION_INCOMING_MUC_INVITE:
            action = null;
            showMucInviteDialog();
            break;

        }
    }

    if (Application.getInstance().doNotify()) {
        if (!SettingsManager.isTranslationSuggested()) {
            Locale currentLocale = getResources().getConfiguration().locale;
            if (!currentLocale.getLanguage().equals("en") && !getResources().getBoolean(R.bool.is_translated)) {
                new TranslationDialog().show(getFragmentManager(), "TRANSLATION_DIALOG");
                SettingsManager.setTranslationSuggested();
            }
        }

        if (SettingsManager.bootCount() > 2 && !SettingsManager.connectionStartAtBoot()
                && !SettingsManager.startAtBootSuggested()) {
            StartAtBootDialogFragment.newInstance().show(getFragmentManager(), "START_AT_BOOT");
        }

        if (SettingsManager.interfaceTheme() != SettingsManager.InterfaceTheme.dark) {
            if (!SettingsManager.isDarkThemeSuggested() && SettingsManager.bootCount() > 0) {
                new DarkThemeIntroduceDialog().show(getFragmentManager(),
                        DarkThemeIntroduceDialog.class.getSimpleName());
                SettingsManager.setDarkThemeSuggested();
            }
        } else {
            SettingsManager.setDarkThemeSuggested();
        }

        if (!SettingsManager.contactIntegrationSuggested() && Application.getInstance().isContactsSupported()) {
            if (AccountManager.getInstance().getAllAccounts().isEmpty()) {
                SettingsManager.setContactIntegrationSuggested();
            } else {
                ContactIntegrationDialogFragment.newInstance().show(getFragmentManager(),
                        "CONTACT_INTEGRATION");
            }
        }
    }
}