I : 利用隐式Intent实现分享

   1、应用实现分享的功能

      

 1 /* 实现分享功能 */ 2          3         Intent intent = new Intent(); 4         intent.setAction(Intent.ACTION_SEND); 5  6         // 分享文本 7         intent.setType("text/plain"); // text/html ... 8         intent.putExtra(Intent.EXTRA_SUBJECT, "我要分享"); 9         intent.putExtra(Intent.EXTRA_TEXT, "分享的内容");10         11         // 分享本地图片12         intent.setType("image/*");13         File file = new File(Environment.getExternalStorageDirectory()+"/imgCache/a0.jpg"); 14 Uri uri = Uri.fromFile(file); 15  intent.putExtra(Intent.EXTRA_STREAM,uri); 16 17  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 18 startActivity(Intent.createChooser(intent, "分享列表"));

 

 2、应用加入系统的分享列表

 

 1  在AndroidManifest.xml文件中的标签下添加 2  3  <activity 4    android:name="com.example.demo_share_01.Leading" 5    android:label="@string/app_name" > 6              7                  9                 10                   11             12   

 

 

 II :  利用ShareSDK第三方库实现分享

    以一键分享(新浪微博和腾讯微博)为例

   第一步: 在src文件夹下添加叫cn.sharesdk.onekeyshare包

   第二步: 在libs文件夹下添加库文件 

                        

  第三步:在assets文件夹下添加ShareSDK.xml文件

        

+ View Code

 第四步:在AndroidManifest.xml文件中添加访问权限等配置信息

  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 <?xml version= "1.0"  encoding= "utf-8" ?> "http://schemas.android.com/apk/res/android"      package = "com.qf.sdemo_02_01_volley_news"      android:versionCode= "1"      android:versionName= "1.0"  >                 android:minSdkVersion= "12"          android:targetSdkVersion= "18"  />               "android.permission.INTERNET"  />      "android.permission.WRITE_EXTERNAL_STORAGE"  />      "android.permission.GET_TASKS"  />      "android.permission.INTERNET"  />      "android.permission.ACCESS_WIFI_STATE"  />      "android.permission.ACCESS_NETWORK_STATE"  />      "android.permission.CHANGE_WIFI_STATE"  />      "android.permission.WRITE_EXTERNAL_STORAGE"  />      "android.permission.READ_PHONE_STATE"  />      "android.permission.MANAGE_ACCOUNTS"  />      "android.permission.GET_ACCOUNTS"  />           "android.permission.BLUETOOTH"  />      "android.permission.BLUETOOTH_ADMIN"  />                 android:anyDensity= "true"          android:largeScreens= "true"          android:normalScreens= "true"          android:resizeable= "true"          android:smallScreens= "true"  />                 android:allowBackup= "true"          android:icon= "@drawable/ic_launcher"          android:label= "@string/app_name"          android:theme= "@style/AppTheme"  >                                        android:name= "com.qf.sdemo_02_01_volley_news.MainActivity"              android:label= "@string/app_name"  >                  "android.intent.action.MAIN"  />                    "android.intent.category.LAUNCHER"  />                                "com.qf.sdemo_02_01_volley_news.Detail"  >                                                   android:name= "cn.sharesdk.framework.ShareSDKUIShell"              android:configChanges= "keyboardHidden|orientation|screenSize"              android:theme= "@android:style/Theme.Translucent.NoTitleBar"              android:windowSoftInputMode= "stateHidden|adjustResize"  >                                              "db-7janx53ilz11gbs"  />                    "android.intent.action.VIEW"  />                    "android.intent.category.BROWSABLE"  />                  "android.intent.category.DEFAULT"  />                                                           "tencent100371282"  />                    "android.intent.action.VIEW"  />                    "android.intent.category.DEFAULT"  />                  "android.intent.category.BROWSABLE"  />                                        

第五步:将官方Demo中的Sample工程下的res文件下的资源文件拷贝到自己的工程目录下

第六步: 在mob.com 、新浪微博开发平台 和腾讯微博开发平台创建应用获得 appkey 和 appsecrect ,并添加到ShareSDK.xml文件中

第七步: 写代码实现分享


转载于http://www.cnblogs.com/d-on/p/4085167.html

更多相关文章

  1. Android(安卓)listview下拉刷新 上拉加载
  2. [Android病毒分析]木马病毒之DroidKongFu病毒
  3. 【Android】Android(安卓)签名相关问题
  4. Android(安卓)动态获取创建与删除文件权限
  5. Android中如何自己制作su
  6. android studio ndk编译问题
  7. RK3288[android 7.1]调试笔记 强制横屏
  8. Android系统关机或重启的几种实现方式
  9. 说说在 Android(安卓)中如何发送自定义广播

随机推荐

  1. centos7 安装python3.8
  2. Python地信专题 | 基于geopandas的空间数
  3. 利用python回顾统计学中的基础概念(全)
  4. python自动化办公太难?学这些就够用了
  5. Python地信专题 | 基于geopandas的空间数
  6. 知乎千赞 | 疫情在家能get什么新技能?
  7. 你一定不能错过的pandas 1.0.0四大新特性
  8. 用Python编写小工具下载OSM路网数据
  9. 使用Python检测新冠肺炎疫情拐点,抗疫成果
  10. 对容器镜像的思考和讨论