Android读取联系人权限问题

teamade 2015-09-12 11:27:24
我在manifest.xml文件添加了权限,但是运行的时候一直报错“requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS”,说没有权限。请问如何解决,新手完全不懂

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ynfy.share1" >

<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
...全文
7511 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
smileliuyuefree 2016-09-30
  • 打赏
  • 举报
回复 1
6.0以上的是需要手动申请权限的
chsh5423654 2016-05-19
  • 打赏
  • 举报
回复 1
我觉得你应该先看看你这个应用在系统设置中的权限是不是被拒绝了,是的话,手动打开
ifu25 2016-03-11
  • 打赏
  • 举报
回复
去模拟器,应用,找到这个app,将权限中的读取联系人允许。 我也遇到这问题,不知道为什么app启动时没有提示是否允许读取联系人。
suntiezhu101288 2015-11-13
  • 打赏
  • 举报
回复
你的是SDK23么? 是的话可以参考: http://blog.csdn.net/tiezhu_sun/article/details/49818915 http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en
MR__P 2015-09-14
  • 打赏
  • 举报
回复
读写都加上 三星的个别系统会有这种问题
teamade 2015-09-14
  • 打赏
  • 举报
回复
搜了下,好像是我用的SDK版本的原因,SDK23的权限和之前的不一样
月盡天明 2015-09-14
  • 打赏
  • 举报
回复
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />  
都加上
黎西米 2015-09-13
  • 打赏
  • 举报
回复
还有,你那功能真的只是读而已?没看到代码不能确定
黎西米 2015-09-13
  • 打赏
  • 举报
回复
先加二个读和写权限: <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> 看那报错,我觉得你是少了个写的权限没添加。
teamade 2015-09-13
  • 打赏
  • 举报
回复

Cursor cursor = null;
        try {
            getContentResolver().query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    null, null, null, null);
            while (cursor.moveToNext()) {
                String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                String phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                Log.d("MainActivity", name);
                Log.d("MainActivity", phone);
                list.add(name + "\n" + phone);
            }
        } catch (Exception e) {
            e.printStackTrace();;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
这是读取的代码
黎西米 2015-09-13
  • 打赏
  • 举报
回复
我总感觉你多加了其他功能,感觉你加权限的没问题,我的试调可以,你可以看看,(也可能是我技术太菜没看出来)
黎西米 2015-09-13
  • 打赏
  • 举报
回复
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.widget.TextView;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
TextView tv = new TextView(this);
String string = "";
super.onCreate(savedInstanceState);
// 得到contentresolver对象
ContentResolver cr = getContentResolver();
// 取得电话本中开始一项的光标,必须先moveToNext()
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
while (cursor.moveToNext()) {
// 取得联系人的名字索引
int nameIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = cursor.getString(nameIndex);
string += (contact + ":" + "/n");

// 取得联系人的ID索引值
String contactId = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID));
// 查询该位联系人的电话号码,类似的可以查询email,photo
Cursor phone = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
+ contactId, null, null);// 第一个参数是确定查询电话号,第三个参数是查询具体某个人的过滤值
// 一个人可能有几个号码
while (phone.moveToNext()) {
String strPhoneNumber = phone
.getString(phone
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
string += (strPhoneNumber + "/n");
}
phone.close();
}
cursor.close();
// 设置显示内容
tv.setText(string);
// 显示
setContentView(tv);
// setContentView(R.layout.main);
}
}



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.read"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.read.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>







aircatcher 2015-09-13
  • 打赏
  • 举报
回复
<uses-permission android:name="android.permission.CALL_PHONE"> </uses-permission><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"> </uses-permission><uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.READ_CONTACTS"> </uses-permission><uses-permission android:name="android.permission.WRITE_CONTACTS"> </uses-permission> 这是我做手机联系人时用到的权限 希望对你有所帮助 我也是新手
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,分析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文中不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性分析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性分析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网中提升稳定性的内在机理;③复现顶刊论文中的阻抗分析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文中提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据分析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧