将号码添加到联系人中可以在模拟器上使用,但不能在设备上使用
我编写了代码,以便在使用应用程序时在通讯录中添加号码。
ContentResolver cr = getContentResolver();
Uri phoneUri = null;
ContentValues values = new ContentValues();
values.put(People.NAME, "stack");
Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);
values.clear();
values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
values.put(People.Phones.NUMBER, "9879958170");
getContentResolver().insert(phoneUri, values);
甚至在 .manifest 文件中添加了权限。
<uses-permission android:name="android.permission.READ_CONTACTS"
android:enabled="true" />
<uses-permission android:name="android.permission.WRITE_CONTACTS"
android:enabled="true" />
这正在模拟器上工作,联系人被添加,但是..当我将此应用程序放入设备中时....与名称堆栈没有联系...
任何人都可以帮助我并让我知道我是否犯了任何错误。
提前致谢:)
I have written code to add a number in contact book when the application is used.
ContentResolver cr = getContentResolver();
Uri phoneUri = null;
ContentValues values = new ContentValues();
values.put(People.NAME, "stack");
Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);
values.clear();
values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
values.put(People.Phones.NUMBER, "9879958170");
getContentResolver().insert(phoneUri, values);
and even added the permission in .manifest file.
<uses-permission android:name="android.permission.READ_CONTACTS"
android:enabled="true" />
<uses-permission android:name="android.permission.WRITE_CONTACTS"
android:enabled="true" />
this is working on emulator the contact gets added but..when i put this application into device....there is no contact with name stack...
Can anyone help me and let me know if i have done any mistake.
Thanks in advance:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有什么电话?有些手机(例如三星)安装了修改后的联系人应用程序,也许这就是原因。
what phone do you have? Some phones (ex. samsung) have a modified contact-app installed, maybe thats the reason.
您的手机运行的是哪个版本的安卓系统?您在这里使用的是旧的联系人 API,如果您的手机运行的是 Eclair 或更好的版本,尽管这些 api 调用在技术上应该仍然有效,但不建议使用。特别是当我们谈论制造商定制的手机应用程序时,结果可能有点难以预测。
另外,有时如果您不将联系人添加到“我的联系人”系统组,该联系人将不会出现在联系人应用程序中。并非每个联系人应用程序都是如此,但我在少数情况下看到过这种情况。
请向我们提供更多信息,以便我们正确回答您的问题。 (手机型号、运行的android版本等)
What version of android is your phone running? You're using the old contacts API here and if your phone is running Eclair or better, though these api calls should still technically work, they are not recommended. Especially when we're talking about a manufacturer customized phone app the results might be a little unpredictable.
Also, sometimes if you don't add your contact to the "My Contacts" system group, the contact will not appear in the contacts application. This is not true for every contacts app but I have seen it happen in a few cases.
Please give us a bit more info so we can answer your question properly. (Model of phone, android version its running, etc)