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.example.Bama.chat.chatuidemo.activity.ChatActivity.java

/**
 * ??/*  w  w w. j  a va2 s .c o m*/
 *
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        String st7 = getResources().getString(R.string.File_does_not_exist);
        Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_SHORT).show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m);
        Toast.makeText(getApplicationContext(), st6, Toast.LENGTH_SHORT).show();
        return;
    }

    // ?
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // ?chattype,??
    if (chatType == CHATTYPE_GROUP) {
        message.setChatType(ChatType.GroupChat);
    } else if (chatType == CHATTYPE_CHATROOM) {
        message.setChatType(ChatType.ChatRoom);
    }

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refreshSelectLast();
    setResult(RESULT_OK);
}

From source file:com.silentcircle.contacts.ContactPhotoManagerNew.java

/**
 * Checks if the photo is present in cache.  If so, sets the photo on the view.
 *
 * @return false if the photo needs to be (re)loaded from the provider.
 *//*w  ww .  j  av a2  s.  com*/
private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) {
    BitmapHolder holder = mBitmapHolderCache.get(request.getKey());
    if (holder == null) {
        // The bitmap has not been loaded ==> show default avatar
        request.applyDefaultImage(view, request.mIsCircular);
        return false;
    }

    if (holder.bytes == null) {
        request.applyDefaultImage(view, request.mIsCircular);
        return holder.fresh;
    }

    Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get();
    if (cachedBitmap == null) {
        if (holder.bytes.length < 8 * 1024) {
            // Small thumbnails are usually quick to inflate. Let's do that on the UI thread
            inflateBitmap(holder, request.getRequestedExtent());
            cachedBitmap = holder.bitmap;
            if (cachedBitmap == null)
                return false;
        } else {
            // This is bigger data. Let's send that back to the Loader so that we can
            // inflate this in the background
            request.applyDefaultImage(view, request.mIsCircular);
            return false;
        }
    }

    final Drawable previousDrawable = view.getDrawable();
    if (fadeIn && previousDrawable != null) {
        final Drawable[] layers = new Drawable[2];
        // Prevent cascade of TransitionDrawables.
        if (previousDrawable instanceof TransitionDrawable) {
            final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable;
            layers[0] = previousTransitionDrawable
                    .getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1);
        } else {
            layers[0] = previousDrawable;
        }
        layers[1] = getDrawableForBitmap(mContext.getResources(), cachedBitmap, request);
        TransitionDrawable drawable = new TransitionDrawable(layers);
        view.setImageDrawable(drawable);
        drawable.startTransition(FADE_TRANSITION_DURATION);
    } else {
        view.setImageDrawable(getDrawableForBitmap(mContext.getResources(), cachedBitmap, request));
    }

    // Put the bitmap in the LRU cache. But only do this for images that are small enough
    // (we require that at least six of those can be cached at the same time)
    if (cachedBitmap.getByteCount() < mBitmapCache.maxSize() / 6) {
        mBitmapCache.put(request.getKey(), cachedBitmap);
    }

    // hack: Don't allow resources from external requests to expire easily
    Uri uri = request.getUri();
    if (uri != null) {
        final String scheme = uri.getScheme();
        if (scheme.equals("http") || scheme.equals("https")) {
            holder.fresh = true;
        }
    }

    // Soften the reference
    holder.bitmap = null;

    return holder.fresh;
}

From source file:gc.david.dfm.ui.MainActivity.java

/**
 * Handles a send intent with position data.
 *
 * @param intent Input intent with position data.
 *///from www .ja  v  a 2 s  .  co m
private void handleViewPositionIntent(final Intent intent) throws Exception {
    Mint.leaveBreadcrumb("MainActivity::handleViewPositionIntent");
    final Uri uri = intent.getData();
    Mint.addExtraData("queryParameter", uri.toString());

    final String uriScheme = uri.getScheme();
    if (uriScheme.equals("geo")) {
        final String schemeSpecificPart = uri.getSchemeSpecificPart();
        final Matcher matcher = getMatcherForUri(schemeSpecificPart);
        if (matcher.find()) {
            if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) {
                if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label)
                    setDestinationPosition(matcher);
                } else { // Manage geo:0,0?q=my+street+address
                    String destination = Uri.decode(uri.getQuery()).replace('+', ' ');
                    destination = destination.replace("q=", "");

                    // TODO check this ugly workaround
                    new SearchPositionByName().execute(destination);
                    mustShowPositionWhenComingFromOutside = true;
                }
            } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom
                setDestinationPosition(matcher);
            }
        } else {
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Error al obtener las coordenadas. Matcher = " + matcher.toString());
            Mint.logException(noSuchFieldException);
            throw noSuchFieldException;
        }
    } else if ((uriScheme.equals("http") || uriScheme.equals("https"))
            && (uri.getHost().equals("maps.google.com"))) { // Manage maps.google.com?q=latitude,longitude

        final String queryParameter = uri.getQueryParameter("q");
        if (queryParameter != null) {
            final Matcher matcher = getMatcherForUri(queryParameter);
            if (matcher.find()) {
                setDestinationPosition(matcher);
            } else {
                final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                        "Error al obtener las coordenadas. Matcher = " + matcher.toString());
                Mint.logException(noSuchFieldException);
                throw noSuchFieldException;
            }
        } else {
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Query sin parmetro q.");
            Mint.logException(noSuchFieldException);
            throw noSuchFieldException;
        }
    } else {
        final Exception exception = new Exception("Imposible tratar la query " + uri.toString());
        Mint.logException(exception);
        throw exception;
    }
}

From source file:cn.ucai.yizhesale.activity.ChatActivity.java

/**
 * ??/*w w  w.j  av  a  2s .  c  om*/
 * 
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        String st7 = getResources().getString(cn.ucai.yizhesale.R.string.File_does_not_exist);
        Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_SHORT).show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        String st6 = getResources().getString(cn.ucai.yizhesale.R.string.The_file_is_not_greater_than_10_m);
        Toast.makeText(getApplicationContext(), st6, Toast.LENGTH_SHORT).show();
        return;
    }

    // ?
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // ?chattype,??
    if (chatType == CHATTYPE_GROUP) {
        message.setChatType(ChatType.GroupChat);
    } else if (chatType == CHATTYPE_CHATROOM) {
        message.setChatType(ChatType.ChatRoom);
    }

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);
    if (isRobot) {
        message.setAttribute("em_robot_message", true);
    }
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refreshSelectLast();
    setResult(RESULT_OK);
}

From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java

void initialize() {
    if (android.os.Build.VERSION.SDK_INT >= 9) {
        android.os.StrictMode.ThreadPolicy policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll()
                .build();//from  ww w . j  a v a 2s.  c o m
        android.os.StrictMode.setThreadPolicy(policy);
    }

    handler = new Handler();

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    database = new Database(this);

    Intent i = getIntent();
    connection = null;

    Uri data = i.getData();

    Log.e(TAG, "uri=" + data);

    boolean isSupportedScheme = false;
    if (data != null) {
        String s = data.getScheme();
        isSupportedScheme = s.equals("rdp") || s.equals("spice") || s.equals("vnc");
    }

    if (isSupportedScheme || !Utils.isNullOrEmptry(i.getType())) {
        if (isMasterPasswordEnabled()) {
            Utils.showFatalErrorMessage(this,
                    getResources().getString(R.string.master_password_error_intents_not_supported));
            return;
        }

        connection = ConnectionBean.createLoadFromUri(data, this);

        String host = data.getHost();
        if (!host.startsWith(Constants.CONNECTION)) {
            connection.parseFromUri(data);
        }

        if (connection.isSaved()) {
            connection.saveAndWriteRecent(false);
        }
        // we need to save the connection to display the loading screen, onclso otherwise we should exit
        if (!connection.isReadyForConnection()) {
            if (!connection.isSaved()) {
                Log.i(TAG, "Exiting - Insufficent information to connect and connection was not saved.");
                Toast.makeText(this, getString(R.string.error_uri_noinfo_nosave), Toast.LENGTH_LONG).show();
                ;
            } else {
                // launch bVNC activity
                Log.i(TAG, "Insufficent information to connect, showing connection dialog.");
                Intent bVncIntent = new Intent(this, bVNC.class);
                startActivity(bVncIntent);
            }
            finish();
            return;
        }
    } else {
        connection = new ConnectionBean(this);
        Bundle extras = i.getExtras();

        if (extras != null) {
            connection.Gen_populate((ContentValues) extras.getParcelable(Constants.CONNECTION));
        }

        // Parse a HOST:PORT entry
        String host = connection.getAddress();
        if (!Utils.isValidIpv6Address(host) && host.indexOf(':') > -1) {
            String p = host.substring(host.indexOf(':') + 1);
            try {
                int parsedPort = Integer.parseInt(p);
                connection.setPort(parsedPort);
                connection.setAddress(host.substring(0, host.indexOf(':')));
            } catch (Exception e) {
            }
        }

        if (connection.getPort() == 0)
            connection.setPort(Constants.DEFAULT_VNC_PORT);

        if (connection.getSshPort() == 0)
            connection.setSshPort(Constants.DEFAULT_SSH_PORT);
    }
}

From source file:dk.nota.lyt.libvlc.PlaybackService.java

@MainThread
public void loadUri(Uri uri) {
    String path = uri.toString();
    if (TextUtils.equals(uri.getScheme(), "content")) {
        path = "file://" + Utils.getPathFromURI(uri);
    }/*  w  ww. j a v  a 2s  . c o  m*/
    loadLocation(path);
}

From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && 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)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }//from  www. j  ava  2 s . c o m
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:com.dwdesign.gallery3d.app.ImageViewerGLActivity.java

@Override
public void onClick(final View view) {
    final Uri uri = getIntent().getData();
    switch (view.getId()) {
    case R.id.close: {
        onBackPressed();/*from www. j av a 2  s  . co m*/
        break;
    }
    case R.id.refresh_stop_save: {
        final LoaderManager lm = getSupportLoaderManager();
        if (!mImageLoaded && !lm.hasRunningLoaders()) {
            loadImage();
        } else if (!mImageLoaded && lm.hasRunningLoaders()) {
            stopLoading();
        } else if (mImageLoaded) {
            new SaveImageTask(this, mImageFile).execute();
        }
        break;
    }
    case R.id.share: {
        if (uri == null) {
            break;
        }
        final Intent intent = new Intent(Intent.ACTION_SEND);
        if (mImageFile != null && mImageFile.exists()) {
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImageFile));
        } else {
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, uri.toString());
        }
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case R.id.open_in_browser: {
        if (uri == null) {
            break;
        }
        final String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            try {
                startActivity(intent);
            } catch (final ActivityNotFoundException e) {
                // Ignore.
            }
        }
        break;
    }
    }
}

From source file:com.youti.chat.activity.ChatActivity.java

/**
 * ??// w  w w  .java2  s. c  om
 * 
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        String st7 = getResources().getString(R.string.File_does_not_exist);
        Toast.makeText(getApplicationContext(), st7, 0).show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m);
        Toast.makeText(getApplicationContext(), st6, 0).show();
        return;
    }

    // ?
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // ?chattype,??
    if (chatType == CHATTYPE_GROUP) {
        message.setChatType(ChatType.GroupChat);
    } else if (chatType == CHATTYPE_CHATROOM) {
        message.setChatType(ChatType.ChatRoom);
    }

    message.setReceipt(toTel);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refreshSelectLast();
    setResult(RESULT_OK);
}

From source file:com.wemolian.app.wml.ChatActivity.java

/**
 * ??/*w w w .j  a  v  a2 s  .c  o m*/
 * 
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        Toast.makeText(getApplicationContext(), "?", Toast.LENGTH_SHORT).show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        Toast.makeText(getApplicationContext(), "?10M", Toast.LENGTH_SHORT).show();
        return;
    }

    // ?
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // ?chattype,??
    if (chatType == CHATTYPE_GROUP)
        message.setChatType(ChatType.GroupChat);

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);
    message.setAttribute("toUserNick", toUserCName);
    //message.setAttribute("toUserAvatar", toUserAvatar);
    //message.setAttribute("useravatar", myUserAvatar);
    message.setAttribute(LocalDBKey.CONTACTS_COLUMN_NAME_LABEL, myUserNick);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}