-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.kt
64 lines (51 loc) · 1.86 KB
/
Camera.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.example.iot_assignment
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.content.Intent
import android.app.Activity
import android.os.Build
import androidx.annotation.RequiresApi
import com.github.dhaval2404.imagepicker.ImagePicker
import com.google.firebase.storage.FirebaseStorage
import kotlinx.android.synthetic.main.activity_camera.*
class Camera : AppCompatActivity() {
companion object{
const val REQUEST_FROM_CAMERA = 1001;
const val REQUEST_FROM_GALLERY = 1002;
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_camera)
initUI()
}
private fun initUI(){
btnCamera.setOnClickListener{
captureImageUsingCamera()
}
btnGallery2.setOnClickListener{
pickImageFromGallery()
}
}
private fun pickImageFromGallery(){
ImagePicker.with(this).galleryOnly().start(REQUEST_FROM_GALLERY)
}
private fun captureImageUsingCamera(){
ImagePicker.with(this).cameraOnly().start(REQUEST_FROM_CAMERA)
}
@RequiresApi(Build.VERSION_CODES.O)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(resultCode==Activity.RESULT_OK){
when(requestCode){
REQUEST_FROM_CAMERA ->{
imgProfile2.setImageURI(data!!.data)
FirebaseStorage().uploadImage(this,data.data!!)
}
REQUEST_FROM_GALLERY -> {
imgProfile2.setImageURI(data!!.data)
FirebaseStorage().uploadImage(this,data.data!!)
}
}
}
}
}