@Override PublicCursor query (Uri uri, string[] projection, string selection, string[] Selectionargs, string sortOrder) { Switch(Surimatcher.match (URI)) { Casesp:sharedpreferences SP=getsharedpreference (sp_name_string); //Two column dataMatrixcursor cursor =NewMatrixcursor (NewString[] {"Key", "value" }); Map<string,?> map =Sp.getall (); if(Map = =NULL|| Map.size () = = 0) {log.i (GetClass (). Getsimplename (),"Map is empty"); return NULL; } if(Selection! =NULL) {log.i (GetClass (). Getsimplename (),"Query a single"); //unify returns as String typeCursor.addrow (Newstring[] {selection, string.valueof (Map.get (selection))}); } Else{log.i (GetClass (). Getsimplename (),"Query All"); Iterator<String> iterator =Map.keyset (). iterator (); while(Iterator.hasnext ()) {String key=Iterator.next (); Cursor.addrow (Newstring[] {key, string.valueof (Map.get (Key))}); } } returncursor; default: Break; } return NULL; } Privatesharedpreferences getsharedpreference (String spname) {returnGetContext (). Getsharedpreferences (Spname, context.mode_private); }
cursor cursor =getcontentresolver (). Query (Uri.parse ("Content://com.secapp.auth/sec"),NULL, Selection,NULL,NULL); if(cursor==NULL) {Toast.maketext ( This, "Cursor==null", Toast.length_short). Show (); return; } while(Cursor.movetonext ()) {System.out.println ("Key=" + cursor.getstring (0) + "value=" + cursor.getstring (1));//if (cursor.getstring (0). Equals ("KeyInt")) {//int i = cursor.getint (1);//if (i = = ten) {//System.out.println ("i=" + i);// }// } }
Use ContentProvider to access sharedpreferences data from other apps