Intent 文件存储 找到文件
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
protected void t1() {
int cc = 100;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, cc);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK) {
Uri uri = data.getData();
System.out.println(uri);
Fpath(uri);
}
}
protected void Fpath(Uri uri) {
ContentResolver contentResolver = getContentResolver();
long id = ContentUris.parseId(uri);
// 1. select _id,_data from uri while _id = id;
String[] select = new String[]{"_id","_data"};
Cursor cursor = contentResolver.query(uri, select, "_id = " + id, null, null);
// 2. select * from uri while _id = id;
// Cursor cursor = contentResolver.query(uri, null, "_id = " + id, null, null);
// 3. select * from uri;
// Cursor cursor = contentResolver.query(uri, null, null, null, null);
while (cursor.moveToNext()) {
int cont = cursor.getColumnCount();
for (int i = 0; i < cont; i++) {
System.out.print(cursor.getColumnName(i) + ">> ");
System.out.println(cursor.getString(i));
}
}
}
0 件のコメント:
コメントを投稿