Two sharing methods for android
When I want to create an intelligent notebook, I am trying to write a group of sharing functions by myself. Later I learned that every social software had its own sharing interface. This greatly reduces the amount of code. Method 1: feature-simple copy code package com. example. share; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. menu; import android. view. menuItem; public class MainActivity extends Activity {@ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main);}/* Create Menu */public boolean onCreateOptionsMenu (menu) {Menu. add (0, 0, 0, "share"); return true;} public boolean onOptionsItemSelected (MenuItem item) {switch (item. getItemId () {case 0: // intent. setType ("text/plain"); // plain text/** image sharing it. setType ("image/png"); // Add the image File f = new * File (Environment. getExternalStorageDirectory () + "/name.png"); ** Uri uri = Uri. fromFile (f); intent. putExtra (Intent. EXTRA_STREAM, * uri); */Intent intent = new Intent (Intent. ACTION_SEND); intent. setType ("image/*"); intent. putExtra (Intent. EXTRA_SUBJECT, "Share"); intent. putExtra (Intent. EXTRA_TEXT, "I have successfully share my message through my app"); intent. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); startActivity (Intent. createChooser (intent, getTitle (); return true;} return false ;}}