activity_main.xml AndroidManifest.xml MainActivity.java
Copy <?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/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editText"
android:layout_marginTop="40dp"
android:onClick="share"
android:text="Send"
android:textColorHighlight="@color/black"/>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginTop="250dp"
android:inputType="textPersonName"
android:text="Some Text to send"
android:textAlignment="center"/>
</RelativeLayout>
Copy <?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.q4_implicit_intent">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Q4_Implicit_Intent">
<activity android:name=".MainActivity">
<intent-filter>
<action android:
name="android.intent.action.MAIN" />
<category android:
name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:
name="android.intent.action.SEND"/>
<category android:
name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
</application>
</manifest>
Copy package com.example.q4_implicit_intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void share(View v){
EditText editText =
(EditText)findViewById(R.id.editText);
Button btn = (Button)findViewById(R.id.button);
String str = editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,str);
startActivity(Intent.createChooser(intent,"Share"));
}
}