Hi,

I have an app which creates a sync account, and I want to set the
created account as the preffered one for contacts sync.   I get the
following error - 'Neither user 10052 nor current process has
android.permission.SET_PREFERRED_APPLICATIONS.'

android.permission.SET_PREFERRED_APPLICATIONS has been added to the
manifest file.

Below is the code used;  Exception when
pm.clearPackagePreferredActivities("com.android.contacts"); is called,
and if commented, exception when pm.addPreferredActivity(...) is
called.

-----

        PackageManager pm = context.getPackageManager();

        try {
 
pm.clearPackagePreferredActivities("com.android.contacts");

            Intent edit_intent = new
Intent("android.intent.action.EDIT");
            Intent insert_intent = new
Intent("android.intent.action.INSERT");

 
edit_intent.addCategory("android.intent.category.DEFAULT");
 
insert_intent.addCategory("android.intent.category.DEFAULT");

            edit_intent.setData(ContentUris.withAppendedId(
                    ContactsContract.RawContacts.CONTENT_URI, 100));
 
insert_intent.setData(ContactsContract.RawContacts.CONTENT_URI);

            List<ResolveInfo> editList = pm.queryIntentActivities(
                          edit_intent,
PackageManager.MATCH_DEFAULT_ONLY |
                          PackageManager.GET_RESOLVED_FILTER );

            List<ResolveInfo> insertList = pm.queryIntentActivities(
                          insert_intent,
PackageManager.MATCH_DEFAULT_ONLY |
                          PackageManager.GET_RESOLVED_FILTER );

            ResolveInfo editRI = null;
            ResolveInfo insertRI = null;

            ComponentName[] editRIS = new
ComponentName[editList.size()];
            ComponentName[] insertRIS = new
ComponentName[insertList.size()];

            if(editList.size() > 0) {
                editRI = editList.get(0);
                for (int i=0; i<editList.size(); i++) {
                    ResolveInfo r = editList.get(i);
                    editRIS[i] = new
ComponentName(r.activityInfo.packageName,
                          r.activityInfo.name);
                }
            }
            if(insertList.size() > 0) {
                insertRI = insertList.get(0);
                for (int i=0; i<insertList.size(); i++) {
                    ResolveInfo r = insertList.get(i);
                    insertRIS[i] = new
ComponentName(r.activityInfo.packageName,
                          r.activityInfo.name);
                }
            }

            pm.addPreferredActivity(editRI.filter, editRI.match ,
editRIS,
                      new ComponentName("com.test.myapp",
            "com.test.myapp.contacts.ui.EditContactActivity"));
            pm.addPreferredActivity(insertRI.filter, insertRI.match ,
insertRIS,
                      new ComponentName(com.test.myapp",
            "com.test.myapp.contacts.ui.EditContactActivity"));

        }
        catch (Exception e) {
            e.printStackTrace();
        }

-----

Thanks in advance.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to