Work yes
This commit is contained in:
parent
3e6fe310e0
commit
07051a904b
@ -1,4 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.android")
|
||||||
androidApplication
|
androidApplication
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6,7 +7,7 @@ val packageName = "ru.myitschool.work"
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = packageName
|
namespace = packageName
|
||||||
compileSdk = Version.Android.Sdk.compile
|
compileSdk = 35
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = packageName
|
applicationId = packageName
|
||||||
@ -24,8 +25,12 @@ android {
|
|||||||
sourceCompatibility = Version.Kotlin.javaSource
|
sourceCompatibility = Version.Kotlin.javaSource
|
||||||
targetCompatibility = Version.Kotlin.javaSource
|
targetCompatibility = Version.Kotlin.javaSource
|
||||||
}
|
}
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation("androidx.core:core-ktx:+")
|
||||||
defaultLibrary()
|
defaultLibrary()
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,30 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.Default"
|
android:theme="@style/Theme.Default"
|
||||||
tools:targetApi="31" />
|
tools:targetApi="31" >
|
||||||
|
<activity
|
||||||
|
android:exported="true"
|
||||||
|
android:enabled="true"
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:screenOrientation="portrait">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:exported="true"
|
||||||
|
android:enabled="true"
|
||||||
|
android:name=".GetActivity"
|
||||||
|
android:screenOrientation="portrait">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="text/plain"/>
|
||||||
|
<data android:mimeType="image/*"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
47
app/src/main/kotlin/ru/myitschool/work/GetActivity.kt
Normal file
47
app/src/main/kotlin/ru/myitschool/work/GetActivity.kt
Normal file
@ -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<ImageView>(R.id.IV)
|
||||||
|
val bitmap = getBitmap(intent)
|
||||||
|
imageView.setImageBitmap(bitmap)
|
||||||
|
} else if (intent.type == "text/plain") {
|
||||||
|
val textView = findViewById<TextView>(R.id.TV)
|
||||||
|
val text = getText(intent)
|
||||||
|
textView.text = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getBitmap(intent: Intent):Bitmap{
|
||||||
|
val uri = intent.getParcelableExtra<Uri>(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)!!
|
||||||
|
}
|
||||||
|
}
|
60
app/src/main/kotlin/ru/myitschool/work/MainActivity.kt
Normal file
60
app/src/main/kotlin/ru/myitschool/work/MainActivity.kt
Normal file
@ -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<View>(R.id.buttonShareTextUrl).setOnClickListener(handler)
|
||||||
|
findViewById<View>(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()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
24
app/src/main/res/layout/activity_main.xml
Normal file
24
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonShareTextUrl"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:text="@string/share_text_or_url" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonShareImage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/buttonShareTextUrl"
|
||||||
|
android:text="@string/share_image" />
|
||||||
|
</RelativeLayout>
|
20
app/src/main/res/layout/getter_activity.xml
Normal file
20
app/src/main/res/layout/getter_activity.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/IV"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
</ImageView>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/TV"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -1,3 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Work</string>
|
<string name="app_name">Work</string>
|
||||||
|
<string name="share_text_or_url">share_text_or_url</string>
|
||||||
|
<string name="share_image">share_image</string>
|
||||||
</resources>
|
</resources>
|
@ -2,4 +2,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
androidApplication version Version.gradle apply false
|
androidApplication version Version.gradle apply false
|
||||||
kotlinJvm version Version.Kotlin.language apply false
|
kotlinJvm version Version.Kotlin.language apply false
|
||||||
|
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user