Share Component usage records and component records

Source: Internet
Author: User

Share Component usage records and component records

Sharing components are often used in applications. Of course, many third parties provide social sharing services, such as ShareSDK and umeng.

This is neither sharesdk nor umeng.

Record the integration details today:

① No matter which platform you share, you must register an application on this platform.

② Take sharing to, circle of friends, and Weibo as an example:

/***/Public class Constant {// public static final String AppID = "wx9117e18be87a2aca"; public static final String AppSecret = "1ed5744aa7258808567873a2aa764409 "; // The appkey developed by sina is the public static final String APP_KEY = "2253710460"; public static final String REDIRECT_URL = "http://blog.csdn.net/leokelly001"; public static final String SCOPE = "email, direct_messages_read, direct_messages_write, "+" external, friendships_groups_write, statuses_to_me_read, "+" external, "+" invitation_write "; // advanced application permissions}

Ipv2weibo. java

Package com. leo. xjtulib. scanbook. common; import java. io. file; import android. app. activity; import android. content. intent; import android. graphics. bitmap; import android. graphics. bitmapFactory; import android. OS. bundle; import android. widget. toast; import com. leo. xjtulib. r; import com. sina. weibo. sdk. api. imageObject; import com. sina. weibo. sdk. api. textObject; import com. sina. weibo. sdk. api. webpageObject; import com. sina. weibo. sdk. api. weiboMultiMessage; import com. sina. weibo. sdk. api. share. baseResponse; import com. sina. weibo. sdk. api. share. IWeiboHandler; import com. sina. weibo. sdk. api. share. iweibow.api; import com. sina. weibo. sdk. api. share. sendmultimessagetoweibo orequest; import com. sina. weibo. sdk. api. share. weiboShareSDK; import com. sina. weibo. sdk. constant. WBConstants; import com. sina. weibo. sdk. utils. utility;/*****/public class implements 2weibo extends Activity implements IWeiboHandler. response {private iweibow.api mweibow.api; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); String name = getIntent (). getStringExtra ("name"); String url = getIntent (). getStringExtra ("url"); String picurl = getIntent (). getStringExtra ("picurl"); String score = getIntent (). getStringExtra ("score"); System. out. println ("------- start1 -------"); mweibow.api = WeiboShareSDK. createWeiboAPI (this, Constant. APP_KEY); mweibow.api. registerApp (); System. out. println ("------- start2 -------"); sendMultiMessage (score, name, url, picurl);} private TextObject getTextObj (String score) {TextObject textObject = new TextObject (); textObject. text = "I found a good book in the @ mobile library. Douban scores:" + score + ". Come and have a look."; return textObject ;} private WebpageObject getWebpageObj (String name, String url) {WebpageObject mediaObject = new WebpageObject (); mediaObject. identify = Utility. generateGUID (); mediaObject. title = name; mediaObject. description = name; mediaObject. setThumbImage (BitmapFactory. decodeResource (getResources (), R. drawable. ic_launcher); if (url. equals ("") url = "http://book.douban.com"; mediaObject. actionUrl = url; mediaObject. defaultText = ""; return mediaObject;} private ImageObject getImageObj (String picurl) {ImageObject imageObject = new ImageObject (); String tempPath = FileUtils. getCachePath () + "/temp.jpg"; File f = new File (tempPath); if (f. exists () {Bitmap thumb = BitmapFactory. decodeFile (tempPath); imageObject. setImageObject (thumb);} else {Bitmap thumb = BitmapFactory. decodeResource (getResources (), R. drawable. ic_launcher); imageObject. setImageObject (thumb);} return imageObject;} private void sendMultiMessage (String score, String name, String url, String picurl) {WeiboMultiMessage weiboMessage = new WeiboMultiMessage (); // initialize the Weibo shared message // System. out. println ("---------- initialize the Weibo sharing message --------"); weiboMessage. textObject = getTextObj (score); weiboMessage. imageObject = getImageObj (picurl); weiboMessage. mediaObject = getWebpageObj (name, url); sendmultimessagetoweibo orequest request = new sendmultimessagetoweibo orequest (); request. transaction = String. valueOf (System. currentTimeMillis (); request. multiMessage = weiboMessage; mweibow.api. sendRequest (request); // System. out. println ("---------- end Weibo sharing message --------") ;}@ Overrideprotected void onNewIntent (Intent intent) {super. onNewIntent (intent); mweibow.api. handleweibo oresponse (intent, this) ;}@ Overridepublic void onResponse (BaseResponse baseResp) {System. out. println ("------ onResponse --------"); switch (baseResp. errCode) {case WBConstants. errorCode. ERR_ OK: Toast. makeText (this, "shared successfully", Toast. LENGTH_LONG ). show (); finish (); break; case WBConstants. errorCode. ERR_CANCEL: Toast. makeText (this, "cancel sharing", Toast. LENGTH_LONG ). show (); finish (); break; case WBConstants. errorCode. ERR_FAIL: Toast. makeText (this, "sharing failed", Toast. LENGTH_LONG ). show (); finish (); break; default: finish (); break ;}}}

Ipv2weixin. java


Package com. leo. xjtulib. scanbook. common; import java. io. file; import android. app. activity; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmapFactory; import android. OS. bundle; import com. leo. xjtulib. r; import com. tencent. mm. sdk. openapi. IWXAPI; import com. tencent. mm. sdk. openapi. sendMessageToWX; import com. tencent. mm. sdk. openapi. wxapifacloud; import com. tencent. mm. sdk. Openapi. WXMediaMessage; import com. tencent. mm. sdk. openapi. WXWebpageObject; import com. tencent. mm. sdk. platformtools. util;/*****/public class extends 2weixin extends Activity {private iwxapi wxapi; private static final int TIMELINE = 1; private static final int FRIEND = 2; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); final String name = getIntent (). getStr IngExtra ("name"); final String url = getIntent (). getStringExtra ("url"); final String score = getIntent (). getStringExtra ("score"); final int type = getIntent (). getIntExtra ("type", 1); share (%2weixin. this, type, name, score, url);} public void share (Context context, int type, String name, String score, String url) {WXAPI = wxapifacloud. createWXAPI (context, Constant. appID); WXAPI. registerApp (Constant. ap PID); WXWebpageObject webpage = new WXWebpageObject (); if (url. equals ("") url = "http://book.douban.com"; webpage. webpageUrl = url; WXMediaMessage msg = new WXMediaMessage (webpage); if (type = TIMELINE) {msg. title = "I found a good book in the @ mobile library." + name + "Douban rating:" + score + "points"; msg. description = name;} else {msg. title = name; msg. description = "I found a good book in the @ mobile library." + name + "" Douban rating: "+ score +" score ";} String te MpPath = FileUtils. getCachePath () + "/temp.jpg"; File f = new File (tempPath); if (f. exists () {Bitmap thumb = BitmapFactory. decodeFile (tempPath); msg. thumbData = Util.bmp ToByteArray (thumb, true);} else {Bitmap thumb = BitmapFactory. decodeResource (getResources (), R. drawable. ic_launcher); msg. thumbData = Util.bmp ToByteArray (thumb, true);} SendMessageToWX. req req = new SendMessageToWX. req (); req. transaction = ""; Req. message = msg; req. scene = type = TIMELINE? SendMessageToWX. Req. WXSceneTimeline: SendMessageToWX. Req. WXSceneSession; WXAPI. sendReq (req); finish ();}}


Start activity in Application

Intent intent = new Intent(BookViewActivity_scanbook.this,Share2Weibo.class);intent.putExtra("url", mBook.getUrl());intent.putExtra("score",mBook.getRate() + "");intent.putExtra("picurl",mBook.getBitmap());intent.putExtra("name",mBook.getTitle());startActivity(intent);



Register in xml

<pre name="code" class="html"><activity            android:name="com.leo.xjtulib.scanbook.common.Share2Weibo"            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.leo.xjtulib.scanbook.common.Share2Weixin"            android:configChanges="keyboardHidden|orientation"            android:screenOrientation="portrait" >        </activity>


Jar package used download: http://download.csdn.net/detail/leokelly001/8693485 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.