Use plug-in technology to call ShareSDK to reduce application volume and sharesdk to reduce
I. Introduction:
ShareSDK is componentized using the ApkPlug plug-in framework to dynamically load and reduce application volume as needed.
ShareSDK is a great mobile social sharing and commenting tool. I believe we can't do without it during application development. However, when we integrate ShareSDK, we also encounter some problems.
1. The ShareSDK package is relatively large. After combining multiple sharing platforms in China, the SDK package size should be above 1 MB, which is not heavy for applications.
2. During the process of integrating ShareSDK, We need to copy its resource files to the res Resource Directory of the application, which will cause a lot of interference to the later maintenance of our application.
Based on the above two situations, I want to use the ApkPlug framework to make ShareSDK a component and dynamically load the ShareSDK from the server to the local machine as needed, this easily solves the above two problems.
Project source code can be downloaded from here
Development library used by project 2
Apkplugv2.7.5 (it must be v2.7.5 or later, or it cannot run)
Apkplug plug-in hosting service v1.8.0 or later
ShareSDKv2.10.7 (the latest DEMO version is used)
3. project directory structure
ShareSDKMain --- DEMO of the main application
ShareSDKPlug --- Implementation of ShareSDK Components
PlugShareSDK1.0.0.jar -- component Call Library
Step 4
5. Call the ShareSDK component
After completing the preceding steps, you can use the ShareSDK component. The usage is very simple. The sharing function is used as an example.
1. initialize the ShareSdkAgent (defined in the PlugShareSDK1.0.0.jar package)
ShareSdkAgent agent=new ShareSdkAgent(this,frame.getSystemBundleContext());
2. Create the shared data Bean plugshareshareinfo (defined in the PlugShareSDK1.0.0.jar package)
Final plugshareshareinfo oks = new plugshareshareinfo (); oks. setAddress ("Beijing"); oks. setTitle ("sharesdk sharing component function under apkplug"); oks. setTitleUrl ("http://www.apkplug.com"); oks. setText ("apkplug is a modular framework in android. ShareSDK is a great social sharing component. Based on the idea of not repeating the wheel, we made ShareSDK a plug-in. For details, see the official http://www.apkplug.com "); // oks. setImagePath (testImage); oks. setImageUrl ("http://img.appgo.cn/imgs/sharesdk/content/2013/07/25/1374723172663.jpg"); oks. setUrl ("http://www.apkplug.com"); // oks. setFilePath (testImage); oks. setComment ("we recommend that you use the apkplug framework to reduce the application volume and provide development efficiency. "); Oks. setSite (getString (R. string. app_name); oks. setSiteUrl ("http://mob.com"); oks. setVenueName ("apkplug"); oks. setVenueDescription ("apkplug is a modular framework in android! "); Oks. setLatitude (23.056081f); oks. setlongpolling (113.20.708f); oks. setDisableSSOWhenAuthorize (false );
3. Call the ShareSDK component for sharing.
Agent. statShareSDK (new CheckInitCallBack () {@ Overridepublic void onSuccess (PlugShareSDK sharesdk) {// The ShareSDK component has been installed and started. // The sharesdk function is executed. showShare (oks) ;}@ Overridepublic void onFailure (int errorNo, String strMsg ){}});
Run DEMO: