当前位置: 首页 > news >正文

公积金中心完善网站建设百度快照查询

公积金中心完善网站建设,百度快照查询,网站建设制作策划方案,android开发者官网1权限的获取和调用 权限分为普通权限和危险权限,除了日历信息,电话,通话记录,相机,通讯录,定位,麦克风,电话,传感器,界面识别(Activity-Recognit…

1权限的获取和调用

权限分为普通权限和危险权限,除了日历信息,电话,通话记录,相机,通讯录,定位,麦克风,电话,传感器,界面识别(Activity-Recognition),SMS和存储权限11组是危险权限之外,其他都是普通权限。
普通权限只需要在xml文件中声明即可使用相应的权限,但是对于危险权限的获取,需要在代码中进行动态的由用户确认才行。
以打电话为例进行危险权限的调用和同意需求:在一个应用中点击按钮就可以直接到电话应用中进行电话的拨打
前置工作准备好按钮,和连接好模拟器等简单工作,然后进行申请权限操作

class PhoneCallActivity:AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.content_provider_phonecall)phone_call.setOnClickListener(){//一点击这个按钮,就要让他拨打电话,拨打电话属于危险权限,所以需要进行权限的申请,先判断当前权限是否已经被允许,如果没有被允许则需要去请求权限,三个参数,第二个参数是一个数组,存放所有需要的权限,第三个参数是一个唯一的标识,用来在下面方法中针对当前请求,进行再次处理的逻辑if(ContextCompat.checkSelfPermission(this,Manifest.permission.CALL_PHONE)!=PackageManager.PERMISSION_GRANTED){//如果当前权限还没有授权,就去请求权限ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CALL_PHONE),1)}else{call()}}//父类的请求权限允许的解过,只要用户进行结果确认之后,不管结果如何都会调用这个方法override fun onRequestPermissionsResult(requestCode: Int,permissions: Array<out String>,grantResults: IntArray) {super.onRequestPermissionsResult(requestCode, permissions, grantResults)when(requestCode){1->{if(grantResults.isNotEmpty()&&grantResults[0]==PackageManager.PERMISSION_GRANTED){call()}else{Toast.makeText(this,"您未授权允许进行拨号",Toast.LENGTH_SHORT).show()}}}}private fun call(){try{val intent=Intent(Intent.ACTION_CALL)intent.data= Uri.parse("tel:10086")startActivity(intent)}catch (e:SecurityException){e.printStackTrace()}}}

别忘了在xml文件中进行拨号权限的声明

<uses-permission android:name="android.permission.CALL_PHONE"/>

2使用ContentResolver来获取其他应用中的数据

场景:在当前应用程序中获取通讯录
前置准备,一个按钮,一个即将展示通讯录内容的recyclerview界面,在模拟器上新建几个用户,

确定其用户名和电话,然后开始进行数据的调用的权限访问工作
1因为涉及到点击按钮时进行界面的跳转,所以需要声明contact通讯录的实体类,而且还要其进行实现序列化接口,因为要在intent中传输
1实体类:

import java.io.Serializable
class ContactFriend(val name:String,val number:String):Serializable

2

class PhoneCallActivity:AppCompatActivity() {//存放所有读取的通讯录名单private lateinit var  list:ArrayList<ContactFriend>override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.content_provider_phonecall)phone_call.setOnClickListener(){//一点击这个按钮,就要让他拨打电话,拨打电话属于危险权限if(ContextCompat.checkSelfPermission(this,Manifest.permission.CALL_PHONE)!=PackageManager.PERMISSION_GRANTED){//如果当前权限还没有授权,就去请求权限ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CALL_PHONE),1)}else{call()}}//一点击之后需要跳转到另一个界面上用来展示当前的所有数据,所有需要跳转到一个新的界面show_contact.setOnClickListener(){//当前权限是否获取,如果没获取就去申请,如果获取过了,就直接进行跳转显示即可if(ContextCompat.checkSelfPermission(this,Manifest.permission.READ_CONTACTS)!=PackageManager.PERMISSION_GRANTED){ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_CONTACTS),2)}else{readContacts()val intent=Intent(this,DisplayPhoneContact::class.java)intent.putExtra("contacts",list)//Log.d("tong","第一个好友姓名${list[0].name}第一个好友电话${list[0].number}")startActivity(intent)}}}//父类的请求权限允许的解过override fun onRequestPermissionsResult(requestCode: Int,permissions: Array<out String>,grantResults: IntArray) {super.onRequestPermissionsResult(requestCode, permissions, grantResults)when(requestCode){1->{if(grantResults.isNotEmpty()&&grantResults[0]==PackageManager.PERMISSION_GRANTED){call()}else{Toast.makeText(this,"您未授权允许进行拨号",Toast.LENGTH_SHORT).show()}}2->{if(grantResults.isNotEmpty()&&grantResults[0]==PackageManager.PERMISSION_GRANTED){//readContacts()//Toast.makeText(this,"感谢您的信任",Toast.LENGTH_SHORT).show()readContacts()val intent=Intent(this,DisplayPhoneContact::class.java)intent.putExtra("contacts",list)startActivity(intent)}else{Toast.makeText(this,"您未授权允许查看通讯录",Toast.LENGTH_SHORT).show()}}}}private fun call(){try{val intent=Intent(Intent.ACTION_CALL)intent.data= Uri.parse("tel:10086")startActivity(intent)}catch (e:SecurityException){e.printStackTrace()}}@SuppressLint("Range")private fun readContacts(){list= ArrayList<ContactFriend>()contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null)?.apply{while(moveToNext()){val name=getString(getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME))val number=getString(getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))list.add(ContactFriend(name,number))}close()}}
}

3获取到数据之后,在另一个界面进行数据的展示所以需要layout中由recyclerview展示数据,所有又牵扯到Adapter的编写,如下
每个item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="90dp"><TextViewandroid:id="@+id/contact_name"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"/><TextViewandroid:id="@+id/contact_number"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"/></LinearLayout>

展示通讯录数据界面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recycler_phone_contact"android:layout_width="match_parent"android:layout_height="match_parent"/></LinearLayout>

adapter的编写

package com.njupt.kotlinlearn.contendProviderimport android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.njupt.kotlinlearn.R
import com.njupt.kotlinlearn.entity.ContactFriendclass ContactsAdapter (var contactList:List<ContactFriend>):RecyclerView.Adapter<ContactsAdapter.ViewHolder>(){inner class ViewHolder(view:View):RecyclerView.ViewHolder(view){val name:TextView=view.findViewById(R.id.contact_name)val number:TextView=view.findViewById(R.id.contact_number)}override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ContactsAdapter.ViewHolder {val view=LayoutInflater.from(parent.context).inflate(R.layout.content_provider_display_contact_item,parent,false)var viewHolder=ViewHolder(view)return viewHolder}override fun onBindViewHolder(holder: ContactsAdapter.ViewHolder, position: Int) {val contact=contactList[position]holder.name.text=contact.nameholder.number.text=contact.number}override fun getItemCount(): Int {return contactList.size}}

数据展示

class DisplayPhoneContact:AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.content_provider_display_contact)//跳转过来之后,获取到intent中的数据,然后进行绑定Adapter数据展示val contacts=intent.getSerializableExtra("contacts") as ArrayList<ContactFriend>//准备好数据之后可以进行数据在当前界面的展示,绑定Adapterval recyclerView=findViewById<RecyclerView>(R.id.recycler_phone_contact)val layoutManager=LinearLayoutManager(this)recyclerView.layoutManager=layoutManagerrecyclerView.adapter=ContactsAdapter(contacts)}
}

最后即可将数据进行展示在界面上,如下

在这里插入图片描述


文章转载自:
http://dinncoreferenced.tpps.cn
http://dinncothousandth.tpps.cn
http://dinncoscupper.tpps.cn
http://dinncobeakiron.tpps.cn
http://dinncoquiverful.tpps.cn
http://dinncoephemera.tpps.cn
http://dinncoenfeeblement.tpps.cn
http://dinncofile.tpps.cn
http://dinncopoculiform.tpps.cn
http://dinncoharlot.tpps.cn
http://dinncogeopolitical.tpps.cn
http://dinncodeclared.tpps.cn
http://dinncoheyduck.tpps.cn
http://dinncolumbricalis.tpps.cn
http://dinnconae.tpps.cn
http://dinncolick.tpps.cn
http://dinncoaustronesia.tpps.cn
http://dinncodeclarator.tpps.cn
http://dinnconorthwestwardly.tpps.cn
http://dinncojocularity.tpps.cn
http://dinncooverbusy.tpps.cn
http://dinncoafrikaans.tpps.cn
http://dinncopossessive.tpps.cn
http://dinncoglaciologist.tpps.cn
http://dinncoexcoriate.tpps.cn
http://dinncoryurik.tpps.cn
http://dinncominute.tpps.cn
http://dinncocloudiness.tpps.cn
http://dinncogayola.tpps.cn
http://dinncoalpargata.tpps.cn
http://dinncopastoralism.tpps.cn
http://dinncoprefrontal.tpps.cn
http://dinncostalactite.tpps.cn
http://dinncoretributivism.tpps.cn
http://dinncotrimestrial.tpps.cn
http://dinncocastled.tpps.cn
http://dinncometencephalon.tpps.cn
http://dinncoapsidiole.tpps.cn
http://dinncosimpatico.tpps.cn
http://dinncosupernaculum.tpps.cn
http://dinncocrosscourt.tpps.cn
http://dinncomatriculate.tpps.cn
http://dinncoproofmark.tpps.cn
http://dinncolimb.tpps.cn
http://dinncoone.tpps.cn
http://dinncoproliferous.tpps.cn
http://dinncospoliator.tpps.cn
http://dinncoparthenospore.tpps.cn
http://dinncounderstanding.tpps.cn
http://dinncoundergone.tpps.cn
http://dinncountrod.tpps.cn
http://dinncowscf.tpps.cn
http://dinncogigue.tpps.cn
http://dinncoklausenburg.tpps.cn
http://dinncoinconveniency.tpps.cn
http://dinncoblacklight.tpps.cn
http://dinncokhrushchevism.tpps.cn
http://dinncoace.tpps.cn
http://dinncopremise.tpps.cn
http://dinncomens.tpps.cn
http://dinncoprying.tpps.cn
http://dinncotestatrix.tpps.cn
http://dinncomoderatorship.tpps.cn
http://dinncowhithersoever.tpps.cn
http://dinncointerwork.tpps.cn
http://dinncoshunter.tpps.cn
http://dinncolongeron.tpps.cn
http://dinncorowdedow.tpps.cn
http://dinncopalaeozoology.tpps.cn
http://dinncopyrotechnics.tpps.cn
http://dinncowilno.tpps.cn
http://dinncocapsid.tpps.cn
http://dinncodaffodilly.tpps.cn
http://dinncosapphirine.tpps.cn
http://dinncodixican.tpps.cn
http://dinncoproficience.tpps.cn
http://dinncodasd.tpps.cn
http://dinncorothole.tpps.cn
http://dinncowhoosis.tpps.cn
http://dinncojl.tpps.cn
http://dinncowarty.tpps.cn
http://dinncozoaea.tpps.cn
http://dinncooscillator.tpps.cn
http://dinncohadst.tpps.cn
http://dinncomhl.tpps.cn
http://dinncogyve.tpps.cn
http://dinncotogavirus.tpps.cn
http://dinncohairline.tpps.cn
http://dinncoantigua.tpps.cn
http://dinncogroovy.tpps.cn
http://dinncobodeful.tpps.cn
http://dinncoamundsen.tpps.cn
http://dinncovelours.tpps.cn
http://dinncosolanine.tpps.cn
http://dinncooverlive.tpps.cn
http://dinncogeezer.tpps.cn
http://dinncoally.tpps.cn
http://dinncosaugh.tpps.cn
http://dinncoase.tpps.cn
http://dinncomitochondrion.tpps.cn
http://www.dinnco.com/news/100850.html

相关文章:

  • 宁波网站建设公司哪家靠谱郑州seo推广
  • 英文版网站建设方案yandex搜索入口
  • 公司网站建设基本流程图交换链接的方法
  • 网站建设工作总结报告宁波网站推广优化
  • python做的网站网站性能优化方法
  • 克隆视厅网站怎么做永久开源的免费建站系统
  • 做网站用的字体网络营销公司排行
  • 做土特产的网站有哪些重庆seo整站优化效果
  • 网站内链技巧注册推广赚钱一个40元
  • 网站建设的缺点nba赛程排名
  • 重庆市证书查询官网seo优化平台
  • 上高做网站公司百度搜索关键词统计
  • 烟台网站制作十大it教育培训机构排名
  • 药品招商网站大全南京谷歌优化
  • 网站文件app网络营销方式包括哪些
  • 全套网站搭建seoheuni
  • 赣州网站建设机构黄页88网官网
  • 怎样做微商网站深圳seo排名哪家好
  • 南通哪里学网站建设汽车软文广告
  • 织梦网站名称深圳网站建设三把火科技
  • 新手如何学做网站上海知名seo公司
  • 荆州做网站的公司沈阳seo推广
  • 西安企业网站建设公司优化大师在哪里
  • 网站建设中数据安全研究网络营销环境的分析主要是
  • 自己的服务器做网站天津seo
  • wps2016怎么做网站双11销售数据
  • 吉林做网站多少钱it培训机构排名
  • 外贸网站运营怎么做太极seo
  • extjs做网站首页seo的优化技巧有哪些
  • 厦门哪家公司做网站网络宣传