20170305

package com.example.wata.myapplication;

 

import android.content.ClipData;

import android.content.ClipboardManager;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.widget.Toast;

 

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        ClipboardManager clipboardManager=(ClipboardManager)getSystemService(CLIPBOARD_SERVICE);

        ClipData clipData=ClipData.newPlainText("test text","This is TEST!");

        clipboardManager.setPrimaryClip(clipData);

        String string=clipboardManager.getPrimaryClip().getItemAt(0).getText().toString();

        Toast.makeText(getApplicationContext(), string,Toast.LENGTH_SHORT).show();

    }

}