步骤一:在ShareSDk官网注册账号,并创建应用 。登陆Mob官网注册,官网地址:http://www.mob.com
步骤二:在ShareSDk官网下载所需要的分享的SDK
步骤三:将下载好的包解压
步骤四:将解压出的文件夹放入自己的项目中
步骤五:添加权限
- <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" />
步骤六:在ShareSDK.xml中添加ShareSDK应用APPKey
- <ShareSDK
- AppKey = "17b711d0d5064"/> <!-- 修改成你在sharesdk后台注册的应用的appkey"-->
步骤七:添加所ShareSDK需要的manifests配置
- <activity
- android:name="com.mob.tools.MobUIShell"
- android:theme="@android:style/Theme.Translucent.NoTitleBar"
- android:configChanges="keyboardHidden|orientation|screenSize"
- android:screenOrientation="portrait"
- android:windowSoftInputMode="stateHidden|adjustResize" >
- <intent-filter>
- <data android:scheme="tencent1105665723" />
- <action android:name="android.intent.action.VIEW" />
- <category android:name="android.intent.category.BROWSABLE" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- <!-- 调用新浪原生SDK,需要注册的回调activity -->
- <intent-filter>
- <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
步骤八:在代码中可以使用官方文档代码进行分享了
- public class MainActivity extends AppCompatActivity {
- Button shareBtn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- ShareSDK.initSDK(this);
- setContentView(R.layout.activity_main);
- shareBtn = (Button) findViewById(R.id.shareBtn);
- shareBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- OnekeyShare oks = new OnekeyShare();
- oks.setTitle("趣分享");
- oks.setText("我为技术带盐,我骄傲,我自豪");
- oks.setImageUrl("http://7sby7r.com1.z0.glb.clouddn.com/CYSJ_02.jpg");
- oks.setTitleUrl("http://wwww.baidu.com");
- oks.show(MainActivity.this);
- }
- });
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- ShareSDK.stopSDK(this);
- }
- }
注意:ShareSDK.initSDK(this);这个是从3.0开始的,官方换了一种。1,<application android:name="com.mob.MobApplication"></application> 2,可以不继承MobApplication,只要在使用ShareSDK之前,调用MobSDK.init(Context context,"MobAppkey","MobAppsecret");