欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android开发指南之友盟新浪微博分享功能开发

程序员文章站 2022-04-12 21:37:40
Android开发指南之友盟新浪微博分享功能开发。 1.在清单文件中配置

Android开发指南之友盟新浪微博分享功能开发。

1.在清单文件中配置

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<activity  android:name=".WBShareActivity"  android:configChanges="keyboardHidden|orientation"  android:screenOrientation="portrait" > <intent-filter> <action  android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> intent-filter> activity> <activity  android:name="com.umeng.socialize.media.WBShareCallBackActivity"  android:configChanges="keyboardHidden|orientation"  android:theme="@android:style/Theme.Translucent.NoTitleBar"  android:exported="false"  android:screenOrientation="portrait" > activity> <activity android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"  android:configChanges="keyboardHidden|orientation"  android:exported="false"  android:windowSoftInputMode="adjustResize"  > activity> <activity  android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"  android:launchMode="singleTask"  android:name="com.sina.weibo.sdk.share.WbShareTransActivity"> <intent-filter> <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> intent-filter> activity> <activity  android:name="com.umeng.qq.tencent.AuthActivity"  android:launchMode="singleTask"  android:noHistory="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="tencent100424468" /> intent-filter> activity> <activity  android:name="com.umeng.qq.tencent.AssistActivity"  android:configChanges="orientation|keyboardHidden|screenSize"  android:screenOrientation="portrait"  android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <meta-data  android:name="UMENG_APPKEY"  android:value="59c8c0451c5dd02d54000408" />//你自己的key值
2.APP gradle配置
buildTypes {
    release {
        minifyEnabled false
        signingConfig signingConfigs.debug
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled false
        signingConfig signingConfigs.debug
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword "android"
        keyAlias "androiddebugkey"
        keyPassword "android"
    }
}
dependencies里面配置
compile files('libs/SocialSDK_QQ_Simplify.jar') compile files('libs/SocialSDK_Sina_Simplify.jar') compile files('libs/SocialSDK_WeChat_Simplify.jar') compile files('libs/umeng_shareboard_widget.jar') compile files('libs/umeng_social_api.jar') compile files('libs/umeng_social_net.jar') compile files('libs/umeng_social_shareboard.jar') compile files('libs/umeng_social_shareview.jar') compile files('libs/umeng_social_tool.jar')
3.在java包下新建wxapi包在包里写个下面的类
public class WXEntryActivity extends WXCallbackActivity { } 
4.
public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        UMShareAPI.get(this);
    }

    {

        PlatformConfig.setWeixin("wx967daebe835fbeac", "5bb696d9ccd75a38c8a0bfe0675559b3");
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        PlatformConfig.setSinaWeibo("2008013593", "560b1588158116bd8185773512b423e9", "https://sns.whalecloud.com");
    }

}
5.新建WBShareActivity类继承WBShareCallBackActivity
public class WBShareActivity extends WBShareCallBackActivity {
}
6.在分享的activity填写如下代码
在onCreate里填写如下代码
mShareAPI = UMShareAPI.get(this);
在分享的按钮或图片的监听里写
new ShareAction(XiangQingActivity.this)
        .withText(title1)//要分享的内容
        .withMedia(new UMWeb(url))//分享多谋体,没有可以不写
        .setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
        .setCallback(shareListener)
        .open();
//qq分享  private void onClickShare() { /* final Bundle params = new Bundle();  params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);  params.putString(QQShare.SHARE_TO_QQ_TITLE, "要分享的标题");  params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "要分享的摘要");  params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, "https://www.qq.com/news/1.html");  params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,"https://imgcache.qq.com/qzone/space_item/pre/0/66768.gif");  params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "测试应用222222");  params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, "其他附加功能");  mTencent.shareToQQ(MainActivity.this, params, new BaseUiListener());*/   } //分享的回调  private UMShareListener shareListener = new UMShareListener() { /**  * @descrption 分享开始的回调  * @param platform 平台类型  */  @Override public void onStart(SHARE_MEDIA platform) { } /**  * @descrption 分享成功的回调  * @param platform 平台类型  */  @Override public void onResult(SHARE_MEDIA platform) { Toast.makeText(XiangQingActivity.this, "成功了", Toast.LENGTH_LONG).show(); } /**  * @descrption 分享失败的回调  * @param platform 平台类型  * @param t 错误原因  */  @Override public void onError(SHARE_MEDIA platform, Throwable t) { Toast.makeText(XiangQingActivity.this, "失败" + t.getMessage(), Toast.LENGTH_LONG).show(); } /**  * @descrption 分享取消的回调  * @param platform 平台类型  */  @Override public void onCancel(SHARE_MEDIA platform) { Toast.makeText(XiangQingActivity.this, "取消了", Toast.LENGTH_LONG).show(); } }; @Override protected void onDestroy() { super.onDestroy(); UMShareAPI.get(this).release(); } //授权的回调  UMAuthListener authListener = new UMAuthListener() { @Override public void onStart(SHARE_MEDIA platform) { //授权开始的回调,可以用来处理等待框,或相关的文字提示  } @Override public void onComplete(SHARE_MEDIA platform, int action, Map data) { } @Override public void onError(SHARE_MEDIA platform, int action, Throwable t) { } @Override public void onCancel(SHARE_MEDIA platform, int action) { } }; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); }
其他需要复制的文件到友盟sdk去复制