Android系统调用短信、电子邮件、蓝牙、社交网站等分享接口

来源:互联网 发布:js验证 是否为英文 编辑:程序博客网 时间:2024/05/17 08:04
点击分享按钮,进入要进行分享的的方式选择,界面,要想分享到开心网、人人网、腾讯微博、新浪微博的前提是手机上面必须安装了该第三方社区的客户端,否则,就无法分享到该客户端上面,这样比较方便,不需要,经过第三方的审核,就可以直接进行分享。
下面我们来看下    分享按钮的事件处理方法:
private OnClickListener listener=new OnClickListener(){    @Override    public void onClick(View arg0) {        // TODO Auto-generated method stub                shareInt=new Intent(Intent.ACTION_SEND);        shareInt.setType("text/plain");           shareInt.putExtra(Intent.EXTRA_SUBJECT, "选择分享方式");           shareInt.putExtra(Intent.EXTRA_TEXT, "OK");            shareInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);         startActivity(shareInt);            }};

注意:其中 shareInt.putExtra(Intent.EXTRA_TEXT, "OK");  设置的是要进行分享的内容,这样直接利用第三方软件提供的分享接口比较方便。

更多代码:

import java.util.List;  import android.app.Activity;  import android.content.Intent;  import android.content.pm.PackageManager;  import android.content.pm.ResolveInfo;  import android.os.Bundle;  import android.view.Menu;  import android.view.MenuItem;  public class Main extends Activity {  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);   } /* 创建菜单 */  public boolean onCreateOptionsMenu(Menu menu) {    menu.add(0,0,0,"分享");     return true;  }  public boolean onOptionsItemSelected(MenuItem item){    switch (item.getItemId()){    case 0:      Intent intent=new Intent(Intent.ACTION_SEND);      //intent.setType("text/plain");  //纯文本    /*图片分享    it.setType("image/png");     //添加图片      File f = new File(Environment.getExternalStorageDirectory()+"/name.png");             Uri uri = Uri.fromFile(f);      intent.putExtra(Intent.EXTRA_STREAM, uri);     */    intent.putExtra(Intent.EXTRA_SUBJECT, "分享");      intent.putExtra(Intent.EXTRA_TEXT, "I would like to share this with you...");      startActivity(Intent.createChooser(intent, getTitle()));      return true;    }    return false;  }  }

转载自:http://blog.csdn.net/qq435757399/article/details/8188625

http://gundumw100.iteye.com/blog/1541412