forked from BorntoDev/PueanNgi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.kt
64 lines (53 loc) · 2.42 KB
/
MainActivity.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.borntodev.trithep.pueanterngijakaira
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.text.TextUtils
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
var MY_PERMISSIONS_REQUEST_READ_CONTACTS = 21
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
TypefaceUtil.overrideFont(this, "SERIF", "fonts/mitr_regular.ttf")
setContentView(R.layout.activity_main)
requestPermission()
btn_question_submit.setOnClickListener {
var intent = Intent(this,AnswerActivity::class.java)
var question = et_question.text.toString().trim()
if(!TextUtils.isEmpty(question)){
intent.putExtra("question",question)
startActivity(intent)
et_question.setText("")
}
}
}
private fun requestPermission(){
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
MY_PERMISSIONS_REQUEST_READ_CONTACTS)
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
// Permission has already been granted
}
}
}