Android Kotlin打开相机拍照和选择图片

MainActivity.kt

package com.example.fredric.takephoto

import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.support.annotation.RequiresApi
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.support.v4.content.FileProvider
import android.util.Log
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import java.io.File
import java.io.IOException
import android.content.ContentUris



class MainActivity : AppCompatActivity() {

    val TAKE_PHOTO: Int = 1
    val CHOOSE_PHOTO: Int = 2

    var picture: ImageView? = null
    var imageUri: Uri? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var takePhoto = findViewById

activity_main.xml




    

res/xml/file_paths.xml



    

AndroidManifest.xml



    

    
        
            
                

                
            
        
        
        
            
        
    


运行效果如图,


Screenshot_20180722-081309-093.jpg

你可能感兴趣的:(Android Kotlin打开相机拍照和选择图片)