Two sharing methods for android

Source: Internet
Author: User

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 ;}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.