package com.example.abbu.implicit_intent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText editTextfield;
Button btnSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Casting
editTextfield = (EditText) findViewById(R.id.editText_field);
btnSend = (Button) findViewById(R.id.button_send);
intent();
}
public void intent(){
btnSend.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
String value = editTextfield.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(i.EXTRA_TEXT, value);
startActivity(i);
}
}
);
}
}
File Name: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.abbu.implicit_intent.MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_marginTop="76dp"
android:background="#ECF0F1"
android:id="@+id/editText_field"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:text="Send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="38dp"
android:id="@+id/button_send"
android:background="#95A5A6"
android:layout_below="@+id/editText_field"
android:layout_centerHorizontal="true" />
<TextView
android:text="Enter Your Message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText_field"
android:layout_alignStart="@+id/editText_field"
android:layout_marginBottom="29dp"
android:id="@+id/textView" />
</RelativeLayout>
Output:
|
activity_main.xml |
After clicking on SEND button, it'll ask from user using app chooser:
|
SEND ACTION |
No comments:
Post a Comment