2017-05-11 68 views
0

我想從光標獲取圖像。我使用Mediastor.image.data 這裏是我的代碼如何從android中的光標獲取圖像?

String los=getArguments().getString(ARG_SECTION_NUMBER1); 
     Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 





    final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_ADDED}; 
     ContentResolver mContentResolver = rootView.getContext().getContentResolver(); 

     Cursor mCursor = mContentResolver.query(mImageUri, columns, MediaStore.Images.Media.DATA + " like ? ",new String[] {los}, null); 

回答

0

//你UserContract類

public class UserContract { 

public static abstract class NewUserInfo 
{ 

     public static final String IMAGE = "image"; 

}} 

//在你dbhelper類

public DataProvider getInformations() 
{ 
    ArrayList<DataProvider> ListViewValuesArr = new ArrayList<DataProvider>(); 
    SQLiteDatabase db = this.getReadableDatabase(); 
    Cursor res = db.rawQuery("select " +UserContract.NewUserInfo.IMAGE+" from "+UserContract.NewUserInfo.TABLE_NAME, null); 
    res.moveToFirst(); 
    DataProvider dataProvider = new DataProvider(); 
    while(res.isAfterLast() == false){ 

     dataProvider.setImage(res.getString(res.getColumnIndex(UserContract.NewUserInfo.IMAGE))); 
     res.moveToNext(); 
    } 
    db.close(); 
    return dataProvider; 

} 

//在你的活動

Context context = this;  
UserDbHelper userDbHelper; 
SQLiteDatabase sqLiteDatabase; 
Cursor cursor;  
String image; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
userDbHelper =new UserDbHelper(this); 
    DataProvider dataProvider=userDbHelper.getInformations(); 

    image = dataProvider.getImage(); 

}