File tree Expand file tree Collapse file tree 6 files changed +180
-0
lines changed
java/com/hmkcode/intent_action_send Expand file tree Collapse file tree 6 files changed +180
-0
lines changed Original file line number Diff line number Diff line change 1+ apply plugin : ' com.android.application'
2+ apply plugin : ' kotlin-android'
3+ apply plugin : ' kotlin-android-extensions'
4+ android {
5+ compileSdkVersion 29
6+ buildToolsVersion " 29.0.2"
7+
8+
9+ defaultConfig {
10+ applicationId " com.hmkcode.intent_action_send"
11+ minSdkVersion 19
12+ targetSdkVersion 29
13+ versionCode 1
14+ versionName " 1.0"
15+
16+ testInstrumentationRunner " androidx.test.runner.AndroidJUnitRunner"
17+ }
18+
19+ buildTypes {
20+ release {
21+ minifyEnabled false
22+ proguardFiles getDefaultProguardFile(' proguard-android-optimize.txt' ), ' proguard-rules.pro'
23+ }
24+ }
25+
26+ }
27+
28+ dependencies {
29+ implementation fileTree(dir : ' libs' , include : [' *.jar' ])
30+ implementation " org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version "
31+ implementation ' androidx.appcompat:appcompat:1.0.2'
32+ implementation ' androidx.core:core-ktx:1.0.2'
33+ implementation ' androidx.constraintlayout:constraintlayout:1.1.3'
34+ testImplementation ' junit:junit:4.12'
35+ androidTestImplementation ' androidx.test.ext:junit:1.1.0'
36+ androidTestImplementation ' androidx.test.espresso:espresso-core:3.1.1'
37+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <manifest xmlns : android =" http://schemas.android.com/apk/res/android"
3+ package =" com.hmkcode.intent_action_send" >
4+
5+ <application
6+ android : allowBackup =" true"
7+ android : icon =" @mipmap/ic_launcher"
8+ android : label =" @string/app_name"
9+ android : roundIcon =" @mipmap/ic_launcher_round"
10+ android : supportsRtl =" true"
11+ android : theme =" @style/AppTheme" >
12+ <activity android : name =" .MainActivity" >
13+ <intent-filter >
14+ <action android : name =" android.intent.action.MAIN" />
15+
16+ <category android : name =" android.intent.category.LAUNCHER" />
17+ </intent-filter >
18+ </activity >
19+ <activity android : name =" .ReceivingActivity" >
20+ <intent-filter >
21+ <action android : name =" android.intent.action.SEND" />
22+ <category android : name =" android.intent.category.DEFAULT" />
23+ <data android : mimeType =" text/plain" />
24+ </intent-filter >
25+ </activity >
26+ </application >
27+
28+ </manifest >
Original file line number Diff line number Diff line change 1+ package com.hmkcode.intent_action_send
2+
3+ import android.content.Intent
4+ import androidx.appcompat.app.AppCompatActivity
5+ import android.os.Bundle
6+ import android.widget.Button
7+ import android.widget.TextView
8+
9+ class MainActivity : AppCompatActivity () {
10+
11+ private lateinit var textView: TextView
12+
13+ override fun onCreate (savedInstanceState : Bundle ? ) {
14+ super .onCreate(savedInstanceState)
15+ setContentView(R .layout.activity_main)
16+
17+ val button = findViewById<Button >(R .id.button)
18+ textView = findViewById<TextView >(R .id.textView)
19+
20+ button.setOnClickListener {
21+ textView.setText(" Clicked!" )
22+ send()
23+ }
24+ }
25+
26+ fun send (){
27+ val sendIntent: Intent = Intent ().apply {
28+ action = Intent .ACTION_SEND
29+ putExtra(Intent .EXTRA_TEXT , " Some text..." )
30+ type = " text/plain"
31+ }
32+
33+ val shareIntent = Intent .createChooser(sendIntent, null )
34+ startActivity(shareIntent)
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ package com.hmkcode.intent_action_send
2+
3+ import android.content.Intent
4+ import androidx.appcompat.app.AppCompatActivity
5+ import android.os.Bundle
6+ import android.widget.EditText
7+
8+ class ReceivingActivity : AppCompatActivity () {
9+
10+ override fun onCreate (savedInstanceState : Bundle ? ) {
11+ super .onCreate(savedInstanceState)
12+ setContentView(R .layout.activity_receiving)
13+
14+ val editText = findViewById<EditText >(R .id.editText)
15+
16+
17+ if (intent?.action == Intent .ACTION_SEND )
18+ editText.setText(intent.getStringExtra(Intent .EXTRA_TEXT ))
19+
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <LinearLayout xmlns : android =" http://schemas.android.com/apk/res/android"
3+ xmlns : app =" http://schemas.android.com/apk/res-auto"
4+ xmlns : tools =" http://schemas.android.com/tools"
5+ android : layout_width =" match_parent"
6+ android : layout_height =" match_parent"
7+ android : orientation =" horizontal"
8+ tools : context =" .MainActivity" >
9+
10+ <LinearLayout
11+ android : layout_width =" match_parent"
12+ android : layout_height =" wrap_content"
13+ android : orientation =" vertical"
14+ android : layout_gravity =" center" >
15+
16+ <Button
17+ android : id =" @+id/button"
18+ android : layout_width =" 172dp"
19+ android : layout_height =" 51dp"
20+ android : text =" Button"
21+ android : layout_gravity =" center"
22+ android : gravity =" center"
23+ />
24+
25+ <TextView
26+ android : id =" @+id/textView"
27+ android : layout_width =" wrap_content"
28+ android : layout_height =" wrap_content"
29+ android : text =" Hello World!"
30+ android : layout_gravity =" center" />
31+
32+ </LinearLayout >
33+
34+
35+ </LinearLayout >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <LinearLayout xmlns : android =" http://schemas.android.com/apk/res/android"
3+ xmlns : app =" http://schemas.android.com/apk/res-auto"
4+ xmlns : tools =" http://schemas.android.com/tools"
5+ android : layout_width =" match_parent"
6+ android : layout_height =" match_parent"
7+ android : orientation =" horizontal"
8+ tools : context =" .ReceivingActivity" >
9+
10+ <LinearLayout
11+ android : layout_width =" match_parent"
12+ android : layout_height =" wrap_content"
13+ android : layout_gravity =" center"
14+ android : orientation =" vertical" >
15+
16+ <EditText
17+ android : id =" @+id/editText"
18+ android : layout_width =" wrap_content"
19+ android : layout_height =" wrap_content"
20+ android : layout_gravity =" center" />
21+
22+ </LinearLayout >
23+ </LinearLayout >
You can’t perform that action at this time.
0 commit comments