zoukankan      html  css  js  c++  java
  • Android Studio 学习(六)内容提供器

    运行时权限

    • 使用ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.CALL_PHONE)!=PackageManager.PERMISSION_GRANTED//判断是否有权限
    • ActivityCompat.requestPermissions(MainActivity.this,
      new String[] {Manifest.permission.CALL_PHONE},1);//没有权限 进行申请
    • onRequestPermissionResult() //无论哪种结果都会回调到这个函数中 所以重写这个函数

    makecallButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.
    permission.CALL_PHONE)!=PackageManager.PERMISSION_GRANTED)
    ActivityCompat.requestPermissions(MainActivity.this,
    new String[] {Manifest.permission.CALL_PHONE},1);
    else
    call();
    }
    });
    private void call()
    {
    try{
    Intent intent = new Intent (Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:10086"));
    startActivity(intent);
    }
    catch (SecurityException e)
    {
    e.printStackTrace();
    }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode){
        case 1:
            if(grantResults.length >0 && grantResults[0]== PackageManager.PERMISSION_GRANTED)
                call();
            else
                Toast.makeText(MainActivity.this,"you denied the  permission",Toast.LENGTH_LONG).show();
            break;
        default:
    }
    }
    

    }

    查找联系人姓名和电话

    ListView contactsView = (ListView) findViewById(R.id.listview);
    adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,contactsList);
    contactsView.setAdapter(adapter);
    if(ContextCompat.checkSelfPermission(this,Manifest.permission.READ_CONTACTS)!=
    PackageManager.PERMISSION_GRANTED)
    ActivityCompat.requestPermissions(this,new String[]{Manifest.permission
    .READ_CONTACTS},2);
    else {
    readContanct();
    }

    private void readContanct()
    {
    Cursor cursor = null;
    try{
    cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
    null,null,null,null);
    if(cursor != null)
    while (cursor.moveToNext()){
    String displayName = cursor.getString(cursor.getColumnIndex
    (ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
    String number =cursor.getColumnName(cursor.getColumnIndex
    (ContactsContract.CommonDataKinds.Phone.NUMBER));
    contactsList.add(number);
    adapter.notifyDataSetChanged();
    }
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    finally {
    if(cursor!=null)
    cursor.close();
    }
    }

  • 相关阅读:
    10.汇编语言--伪指令(offset、prt、lengthof)
    9.汇编语言--算数运算,标记寄存器
    8.汇编语言--数据传输指令mov等
    7.汇编语言--定义数据类型、数组
    6.汇编语言--汇编基本元素、寄存器、内存初步调试
    5.汇编语言--输入输出
    4.汇编语言--更为简便的使用win32-api
    3.汇编语言--x86处理器架构
    微信小程序获取input输入框里面的value值
    学习微信小程序遇到的坑 ---跳转
  • 原文地址:https://www.cnblogs.com/lancelee98/p/9486283.html
Copyright © 2011-2022 走看看