Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
view app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt @ 29:eec88eba58e9
Fix receiving from another app.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 24 Feb 2021 18:44:47 -0800 |
parents | 20da616dcda0 |
children | aacf7a856b5f |
line wrap: on
line source
package com.bartsent.simpleresizer import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.os.Bundle import android.util.Log import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.preference.PreferenceManager import com.bartsent.simpleresizer.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { val GET_IMAGE = 1 private lateinit var binding: ActivityMainBinding private var showChooser = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) } override fun onResume() { super.onResume() if (showChooser) { Intent(Intent.ACTION_GET_CONTENT).run { type = "image/*" addCategory(Intent.CATEGORY_OPENABLE) startActivityForResult(this, GET_IMAGE) } } else { showChooser = true } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { showChooser = false super.onActivityResult(requestCode, resultCode, data) if (requestCode == GET_IMAGE) { val imageUri = data?.data if (resultCode == Activity.RESULT_OK && imageUri != null) { Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { startActivity(this) } } else { Toast.makeText(applicationContext, "Unable to get image!", Toast.LENGTH_LONG).show() } } } }