SHARE
TWEET

Untitled

a guest Feb 17th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3.     TextView textView;
  4.     SearchView searchView;
  5.  
  6.     private static final int DELAY = 1000;
  7.  
  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.activity_main);
  12.  
  13.         textView = findViewById(R.id.receiving_text);
  14.  
  15.         workWithIntent();
  16.     }
  17.  
  18.     private void workWithIntent() {
  19.         final Intent intent = getIntent();
  20.         String action = intent.getAction();
  21.         String type = intent.getType();
  22.  
  23.         if (Intent.ACTION_SEND.equals(action) && type != null) {
  24.             if ("text/plain".equals(type)) {
  25.                 new Handler().postDelayed(new Runnable() {
  26.                     @Override
  27.                     public void run() {
  28.                         String receivedText = intent.getStringExtra(Intent.EXTRA_TEXT);
  29.                         textView.setText(receivedText);
  30.  
  31.                         searchView.setQuery(receivedText, true);
  32.                         searchView.setFocusable(true);
  33.                         searchView.setIconified(false);
  34.                         searchView.clearFocus();
  35.                     }
  36.                 }, DELAY);
  37.             }
  38.         }
  39.     }
  40.  
  41.     @Override
  42.     public boolean onCreateOptionsMenu(Menu menu) {
  43.         getMenuInflater().inflate(R.menu.menu_main, menu);
  44.  
  45.         MenuItem item = menu.findItem(R.id.action_search);
  46.  
  47.         searchView = (SearchView) item.getActionView();
  48.         return super.onCreateOptionsMenu(menu);
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top