标签:android style blog http io ar os 使用 java
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文件中的<activity>标签下添加<Intent-filter>
2
3 <activity
4 android:name="com.example.demo_share_01.Leading"
5 android:label="@string/app_name" >
6 <intent-filter>
7 <action android:name="android.intent.action.SEND" />
9 <category android:name="android.intent.category.DEFAULT" />
10 <data android:mimeType="image/*"/>
11 </intent-filter>
12 </activity>
以一键分享(新浪微博和腾讯微博)为例
第一步: 在src文件夹下添加叫cn.sharesdk.onekeyshare包
第二步: 在libs文件夹下添加库文件

第三步:在assets文件夹下添加ShareSDK.xml文件
ShareSDK.xml文件代码如下:
<?xml version="1.0" encoding="utf-8"?> <DevInfor> <!-- 说明: 1、表格中的第一项 <ShareSDK AppKey="api20" /> 是必须的,其中的AppKey是您在ShareSDK上注册的开发者帐号的AppKey 2、所有集成到您项目的平台都应该为其在表格中填写相对应的开发者信息,以新浪微博为例: <SinaWeibo Id="1" SortId="1" AppKey="568898243" AppSecret="38a4f8204cc784f81f9f0daaf31e02e3" RedirectUrl="http://www.mob.com" Enable="true" /> 其中的SortId是此平台在分享列表中的位置,由开发者自行定义,可以是任何整型数字,数值越大 越靠后AppKey、AppSecret和RedirectUrl是您在新浪微博上注册开发者信息和应用后得到的信息 Id是一个保留的识别符,整型,ShareSDK不使用此字段,供您在自己的项目中当作平台的识别符。 Enable字段表示此平台是否有效,布尔值,默认为true,如果Enable为false,即便平台的jar包 已经添加到应用中,平台实例依然不可获取。 各个平台注册应用信息的地址如下: 新浪微博 http://open.weibo.com 腾讯微博 http://dev.t.qq.com QQ空间 http://connect.qq.com/intro/login/ 微信好友 http://open.weixin.qq.com Facebook https://developers.facebook.com Twitter https://dev.twitter.com 人人网 http://dev.renren.com 开心网 http://open.kaixin001.com 搜狐微博 http://open.t.sohu.com 网易微博 http://open.t.163.com 豆瓣 http://developers.douban.com 有道云笔记 http://note.youdao.com/open/developguide.html#app 印象笔记 https://dev.evernote.com/ Linkedin https://developer.linkedin.com FourSquare https://developer.foursquare.com/ 搜狐随身看 https://open.sohu.com/ Flickr http://www.flickr.com/services/ Pinterest http://developers.pinterest.com/ Tumblr http://www.tumblr.com/developers Dropbox https://www.dropbox.com/developers Instagram http://instagram.com/developer# VKontakte http://vk.com/dev 易信好友 http://open.yixin.im/ 明道 http://open.mingdao.com/ Line http://media.line.me/zh-hant/ Pocket http://getpocket.com/developer/apps/new --> <ShareSDK AppKey = "426e34bef3d7"/> <!-- 修改成你在sharesdk后台注册的应用的appkey"--> <!-- ShareByAppClient标识是否使用微博客户端分享,默认是false --> <SinaWeibo Id="1" SortId="1" AppKey="2073300154" AppSecret="a5f7b084ba7630688831f691e16d146b" RedirectUrl="https://api.weibo.com/oauth2/default.html" ShareByAppClient="false" Enable="true" /> <TencentWeibo Id="2" SortId="2" AppKey="801550161" AppSecret="d2c82a847a577af120857feee42548ea" RedirectUri="http://www.baidu.com" Enable="true" /> </DevInfor>
第四步:在AndroidManifest.xml文件中添加访问权限等配置信息
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qf.sdemo_02_01_volley_news"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<!-- 添加需要的各种权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- 蓝牙分享所需的权限 -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- 主Activity -->
<activity
android:name="com.qf.sdemo_02_01_volley_news.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.qf.sdemo_02_01_volley_news.Detail" >
</activity>
<!-- 进行授权界面的注册 -->
<activity
android:name="cn.sharesdk.framework.ShareSDKUIShell"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize" >
<!--
Dropbox的SSO功能需要在此处添加一个对ACTION_VIEW事件的过滤器,其中的scheme是
“db-”前缀再开发者应用的加上appKey。如果此过滤器不设置,则不能完成SSO功能授权
-->
<intent-filter>
<data android:scheme="db-7janx53ilz11gbs" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!--
如果集成QQ分享,或者使用QQ客户端来进行QQ空间的分享,须要在此处添加一个对ACTION_VIEW
事件的过滤器,其中的scheme是“tencent”前缀再开发者应用的加上appId。如果此过滤器不设置,
则分享结束以后不能得到正确的回调
-->
<intent-filter>
<data android:scheme="tencent100371282" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
</manifest>
标签:android style blog http io ar os 使用 java
原文地址:http://www.cnblogs.com/d-on/p/4085167.html