系统分享----文字

   最近在忙着做毕业设计,其中一个模块有这样的一个功能,要求做第三方分享,在以前的学习过程中学习过微博、微信等分享(有兴趣的话,我们以后再来探讨一下),今天偶然发现一个简单的方法----系统分享,但是这有一个大前提:j_0028.gif手机中必须安装相应的客户端软件哦(切记切记)。闲话少续,一起来看看吧。

 实现功能:打开系统分享对话框,选择要分享的途径,进行文本的分享(今天我们之探讨文本的分享)。

   一:创建工程配置文件:

<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); // 启动系统分享
            }
        });
    }
}

   三:结果展示:

wKiom1Lfmsvijg70AAMsH03MbV8004.png

   

   楼主用的是真机测试的,所以只有这几个功能,至于其他功能是否可以实现,还要具体问题具体分析哦。源码已经奉上,一起学习啦。。。j_0043.gif最近很闲,马上过年回家啦。真好。。。推荐歌曲:《吻别》--张学友

   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章