Use ContentProvider to access sharedpreferences data from other apps

Source: Internet
Author: User

@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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.