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:net.wequick.small.Bundle.java

protected static Bundle getLaunchableBundle(Uri uri) {
    if (sPreloadBundles != null) {
        for (Bundle bundle : sPreloadBundles) {
            if (bundle.matchesRule(uri)) {
                if (!bundle.enabled)
                    return null; // Illegal bundle (invalid signature, etc.)
                return bundle;
            }//from   www .  j a  v a  2  s .c om
        }
    }

    // Downgrade to show webView
    if (uri.getScheme() != null) {
        Bundle bundle = new Bundle();
        try {
            bundle.url = new URL(uri.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        bundle.prepareForLaunch();
        bundle.setQuery(uri.getEncodedQuery()); // Fix issue #6 from Spring-Xu.
        bundle.mApplicableLauncher = new WebBundleLauncher();
        bundle.mApplicableLauncher.prelaunchBundle(bundle);
        return bundle;
    }
    return null;
}

From source file:im.ene.lab.attiq.ui.activities.DeepLinkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Uri data = getIntent().getData();
    String scheme = data.getScheme();
    List<String> paths = data.getPathSegments();
    if (SCHEME_INTERNAL.equals(scheme)) {
        if (!UIUtil.isEmpty(paths)) {
            if (TYPE_TAG.equals(paths.get(0))) {
                String lastPath = data.getLastPathSegment();
                TaskStackBuilder.create(this).addParentStack(TagItemsActivity.class)
                        .addNextIntent(TagItemsActivity.createIntent(this, lastPath)).startActivities();
            } else if (TYPE_USER.equals(paths.get(0))) {
                String lastPath = data.getLastPathSegment();
                startActivity(ProfileActivity.createIntent(this, lastPath));
            }//from  w  w w  .j  a v a 2 s.  c om
        }
    } else if (SCHEME_HTTP.equals(scheme) || SCHEME_HTTPS.equals(scheme)) {
        if (!UIUtil.isEmpty(paths)) {
            Iterator<String> iterator = paths.iterator();
            String id = null;
            while (iterator.hasNext()) {
                if (TYPE_ITEMS.equals(iterator.next())) {
                    id = iterator.next();
                    break;
                }
            }

            if (id != null) {
                TaskStackBuilder.create(this).addParentStack(ItemDetailActivity.class)
                        .addNextIntent(ItemDetailActivity.createIntent(this, id)).startActivities();
                // startActivity(ItemDetailActivity.createIntent(this, id));
            }
        }
    }

    finish();
}

From source file:de.k3b.android.toGoZip.ZipStorageDocumentFile.java

public static String getPath(final Context context, final Uri uri) {
    // DocumentProvider
    if (Global.USE_DOCUMENT_PROVIDER && DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                final File externalStorageDirectory = Environment.getExternalStorageDirectory();

                // split[1] results in index out of bound exception in storage root dir
                if (split.length == 1)
                    return externalStorageDirectory.toString();
                return externalStorageDirectory + "/" + split[1];
            }/*from w w w.j  ava 2s  .co m*/

            // TODO handle non-primary volumes
        }
    }
    if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
    return null;
}

From source file:ca.rmen.android.networkmonitor.app.savetostorage.SaveToStorageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(TAG, "onCreate: bundle=" + savedInstanceState);
    if (savedInstanceState == null) {
        Parcelable extra = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
        if (extra == null || !(extra instanceof Uri)) {
            SaveToStorage.displayErrorToast(this);
            return;
        }//from   w  ww .j a v a2 s .com

        Uri sourceFileUri = (Uri) extra;
        if (!"file".equals(sourceFileUri.getScheme())) {
            SaveToStorage.displayErrorToast(this);
            return;
        }

        if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            SaveToStorage.displayErrorToast(this);
            return;
        }
        File initialFolder = NetMonPreferences.getInstance(this).getExportFolder();
        DialogFragmentFactory.showFileChooserDialog(this, initialFolder, true, ACTION_SAVE_TO_STORAGE);
    }

}

From source file:org.apache.cordova.camera.CordovaUri.java

CordovaUri(Uri inputUri) {
    //Determine whether the file is a content or file URI
    if (inputUri.getScheme().equals("content")) {
        androidUri = inputUri;//from w  ww  .j  a  v a  2s  . c  o m
        fileName = getFileNameFromUri(androidUri);
        fileUri = Uri.parse("file://" + fileName);
    } else {
        fileUri = inputUri;
        fileName = FileHelper.stripFileProtocol(inputUri.toString());
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.StatusObj.java

@Override
public void activate(Context context, SignedObj obj) {
    //linkify should have picked it up already but if we are in TV mode we
    //still need to activate
    Intent intent = new Intent(Intent.ACTION_VIEW);
    String text = obj.getJson().optString(TEXT);

    //launch the first thing that looks like a link
    Matcher m = p.matcher(text);/*from  w w w . ja  v  a2s.c om*/
    while (m.find()) {
        Uri uri = Uri.parse(m.group());
        String scheme = uri.getScheme();

        if (scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) {
            intent.setData(uri);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
            return;
        }
    }
}

From source file:com.commonsware.android.documents.consumer.DurablizerService.java

private DocumentFile buildDocFileForUri(Uri document) {
    DocumentFile docFile;/*w  w w.  j ava2 s.c  om*/

    if (document.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
        docFile = DocumentFile.fromSingleUri(this, document);
    } else {
        docFile = DocumentFile.fromFile(new File(document.getPath()));
    }

    return (docFile);
}

From source file:com.lewie9021.videothumbnail.VideoThumbnail.java

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {/*www . j  a  va2s. com*/
        // Action is 'create'
        if (action.equals("create")) {
            Uri fileURI = Uri.fromFile(new File(args.getString(0)));
            String filePath = args.getString(0).replace(fileURI.getScheme() + ":", "");
            Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);

            callbackContext.success(encodeTobase64(thumbnail));
            return true;
        } else {
            callbackContext.error("Invalid action");
            return false;
        }
    } catch (JSONException e) {
        callbackContext.error("JSON Exception");
        return true;
    }
}

From source file:br.com.hotforms.usewaze.UseWaze.java

private void callWaze(final String url) {
    final Activity activity = this.cordova.getActivity();
    activity.runOnUiThread(new Runnable() {
        @Override//  w  ww .ja  v  a  2 s .  co  m
        public void run() {
            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);
                }

                activity.startActivity(intent);
            } catch (ActivityNotFoundException ex) {
                String urlMarket = "market://details?id=com.waze";
                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(urlMarket);
                if ("file".equals(uri.getScheme())) {
                    intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
                } else {
                    intent.setData(uri);
                }

                activity.startActivity(intent);
            }
        }
    });
}

From source file:Main.java

/**
 * Get the real file path from URI registered in media store 
 * @param contentUri URI registered in media store 
 *///w  w  w.j av  a  2  s  .c  om
public static String getRealPathFromURI(Activity activity, Uri contentUri) {

    String releaseNumber = Build.VERSION.RELEASE;

    if (releaseNumber != null) {
        /* ICS, JB Version */
        if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') {
            // URI from Gallery(MediaStore)
            String[] proj = { MediaStore.Images.Media.DATA };
            String strFileName = "";
            CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null);
            Cursor cursor = cursorLoader.loadInBackground();
            if (cursor != null) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                if (cursor.getCount() > 0)
                    strFileName = cursor.getString(column_index);

                cursor.close();
            }
            // URI from Others(Dropbox, etc.) 
            if (strFileName == null || strFileName.isEmpty()) {
                if (contentUri.getScheme().compareTo("file") == 0)
                    strFileName = contentUri.getPath();
            }
            return strFileName;
        }
        /* GB Version */
        else if (releaseNumber.startsWith("2.3")) {
            // URI from Gallery(MediaStore)
            String[] proj = { MediaStore.Images.Media.DATA };
            String strFileName = "";
            Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null);
            if (cursor != null) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

                cursor.moveToFirst();
                if (cursor.getCount() > 0)
                    strFileName = cursor.getString(column_index);

                cursor.close();
            }
            // URI from Others(Dropbox, etc.) 
            if (strFileName == null || strFileName.isEmpty()) {
                if (contentUri.getScheme().compareTo("file") == 0)
                    strFileName = contentUri.getPath();
            }
            return strFileName;
        }
    }

    //---------------------
    // Undefined Version
    //---------------------
    /* GB, ICS Common */
    String[] proj = { MediaStore.Images.Media.DATA };
    String strFileName = "";
    Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null);
    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

        // Use the Cursor manager in ICS         
        activity.startManagingCursor(cursor);

        cursor.moveToFirst();
        if (cursor.getCount() > 0)
            strFileName = cursor.getString(column_index);

        //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version)
        activity.stopManagingCursor(cursor);
    }
    return strFileName;
}