This article shares the integration of Sina Weibo sharing function for your reference. The specific content is as follows
Download Sina WeiboAndroid SDK
Direct import: suitable for projects that only require authorization, sharing, and network request framework functions.
No matter which method you use, you need to copy all the corresponding file directories in the demo to your target project. Create a new folder jniLibs in app->src->main, copy all the corresponding file directories under the lib directory in demo to it, and do not change any file and folder locations.
When sharing, refer to WBShareMainActivity in demo. Here is the entry to sharing. The main code is as follows:
// Create a Weibo SDK interface instance mWeiboShareAPI = (mContext, SysConstants.SHARE_WEIBO_APP_ID); // Register to Sina Weibo (); Intent i = new Intent(mContext, ); (WBShareActivity.KEY_SHARE_TYPE, WBShareActivity.SHARE_ALL_IN_ONE); (WBShareActivity.IMAGE_URL, imgUrl); (i);
Before sharing, you need to replace the APP_KEY and other parameters with the parameters you applied by yourself. You can refer to the Constants class in the Demo.
Before sharing on Weibo, you need to declare the corresponding Action: ACTION_SDK_REQ_ACTIVITY in the Activity (the class that evokes the Weibo master program) that needs to receive messages, as shown below:
<activity android:name="" android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" > <intent-filter> <action android:name=".ACTION_SDK_REQ_ACTIVITY" /> <category android:name="" /> </intent-filter> </activity> <activity android:name="" android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="adjustResize" android:exported="false" > </activity>
The sharing function is mainly implemented by WBShareActivity, including text, pictures, web pages, music, videos, and sounds. For specific codes, refer to Demo.
The IWeiboHandler#Response interface is implemented in WBShareActivity, and the data returned by Weibo is received after sharing. The code is as follows:
/** * Receive data requested by micro-client. * When the Weibo client calls up the current application and shares it, the method is called. * * @param baseRequest Weibo request data object * @see {@link IWeiboShareAPI#handleWeiboRequest} */ @Override public void onResponse(BaseResponse baseResp) { if(baseResp!= null){ switch () { case .ERR_OK: (this, .weibosdk_demo_toast_share_success, Toast.LENGTH_LONG).show(); break; case .ERR_CANCEL: (this, .weibosdk_demo_toast_share_canceled, Toast.LENGTH_LONG).show(); break; case .ERR_FAIL: (this, getString(.weibosdk_demo_toast_share_failed) + "Error Message: " + , Toast.LENGTH_LONG).show(); break; } } }
It should be noted that in the WBShareActivity method to share images, in getImageObj, the comment says that the thumbnail set is not the picture at the time of sharing. We only need to put the images we need to share into the imageObject, without the 32K size limit. If we place the thumbnail in an imageObject, the shared image is a thumbnail and cannot be seen clearly.
/** * Create image message object. * * @return Image message object. */ private ImageObject getImageObj() { ImageObject imageObject = new ImageObject(); BitmapDrawable bitmapDrawable = (BitmapDrawable) (); //Set thumbnails. Note: The final compressed thumbnail size must not exceed 32kb. /*The comments above are in the demo, but in fact there is no need to set thumbnails here, you just need to set the image we share directly into imageObjet*/ Bitmap bitmap = (getResources(), .ic_logo); (bitmap); return imageObject; }
For other matters, please refer to the documentation provided by Sina Weibo SDK.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.