This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
buildscript { | |
ext { | |
kotlin_version = '1.4.21' | |
} | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="app_id">COMET_CHAT_APP_ID</string> | |
<string name="auth_key">COMET_CHAT_AUTH_KEY</string> | |
<string name="region">us</string> | |
</resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requesting Location Permission | |
bi.btnRequestPermission.setOnClickListener { | |
askLocationPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) | |
} | |
// Single Permission Contract | |
private val askLocationPermission = registerForActivityResult(ActivityResultContracts.RequestPermission()) { result -> | |
if(result){ | |
Log.e("TAG", "Location permnission granted") | |
}else{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pick Images Contract - Normally this is for all kind of files. | |
private val pickImages = registerForActivityResult(ActivityResultContracts.GetContent()) {uri -> | |
uri?.let {uri -> | |
imageView.setImageURI(uri) | |
} | |
} | |
// Calling GetContent contract | |
pickImageButton.setOnClickListener { | |
pickImages("image/*") // We want images, so we set the mimeType as "image/*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TakePicture Contract Registration | |
private val takePicture = registerForActivityResult(ActivityResultContracts.TakePicture()) {bitmap -> | |
bitmap?.let { | |
imageView.setImageBitmap(bitmap) | |
} | |
} | |
// Calling the takePicture contract | |
captureButton.setOnClickListener { | |
var imageUri: Uri? = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
btnPick.setOnClickListener { | |
simpleContractRegistration(input = 3) // Remember, our SimpleContract had input of Int. So, 3 is dummy value here. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
} | |
// Other Methods | |
private val simpleContractRegistration = registerForActivityResult(SimpleContract()) {resultStr -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleContract : ActivityResultContract<Integer, String?>() { | |
override fun createIntent(context: Context, input: Integer?): Intent { | |
var intent = Intent(context, MyChildActivity::class.java) | |
intent.putExtra("myInputKey", input) | |
return intent | |
} | |
override fun parseResult(resultCode: Int, intent: Intent?): String? = when | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation 'androidx.activity:activity-ktx:1.2.0-alpha04' | |
implementation 'androidx.fragment:fragment-ktx:1.3.0-alpha04' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() | |
{ | |
// Other methods of your Activity | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
// Capture Image with Camera | |
if (requestCode == CAMERA_IMAGE_REQUEST && resultCode == Activity.RESULT_OK) { | |
if (data != null) { |