Posted by : Unknown Sabtu, 02 Juni 2018

MainActivity.java

package com.mycompany.myapp;
import android.app.*;
import android.content.*;
import android.os.*;
import android.widget.*;
import android.net.*;
public class MainActivity extends Activity{
EditText tx;
String text;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tx=(EditText)findViewById(R.id.tx);
Intent receivedIntent = getIntent();
String receivedAction = receivedIntent.getAction();
String receivedType = receivedIntent.getType();
if(receivedAction.equals(Intent.ACTION_SEND)){
if(receivedType.startsWith("text/")){
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
if(receivedText != null) {
tx.setText(receivedText);
}}} finish();}}

main.xml
buat EditText dengan id tx


AndroidManifest.xml
tambahkan intent filter

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.myapp" >
<uses-permission
android:name="android.permission.READ_SMS"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <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/*" />
</intent-filter>
        </activity>
     
    </application>

</manifest>

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © BLOG GUE WANGI - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -