diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 0ab9e22..845f53c 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -1,4 +1,5 @@
plugins {
+ id("org.jetbrains.kotlin.android")
androidApplication
}
@@ -6,7 +7,7 @@ val packageName = "ru.myitschool.work"
android {
namespace = packageName
- compileSdk = Version.Android.Sdk.compile
+ compileSdk = 35
defaultConfig {
applicationId = packageName
@@ -24,8 +25,12 @@ android {
sourceCompatibility = Version.Kotlin.javaSource
targetCompatibility = Version.Kotlin.javaSource
}
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
}
dependencies {
+ implementation("androidx.core:core-ktx:+")
defaultLibrary()
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9ee5c40..6b5697a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,6 +11,30 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Default"
- tools:targetApi="31" />
+ tools:targetApi="31" >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/kotlin/ru/myitschool/work/GetActivity.kt b/app/src/main/kotlin/ru/myitschool/work/GetActivity.kt
new file mode 100644
index 0000000..54afde9
--- /dev/null
+++ b/app/src/main/kotlin/ru/myitschool/work/GetActivity.kt
@@ -0,0 +1,47 @@
+package ru.myitschool.work
+
+import android.content.Intent
+import android.graphics.Bitmap
+import android.net.Uri
+import android.os.Bundle
+import android.provider.MediaStore
+import android.widget.ImageView
+import android.widget.TextView
+import androidx.appcompat.app.AppCompatActivity
+
+
+class GetActivity : AppCompatActivity(){
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.getter_activity)
+ }
+
+ override fun onResume() {
+ super.onResume()
+
+ val intent = intent
+
+ // Figure out what to do based on the intent type
+
+ // Figure out what to do based on the intent type
+ if (intent.type!!.indexOf("image/") != -1) {
+ val imageView = findViewById(R.id.IV)
+ val bitmap = getBitmap(intent)
+ imageView.setImageBitmap(bitmap)
+ } else if (intent.type == "text/plain") {
+ val textView = findViewById(R.id.TV)
+ val text = getText(intent)
+ textView.text = text
+ }
+ }
+
+ private fun getBitmap(intent: Intent):Bitmap{
+ val uri = intent.getParcelableExtra(Intent.EXTRA_STREAM)
+ val bitmap = MediaStore.Images.Media.getBitmap(this.contentResolver, uri);
+ return bitmap
+ }
+ private fun getText(intent: Intent):String{
+ return intent.getStringExtra(Intent.EXTRA_TEXT)!!
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/ru/myitschool/work/MainActivity.kt b/app/src/main/kotlin/ru/myitschool/work/MainActivity.kt
new file mode 100644
index 0000000..f7170be
--- /dev/null
+++ b/app/src/main/kotlin/ru/myitschool/work/MainActivity.kt
@@ -0,0 +1,60 @@
+package ru.myitschool.work
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import android.os.Environment
+import android.provider.MediaStore
+import android.view.View
+import android.widget.Toast
+import androidx.activity.result.ActivityResultCallback
+import androidx.activity.result.PickVisualMediaRequest
+import androidx.activity.result.contract.ActivityResultContracts
+import androidx.appcompat.app.AppCompatActivity
+import java.io.File
+
+class MainActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_main)
+ val handler: View.OnClickListener = View.OnClickListener { v ->
+ when (v.id) {
+ R.id.buttonShareTextUrl -> shareTextUrl()
+ R.id.buttonShareImage -> shareImage()
+ }
+ }
+
+ findViewById(R.id.buttonShareTextUrl).setOnClickListener(handler)
+ findViewById(R.id.buttonShareImage).setOnClickListener(handler)
+ }
+
+ private fun shareTextUrl() {
+ val share = Intent(Intent.ACTION_SEND)
+ share.type = "text/plain"
+ share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
+
+ share.putExtra(Intent.EXTRA_SUBJECT, "Hello from my app")
+ share.putExtra(Intent.EXTRA_TEXT, "http://myitschool.ru")
+ startActivity(Intent.createChooser(share, "Share link!"))
+ Toast.makeText(applicationContext, "Text shared", Toast.LENGTH_LONG).show()
+ }
+
+ private fun shareImage() {
+
+ val request = PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
+ requestPicker.launch(request)
+ }
+
+ val requestPicker = registerForActivityResult(ActivityResultContracts.PickMultipleVisualMedia()) { uris ->
+ val share = Intent(Intent.ACTION_SEND)
+
+ share.type = "image/*"
+
+ for (uri in uris) {
+ share.putExtra(Intent.EXTRA_STREAM, uri)
+ }
+ startActivity(Intent.createChooser(share, "Share Image!"))
+ Toast.makeText(applicationContext, "Image shared", Toast.LENGTH_LONG).show()
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..ac62ade
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/getter_activity.xml b/app/src/main/res/layout/getter_activity.xml
new file mode 100644
index 0000000..aa5acdd
--- /dev/null
+++ b/app/src/main/res/layout/getter_activity.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 96034ac..43a5d1e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,5 @@
Work
+ share_text_or_url
+ share_image
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 860f2c8..21be453 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -2,4 +2,5 @@
plugins {
androidApplication version Version.gradle apply false
kotlinJvm version Version.Kotlin.language apply false
+ id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}
\ No newline at end of file