最近在忙着作毕业设计,其中一个模块有这样的一个功能,要求作第三方分享,在之前的学习过程当中学习过微博、微信等分享(有兴趣的话,咱们之后再来探讨一下),今天偶然发现一个简单的方法----系统分享,可是这有一个大前提:手机中必须安装相应的客户端软件哦(切记切记)。闲话少续,一块儿来看看吧。
html
实现功能:打开系统分享对话框,选择要分享的途径,进行文本的分享(今天咱们之探讨文本的分享)。java
一:建立工程配置文件:android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00FFFF" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_margin="10dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="系统分享--文字" /> </LinearLayout> |
二:java代码:
微信
package com.example.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 找ID,添加监听 findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String msg = "日夜为你着迷、时刻为你挂虑、思念是不留馀地"; Intent shareInt = new Intent(Intent.ACTION_SEND); shareInt.setType("text/plain"); // 设置分享内容的类型,文字or图片等 shareInt.putExtra(Intent.EXTRA_SUBJECT, "选择分享方式"); shareInt.putExtra(Intent.EXTRA_TEXT, msg); // 分享的内容 // 参见:http://www.cnblogs.com/xiaoQLu/archive/2012/07/17/2595294.html shareInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareInt); // 启动系统分享 } }); } } |
三:结果展现:
app
楼主用的是真机测试的,因此只有这几个功能,至于其余功能是否能够实现,还要具体问题具体分析哦。源码已经奉上,一块儿学习啦。。。最近很闲,立刻过年回家啦。真好。。。推荐歌曲:《吻别》--张学友ide