不幸的是,应用程序已停止。当在真实设备上运行
答
这是因为您使用的Android操作系统版本比棒棒糖大。
所以你要添加的权限为您的联系人
公共无效askForContactPermission(){ 如果(Build.VERSION.SDK_INT> = Build.VERSION_CODES.M){ 如果(ContextCompat.checkSelfPermission(getActivity() ,Manifest.permission.READ_CONTACTS)= PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
Manifest.permission.READ_CONTACTS)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Contacts access needed");
builder.setPositiveButton(android.R.string.ok, null);
builder.setMessage("please confirm Contacts access");//TODO put real question
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onDismiss(DialogInterface dialog) {
requestPermissions(
new String[]
{Manifest.permission.READ_CONTACTS}
, PERMISSION_REQUEST_CONTACT);
}
});
builder.show();
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
}
+0
没有。 android 5.0.2版本是。 –
这里了解如何提问:-http://stackoverflow.com/help/mcve –
请详细说明您的问题得到适当的解决方案。 –