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

白云做网站网站翻页

白云做网站,网站翻页,wordpress加速教程,网站开发外文翻译1. 核心代码 打开系统相册功能#xff0c;本代码使用两种方式打开本地相册#xff0c;startActivityForResult 已经废弃#xff0c;可以使用新的方式。 package com.example.facedetectordemoimport android.content.pm.PackageManager import androidx.appcompat.app.App…1. 核心代码 打开系统相册功能本代码使用两种方式打开本地相册startActivityForResult 已经废弃可以使用新的方式。 package com.example.facedetectordemoimport android.content.pm.PackageManager import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.view.View import android.widget.TextView import androidx.activity.result.contract.ActivityResultContracts import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import com.example.facedetectordemo.databinding.ActivityMainBinding import com.example.facedetectordemo.entity.FaceInfo import android.Manifest; import android.annotation.SuppressLint import android.annotation.TargetApi import android.app.Activity import android.content.ContentUris import android.content.Intent import android.graphics.BitmapFactory import android.net.Uri import android.os.Build import android.provider.DocumentsContract import android.provider.MediaStore import com.google.android.material.snackbar.Snackbarclass MainActivity : AppCompatActivity() {private lateinit var binding: ActivityMainBindingprivate val CHOOSE_PHOTO 1private val requestPermissionLauncher registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean -if (isGranted) {Log.i(Permission: , Granted)} else {Log.i(Permission: , Denied)}}private val launcherActivity registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {val data it.dataif (it.resultCode Activity.RESULT_OK) {// 判断手机系统版本号if (Build.VERSION.SDK_INT 19) {// 4.4及以上系统使用这个方法处理图片if (data ! null) {if(data.clipData ! null) {handleImageOnKitKat(data.clipData!!.getItemAt(0).uri)} else if(data.data ! null) {handleImageOnKitKat(data.data!!)}}}}}override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)binding ActivityMainBinding.inflate(layoutInflater)setContentView(binding.root)// Example of a call to a native methodbinding.openGallery.setOnClickListener{val intent Intent(android.intent.action.GET_CONTENT)intent.type image/* // */intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)//startActivityForResult(intent, CHOOSE_PHOTO) // 打开相册, 废弃APIlauncherActivity.launch(intent)}val infos getFaceInfoList()Log.d(zhouyong, onCreate: size infos.size)requestPermission();}override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {super.onActivityResult(requestCode, resultCode, data)when (requestCode) {CHOOSE_PHOTO - if (resultCode Activity.RESULT_OK) {// 判断手机系统版本号if (Build.VERSION.SDK_INT 19) {// 4.4及以上系统使用这个方法处理图片if (data ! null) {if(data.clipData ! null) {handleImageOnKitKat(data.clipData!!.getItemAt(0).uri)} else if(data.data ! null) {handleImageOnKitKat(data.data!!)}}} else {}}else - {}}}TargetApi(19)private fun handleImageOnKitKat(uri: Uri) {var imagePath: String? null//val uri data.dataLog.d(TAG, handleImageOnKitKat: uri is $uri)if (DocumentsContract.isDocumentUri(this, uri)) {// 如果是document类型的Uri则通过document id处理val docId DocumentsContract.getDocumentId(uri)if (com.android.providers.media.documents uri!!.authority) {val id docId.split(:.toRegex()).toTypedArray()[1] // 解析出数字格式的idval selection MediaStore.Images.Media._ID idimagePath getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection)} else if (com.android.providers.downloads.documents uri.authority) {val contentUri ContentUris.withAppendedId(Uri.parse(content://downloads/public_downloads), java.lang.Long.valueOf(docId))imagePath getImagePath(contentUri, null)}} else if (content.equals(uri!!.scheme, ignoreCase true)) {// 如果是content类型的Uri则使用普通方式处理imagePath getImagePath(uri, null)} else if (file.equals(uri.scheme, ignoreCase true)) {// 如果是file类型的Uri直接获取图片路径即可imagePath uri.path}displayImage(imagePath) // 根据图片路径显示图片}SuppressLint(Range)private fun getImagePath(uri: Uri?, selection: String?): String? {var path: String? null// 通过Uri和selection来获取真实的图片路径val cursor contentResolver.query(uri!!, null, selection, null, null)if (cursor ! null) {if (cursor.moveToFirst()) {path cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))}cursor.close()}return path}private fun displayImage(imagePath: String?) {if (imagePath ! null) {val bitmap BitmapFactory.decodeFile(imagePath)binding.imageView.setImageBitmap(bitmap)} else {//Toast.makeText(this, failed to get image, Toast.LENGTH_SHORT).show()}}fun requestPermission() {when {ContextCompat.checkSelfPermission(this,Manifest.permission.READ_EXTERNAL_STORAGE) PackageManager.PERMISSION_GRANTED - {}ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.CAMERA) - {requestPermissionLauncher.launch(Manifest.permission.CAMERA)requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)}else - {requestPermissionLauncher.launch(Manifest.permission.CAMERA)requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)}}}fun View.showSnackbar(view: View,msg: String,length: Int,actionMessage: CharSequence?,action: (View) - Unit) {val snackbar Snackbar.make(view, msg, length)if (actionMessage ! null) {snackbar.setAction(actionMessage) {action(this)}.show()} else {snackbar.show()}}/*** A native method that is implemented by the facedetectordemo native library,* which is packaged with this application.*/external fun stringFromJNI(): Stringexternal fun getFaceInfoList(): ArrayFaceInfocompanion object {// Used to load the facedetectordemo library on application startup.init {System.loadLibrary(facedetectordemo)}} }2. main_layout.xml ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.MainActivityButtonandroid:idid/openGalleryandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginBottom212dpandroid:text打开相册app:layout_constraintBottom_toBottomOfparentapp:layout_constraintEnd_toEndOfparentapp:layout_constraintHorizontal_bias0.498app:layout_constraintStart_toStartOfparentapp:layout_constraintTop_toBottomOfid/imageViewapp:layout_constraintVertical_bias1.0 /ImageViewandroid:idid/imageViewandroid:layout_width200dpandroid:layout_height200dpandroid:layout_marginTop96dpapp:layout_constraintEnd_toEndOfparentapp:layout_constraintStart_toStartOfparentapp:layout_constraintTop_toTopOfparenttools:srcCompattools:sample/avatars //androidx.constraintlayout.widget.ConstraintLayout
http://www.w-s-a.com/news/208180/

相关文章:

  • 哪里有做网站的公司微商怎么开店步骤
  • 访问不了服务器的网站北京工业产品设计公司
  • 怎么棋牌网站建设口碑好的福州网站建设
  • 怎么样注册一个网站南通网站定制搭建
  • 网站免费正能量软件下载wordpress 多本小说
  • 临淄网站制作价格低长沙谷歌seo收费
  • 吴江公司网站建设电话免费的那种软件
  • 大淘客网站如何做seo网络广告设计公司
  • 厦门网络营销顾问湘潭网站seo
  • asp.net个人网站淮南 搭建一个企业展示网站
  • 备案关闭网站wordpress 替换
  • 台州建设网站制作wordpress乱码
  • 互联网时代 网站建设做交互设计的网站
  • 网站屏蔽中文浏览器湘潭做网站广告的公司
  • 好看的单页面网站模板免费下载手机网站经典案例
  • 优秀网站建设平台建筑模板工厂价格尺寸
  • 合肥微信网站建设旅游景区网站模板
  • 一个只做百合的网站wordpress文章和博客的区别
  • 编写网站策划方案网站哪里有
  • 网站做得好的公司国家防疫政策最新调整
  • 设计优秀的企业网站做行测的网站
  • 提供做网站公司有哪些关键词优化诊断
  • 建站合肥网络公司seo免费建手机商城网站吗
  • 设计师投资做项目网站外贸网站建设工作室
  • 无聊的网站wordpress的alt属性插件
  • 个股期权系统网站开发小清新wordpress模板
  • 全中文网站开发建筑公司企业愿景文案
  • 广州网站建设正规公司建设银行信用卡中心网站
  • 哪个网站是专门做封面素材怎么制作app平台
  • 网站开发 平均工资商标注册在哪个部门申请