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.anhubo.anhubo.ui.activity.unitDetial.UploadingActivity1.java

@TargetApi(19)
private Bitmap handleImageOnKitKat(Intent data) {
    String imagePath = null;/* www.ja  va  2  s .c o  m*/
    Uri uri = data.getData();
    Log.d("TAG", "handleImageOnKitKat: uri is " + uri);
    if (DocumentsContract.isDocumentUri(this, uri)) {
        // documentUridocument id?
        String docId = DocumentsContract.getDocumentId(uri);
        if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
            String id = docId.split(":")[1]; // ??id
            String selection = MediaStore.Images.Media._ID + "=" + id;
            imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
        } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(docId));
            imagePath = getImagePath(contentUri, null);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        // contentUri??
        imagePath = getImagePath(uri, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        // fileUri???
        imagePath = uri.getPath();
    }
    Bitmap bitmap = displayImage(imagePath);// ?
    return bitmap;
}

From source file:Main.java

public static String getPathFromUri(final Context context, final Uri uri) {

    //        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    //        if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
    //            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];
    //                }
    //            }
    //            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];
    ///*  ww w  .j  av  a 2 s  . c o m*/
    //                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);
    //            }
    //        }
    //        else
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        return getDataColumn(context, uri, null, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:com.android.dialer.DialtactsActivity.java

/** Returns true if the given intent contains a phone number to populate the dialer with */
private boolean isDialIntent(Intent intent) {
    final String action = intent.getAction();
    if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
        return true;
    }/*from  w  ww  .ja  v  a  2  s. c  om*/
    if (Intent.ACTION_VIEW.equals(action)) {
        final Uri data = intent.getData();
        if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
            return true;
        }
    }
    return false;
}

From source file:app.view.chat.ChatActivity.java

/**
 * ??//from w  ww  .j  av  a  2  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()) {
        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);

    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java

/**
 * Opens the binary input stream from a HEX file. A Uri to the stream is given
 * /*w ww .j  ava  2s .  c om*/
 * @param stream
 *            the Uri to the stream
 * @return the binary input stream with Intel HEX data
 * @throws FileNotFoundException
 */
private HexInputStream openInputStream(final Uri stream) throws FileNotFoundException, IOException {
    if (stream.getScheme().equals("http")) {
        return new HexInputStream(new HttpGet(stream.toString()));
    }
    return new HexInputStream(getContentResolver().openInputStream(stream));
}

From source file:Main.java

public static String getPath(final Context context, final Uri uri) {

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

    // DocumentProvider
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        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   w  w  w  .ja  v  a2 s.c  o m*/

                // TODO handle non-primary volumes
            }
            // 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 getDataColumn(context, uri, null, null);
        }
        // File
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }
    }

    return null;
}

From source file:niltor.net.chatuidemo.activity.ChatActivity.java

/**
 * ??/*from w  w  w .  ja 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()) {
        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(EMMessage.ChatType.GroupChat);

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);

    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

public String getPath(Context context, Uri uri) throws URISyntaxException {
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;/*ww w .jav a2  s .  co m*/

        try {
            cursor = context.getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                return cursor.getString(column_index);
            }
        } catch (Exception e) {
            // Eat it
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:com.iiordanov.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  ava 2 s  . com*/
        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();

    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, so 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 (host.indexOf(':') > -1) {
            String p = host.substring(host.indexOf(':') + 1);
            try {
                connection.setPort(Integer.parseInt(p));
            } catch (Exception e) {
            }
            connection.setAddress(host.substring(0, host.indexOf(':')));
        }

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

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

From source file:com.liangxun.university.huanxin.chat.activity.ChatOldActivity.java

/**
 * ??//from   w w  w.j a v  a  2  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);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}