Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

import android.provider.OpenableColumns;

public class Main {
    public static String uriToString(Context context, Uri uri) {
        String scheme = uri.getScheme();
        if (scheme != null) {
            if (scheme.equals("http") || scheme.equals("https")) {
                return uri.toString();
            } else if (scheme.equals("content") || scheme.equals("file")) {
                Cursor cursor = context.getContentResolver().query(uri,
                        new String[] { OpenableColumns.DISPLAY_NAME }, null, null, null);
                if (cursor.moveToNext()) {
                    String name = cursor.getString(0);
                    cursor.close();
                    return name;
                }
                cursor.close();
                return uri.getPath();
            }
        }
        return uri.toString();
    }
}