Android中通过uri查询数据库字段

来源:互联网 发布:淘宝魔镜 编辑:程序博客网 时间:2024/06/07 05:20

      实例:通过uri 查询  MediaStore.MediaColumns.DATA字段:

                  Cursor c = context.getContentResolver().query(uri, new String[] {MediaStore.MediaColumns.DATA}, null, null, null);
                    if (c != null) {
                        try {
                            int numrows = c.getCount();
                            if (numrows == 1) {
                                c.moveToFirst();
                                oldPath = c.getString(0);
                                Log.i(TAG, "oldPath = '" + oldPath + "'");
                            } else {
                                Log.e(TAG, "" + numrows + " rows for " + uri);
                            }
                        } finally {
                            c.close();
                        }
                    }

0 0