在Android中编辑/写入“我”用户个人资料

时间:2014-03-05 09:57:01

标签: android android-contentprovider android-contacts

我需要提供用户选项,以便从我的应用程序中编辑“我”用户个人资料。我可以阅读这个“我”联系人的_id。但是当我尝试为此id打开Contact应用程序时,它会失败,但下面有例外。

//code snippet to get id for "me" contact.
user_profile.cid = cursor.getString(
    cursor.getColumnIndex(
        ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_IS_USER_PROFILE
    )
);

//调用联系人应用程序的代码段

Intent i = new Intent(Intent.ACTION_EDIT);
// i.setType(ContactsContract.RawContacts.CONTENT_ITEM_TYPE);
Uri contactUri = ContentUris.withAppendedId(
    ContactsContract.Profile.CONTENT_URI, Long.parseLong(up.cid)
);

i.setData(Uri.parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + up.cid));
i.setDataAndType(
    contactUri,
    ContactsContract.RawContacts.CONTENT_ITEM_TYPE
);
startActivity(i);

//异常痕迹

03-05 10:30:12.864: E/DatabaseUtils(12381): Writing exception to parcel
03-05 10:30:12.864: E/DatabaseUtils(12381): java.lang.IllegalArgumentException: URI: content://com.android.contacts/profile/1, calling user: android.uid.system:1000, calling package is one of: [com.android.settings, com.android.location.fused, com.android.inputdevices, com.android.keychain, android, com.android.providers.settings]
03-05 10:30:12.864: E/DatabaseUtils(12381):     at com.android.providers.contacts.LegacyApiSupport.getType(LegacyApiSupport.java:2084)
03-05 10:30:12.864: E/DatabaseUtils(12381):     at com.android.providers.contacts.ContactsProvider2.getType(ContactsProvider2.java:8117)
03-05 10:30:12.864: E/DatabaseUtils(12381):     at android.content.ContentProvider$Transport.getType(ContentProvider.java:210)
03-05 10:30:12.864: E/DatabaseUtils(12381):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:142)
03-05 10:30:12.864: E/DatabaseUtils(12381):     at android.os.Binder.execTransact(Binder.java:404)
03-05 10:30:12.864: E/DatabaseUtils(12381):     at dalvik.system.NativeStart.run(Native Method)
03-05 10:30:12.864: A/ActivityManager(617): Activity Manager Crash
03-05 10:30:12.864: A/ActivityManager(617): java.lang.IllegalArgumentException: URI: content://com.android.contacts/profile/1, calling user: android.uid.system:1000, calling package is one of: [com.android.settings, com.android.location.fused, com.android.inputdevices, com.android.keychain, android, com.android.providers.settings]
03-05 10:30:12.864: A/ActivityManager(617):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
03-05 10:30:12.864: A/ActivityManager(617):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
03-05 10:30:12.864: A/ActivityManager(617):     at android.content.ContentProviderProxy.getType(ContentProviderNative.java:446)
03-05 10:30:12.864: A/ActivityManager(617):     at com.android.server.am.ActivityManagerService.getProviderMimeType(ActivityManagerService.java:8109)
03-05 10:30:12.864: A/ActivityManager(617):     at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:1591)
03-05 10:30:12.864: A/ActivityManager(617):     at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2071)
03-05 10:30:12.864: A/ActivityManager(617):     at android.os.Binder.execTransact(Binder.java:404)
03-05 10:30:12.864: A/ActivityManager(617):     at dalvik.system.NativeStart.run(Native Method)
03-05 10:30:12.894: W/ContentResolver(6618): Failed to get type for: content://com.android.contacts/profile/1 (URI: content://com.android.contacts/profile/1, calling user: android.uid.system:1000, calling package is one of: [com.android.settings, com.android.location.fused, com.android.inputdevices, com.android.keychain, android, com.android.providers.settings])
03-05 10:30:12.904: E/ContactLoader(6618): Error loading the contact: content://com.android.contacts/profile/1
03-05 10:30:12.904: E/ContactLoader(6618): java.lang.IllegalArgumentException: uri format is unknown
03-05 10:30:12.904: E/ContactLoader(6618):  at com.android.contacts.common.util.ContactLoaderUtils.ensureIsContactUri(ContactLoaderUtils.java:64)
03-05 10:30:12.904: E/ContactLoader(6618):  at com.android.contacts.common.model.ContactLoader.loadInBackground(ContactLoader.java:307)
03-05 10:30:12.904: E/ContactLoader(6618):  at com.android.contacts.common.model.ContactLoader.loadInBackground(ContactLoader.java:75)
03-05 10:30:12.904: E/ContactLoader(6618):  at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
03-05 10:30:12.904: E/ContactLoader(6618):  at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
03-05 10:30:12.904: E/ContactLoader(6618):  at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)
03-05 10:30:12.904: E/ContactLoader(6618):  at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-05 10:30:12.904: E/ContactLoader(6618):  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-05 10:30:12.904: E/ContactLoader(6618):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-05 10:30:12.904: E/ContactLoader(6618):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-05 10:30:12.904: E/ContactLoader(6618):  at java.lang.Thread.run(Thread.java:841)

0 个答案:

没有答案