Android 注册内容提供商
我一直在尝试创建Android的ContactsProvider的副本。我想对提供商进行最小的更改,因为我的大部分工作将在另一个使用数据的应用程序中进行。但是,我想确保我正在制作的应用程序无法访问真实联系人,因此我计划创建提供商的副本。在成功浏览了使用不同权限创建副本提供程序的过程后,我尝试调用我的副本提供程序。在这一点上,我有两个错误 第一个是在我自己的应用程序中,我得到了错误“未能找到‘ContentProvider’的提供商信息”。我阅读了答案,但我已经处理了这里提到的所有内容 第二个错误发生在我的提供程序中:java.lang.NoClassDefFoundError:com.google.common.collect.ImmutableSet$Builder这可能是我遇到第一个错误的原因。因为我的提供商永远无法访问Android内部的类,所以它没有注册为有效的提供商,因此我的应用程序无法“找到”提供商 这是我的ContactManager清单文件:-Android 注册内容提供商,android,Android,我一直在尝试创建Android的ContactsProvider的副本。我想对提供商进行最小的更改,因为我的大部分工作将在另一个使用数据的应用程序中进行。但是,我想确保我正在制作的应用程序无法访问真实联系人,因此我计划创建提供商的副本。在成功浏览了使用不同权限创建副本提供程序的过程后,我尝试调用我的副本提供程序。在这一点上,我有两个错误 第一个是在我自己的应用程序中,我得到了错误“未能找到‘ContentProvider’的提供商信息”。我阅读了答案,但我已经处理了这里提到的所有内容 第二个错误
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prajitdas.contactmanager"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.prajitdas.contactmanager.ContactManager"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ContactAdder" android:label="@string/addContactTitle">
</activity>
</application>
</manifest>
以及ContactsProvider的清单文件:-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prajitdas.android.providers.contacts"
android:versionCode="2"
android:versionName="2.0">
<permission
android:name="com.android.voicemail.permission.READ_WRITE_ALL_VOICEMAIL"
android:label="@string/read_write_all_voicemail_label"
android:description="@string/read_write_all_voicemail_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="system|signature"
/>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BIND_DIRECTORY_SEARCH" />
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />
<uses-permission android:name="com.android.voicemail.permission.READ_WRITE_ALL_VOICEMAIL" />
<application android:process="android.process.acore"
android:label="@string/app_label"
android:icon="@drawable/app_icon"
android:allowBackup="true">
<!-- Modified provider authority -->
<provider android:name="ContactsProvider2"
android:authorities="fakecontacts;com.prajitdas.android.providers.contacts"
android:label="@string/provider_label"
android:multiprocess="false"
android:exported="true"
android:readPermission="android.permission.READ_CONTACTS"
android:writePermission="android.permission.WRITE_CONTACTS">
<path-permission
android:pathPrefix="/search_suggest_query"
android:readPermission="android.permission.GLOBAL_SEARCH" />
<path-permission
android:pathPrefix="/search_suggest_shortcut"
android:readPermission="android.permission.GLOBAL_SEARCH" />
<path-permission
android:pathPattern="/contacts/.*/photo"
android:readPermission="android.permission.GLOBAL_SEARCH" />
<grant-uri-permission android:pathPattern=".*" />
</provider>
<provider android:name="CallLogProvider"
android:authorities="fakecall_log"
android:syncable="false" android:multiprocess="false"
android:exported="true"
android:readPermission="android.permission.READ_CALL_LOG"
android:writePermission="android.permission.WRITE_CALL_LOG">
</provider>
<provider android:name="VoicemailContentProvider"
android:authorities="com.prajitdas.android.voicemail"
android:syncable="false" android:multiprocess="false"
android:exported="true"
android:permission="com.android.voicemail.permission.ADD_VOICEMAIL">
</provider>
<!-- Handles database upgrades after OTAs, then disables itself -->
<receiver android:name="ContactsUpgradeReceiver">
<!-- This broadcast is sent after the core system has finished
booting, before the home app is launched or BOOT_COMPLETED
is sent. -->
<intent-filter>
<action android:name="android.intent.action.PRE_BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name="PackageIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<receiver android:name="LocaleChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED"/>
</intent-filter>
</receiver>
<service android:name="VoicemailCleanupService"/>
<activity android:name=".debug.ContactsDumpActivity"
android:label="@string/debug_dump_title"
android:theme="@android:style/Theme.Holo.Dialog"
>
<intent-filter>
<action android:name="com.prajitdas.android.providers.contacts.DUMP_DATABASE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<provider android:name=".debug.DumpFileProvider"
android:authorities="com.prajitdas.android.providers.contacts.dumpfile"
android:exported="true">
</provider>
</application>
</manifest>
如您所见,我基本上复制了原始清单文件,并将其修改为我的提供者的新权限。我对java代码也做了同样的操作,但是它太大了,无法在这里发布。如果有人能帮我确定让android内部通话正常工作的步骤,或者可能以某种方式解决在手机上“注册”提供商的第一个问题,我将不胜感激。com.google.common.collect.ImmutableSet$Builder实际上不是一个内部android类。它是谷歌图书馆的一部分。您需要将Guava的JAR作为一个依赖项添加到您的项目中,以对其进行编译(可能还有其他一些依赖项,请在its中查看ContactsProvider的列表) 添加JAR依赖项的实际方式取决于您在构建应用程序时使用的方式(例如Ant、Maven、Gradle或Eclipse)