Search in sources :

Example 56 with Cursor

use of android.database.Cursor in project jpHolo by teusink.

the class FileHelper method getRealPath.

/**
     * Returns the real path of the given URI string.
     * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
     *
     * @param uriString the URI string of the audio/image/video
     * @param cordova the current application context
     * @return the full path to the file
     */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;
    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }
    return realPath;
}
Also used : Cursor(android.database.Cursor)

Example 57 with Cursor

use of android.database.Cursor in project cordova-android-chromeview by thedracle.

the class FileHelper method getRealPath.

/**
     * Returns the real path of the given URI string.
     * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
     *
     * @param uriString the URI string of the audio/image/video
     * @param cordova the current application context
     * @return the full path to the file
     */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;
    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }
    return realPath;
}
Also used : Cursor(android.database.Cursor)

Example 58 with Cursor

use of android.database.Cursor in project cordova-android-chromeview by thedracle.

the class ContactAccessorSdk5 method remove.

@Override
public /**
     * This method will remove a Contact from the database based on ID.
     * @param id the unique ID of the contact to remove
     */
boolean remove(String id) {
    int result = 0;
    Cursor cursor = mApp.getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts._ID + " = ?", new String[] { id }, null);
    if (cursor.getCount() == 1) {
        cursor.moveToFirst();
        String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
        result = mApp.getActivity().getContentResolver().delete(uri, null, null);
    } else {
        Log.d(LOG_TAG, "Could not find contact with ID");
    }
    return (result > 0) ? true : false;
}
Also used : Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 59 with Cursor

use of android.database.Cursor in project glimmr by brk3.

the class LocalPhotosGridFragment method initGridView.

@Override
protected void initGridView() {
    mGridView = (GridView) mLayout.findViewById(R.id.gridview);
    mGridView.setVisibility(View.VISIBLE);
    mGridView.setMultiChoiceModeListener(this);
    mShowDetailsOverlay = false;
    String[] from = { MediaStore.MediaColumns.TITLE };
    int[] to = { android.R.id.text1 };
    CursorLoader cursorLoader = new CursorLoader(getActivity(), SOURCE_URI, null, null, null, MediaStore.Audio.Media.TITLE);
    Cursor cursor = cursorLoader.loadInBackground();
    mAdapter = new MediaStoreImagesAdapter(getActivity(), R.layout.gridview_item, cursor, from, to);
    mGridView.setAdapter(mAdapter);
    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        final String usageTip = getString(R.string.upload_photos_tip);

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            UsageTips.getInstance().show(mActivity, usageTip, true);
        }
    });
}
Also used : Cursor(android.database.Cursor) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) CursorLoader(android.content.CursorLoader) AdapterView(android.widget.AdapterView)

Example 60 with Cursor

use of android.database.Cursor in project FileDownloaderManager by arlyxiao.

the class SystemDownloadActivity method update_progress.

public void update_progress() {
    int[] bytes_and_status = new int[] { -1, -1, 0 };
    DownloadManager.Query query = new DownloadManager.Query().setFilterById(download_id);
    Cursor c = null;
    try {
        c = downloadmanager.query(query);
        if (c != null && c.moveToFirst()) {
            bytes_and_status[0] = c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
            Log.i("到目前为止下载的大小 ", Integer.toString(bytes_and_status[0]));
            bytes_and_status[1] = c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
            Log.i("总大小 ", Integer.toString(bytes_and_status[0]));
            bytes_and_status[2] = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
            Log.i("下载状态 ", Integer.toString(bytes_and_status[0]));
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    handler.sendMessage(handler.obtainMessage(0, bytes_and_status[0], bytes_and_status[1], bytes_and_status[2]));
}
Also used : Cursor(android.database.Cursor) DownloadManager(android.app.DownloadManager)

Aggregations

Cursor (android.database.Cursor)4002 ArrayList (java.util.ArrayList)547 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)527 Uri (android.net.Uri)467 ContentValues (android.content.ContentValues)334 ContentResolver (android.content.ContentResolver)193 Test (org.junit.Test)183 RemoteException (android.os.RemoteException)182 File (java.io.File)170 IOException (java.io.IOException)159 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)140 SQLException (android.database.SQLException)126 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 HashMap (java.util.HashMap)108 SQLiteException (android.database.sqlite.SQLiteException)94 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)93 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75