Android allies share detailed integration process and problem solving

Source: Internet
Author: User

Recent projects need to target, friends Circle, QQ, QQ space integration of the functions of the alliance to share, to tell the truth, I am also the first time to do, during the encounter a lot of problems, this essay on how I integrate the Friends of the Alliance to share, and what problems encountered, how to solve!

In fact, integration of friends is not difficult, follow the integration of the document step-by-step down can be, and download the Friends of the league SDK will be accompanied by the demo, but there are many things in the demo is not used, so we need to selectively extract the useful parts!

If you want to reprint please specify the Source: http://www.cnblogs.com/upwgh/p/6382085.html

1-Get Friends League Appkey

If you have already registered your application with the Friends League and obtained the Appkey, you can continue to use it.

If you have not registered a developer account in the league, you need to register, login to your account after registration, click Add New app, fill out the application basic information, will go to the "Download SDK and Add Code" page, this page can be appkey.

2-Download SDK and unzip to local

Download the latest version of the U-share SDK to the Friends League website, now the version is v6.2.2

Because the project only need integration, circle of friends, QQ and QQ space, so only tick these two items, the full version is with the payment function, no payment function, only need to tick the lite version can be.

We're going to go to our project now.

3-Environment configuration (androidmanifestxml)

3-1 Permissions Configuration

<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.WRITE_EXTERNAL_STORAGE "/><uses-permission Android:name= "Android.permission.READ_EXTERNAL_STORAGE"/><uses-permission android:name= " Android.permission.INTERNET "/><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"/>

3-2 Registration Related activity

<activity        android:name= ". Wxapi. Wxentryactivity "        android:configchanges=" keyboardhidden|orientation|screensize "        android:exported=" true "        android:screenorientation= "Portrait"        android:theme= "@android: Style/theme.translucent.notitlebar"/>

QQ FULL version:

<activity        android:name= "com.tencent.tauth.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.tencent.connect.common.AssistActivity "        android:screenorientation=" Portrait "        android:theme=" @ Android:style/theme.translucent.notitlebar "        android:configchanges=" Orientation|keyboardhidden|screensize " />

Note: Here to put their project in the QQ open platform ID, and the front of the Tencent is must not be omitted, otherwise in the run time, will report QQ configuration error problem.

3-3 allies Appkey and related third party key configuration

Set up Friends League Appkey in Androidmanifest.xml

<meta-data            android:name= "Umeng_appkey"            android:value= "561CAE6AE0F55ABD990035BF" >         </ Meta-data>

Configuring a third-party platform key in application

{
and QQ open platform corresponding to the AppID and Appkey platformconfig.setweixin ("Wx967daebe835fbeac", "5bb696d9ccd75a38c8a0bfe0675559b3") ; Platformconfig.setqqzone ("100424468", "C7394704798A158208A74AB60104F0BA");}

Initializing the SDK in application, this initialization is best placed in the application's program portal to prevent accidental occurrences:

public void OnCreate () {    super.oncreate ();        Open debug mode, easy to locate the error, the specific error check method can see the http://dev.umeng.com/social/android/quick-integration of errors must see, officially released, please close the mode    Config.debug = true;    Umshareapi.get (this);}

4-Code implementation

4-1, unzip the downloaded SDK, the main and platforms below the Libs inside the jar package import into the project (copy paste ... ), and add dependencies.

4-2, the package of the name of the record Create Wxapi folder, a new activity named Wxentryactivity wxcallbackactivity. Note here that it must be under the package name path, for example my package name is Com.umeng.soexample, then the configuration is as follows: (Note that If the path to use Lite wxcallbackactivity is com.umeng.weixin.callback.WXCallbackActivity, If using the full version path is com.umeng.socialize.weixin.view.WXCallbackActivity)

4-3, function code (part of the code to post only some of the key content, if you have questions, please leave a message)

4-3-1 sharing will drop the monitor

Share callback private Umsharelistener Umsharelistener = new Umsharelistener () {@Override public void Onresult (S            Hare_media platform) {LOG.D ("plat", "Platform" +platform); Toastutil.showtoast ("Share Success");//if (platform.tostring (). Equals ("QQ")) {//Toastutil.showtoast ("Phone q            Q Share Success ");//}else if (platform.tostring (). Equals (" QZONE ")) {//Toastutil.showtoast (" QQ Space sharing success ");// }else if (platform.tostring () equals ("Weixin")) {//Toastutil.showtoast ("Friends sharing success");/}        else if (platform.tostring () equals ("Weixin_circle")) {//Toastutil.showtoast ("Circle of Friends sharing success")//} } @Override public void OnError (Share_media platform, Throwable t) {toastutil.showtoast ("share lost            ");            if (t!=null) {log.d ("throw", "Throw:" +t.getmessage ()); }} @Override public void OnCancel (Share_media platform) {toAstutil.showtoast ("Share cancellation"); }    };

This is for sharing success, failure, cancellation of the corresponding callback, to share the results of the corresponding processing (this part of the code to be placed in the member variable)

4-3-2 Click to share event

    @Override public void OnClick (view view) {switch (View.getid ()) {r.id.tv_cancle:                Popupwindow.dismiss ();            Break                Case R.id.rl_common_title_exit:initpopupwindow ();                Set the location of the Popupwindow display popupwindow.showatlocation (Mpopview, gravity.bottom, 0, 0);                Backgroundalpha (0.5f);            Break Case R.id.qq:new ShareAction (showwebviewactivity.this). Setplatform (Share_media.                        QQ). Withtext (content). Withtitle (title). Withtargeturl (Linkhref). Withmedia (image)                . Setcallback (Umsharelistener). Share ();                Popupwindow.dismiss ();            Break Case R.id.weixin:new ShareAction (showwebviewactivity.this). Setplatform (Share_media . Weixin). Withtext (content). Withtitle (title). Withtargeturl (Linkhref). Withmedia (image). Setcallback (umsharelistener). sh                Is ();                Popupwindow.dismiss ();            Break Case R.id.kongjian:new ShareAction (showwebviewactivity.this). Setplatform (share_med Ia.                        QZONE). Withtext (content). Withtitle (title). Withtargeturl (Linkhref). Withmedia (image)                . Setcallback (Umsharelistener). Share ();                Popupwindow.dismiss ();            Break Case R.id.pengyouquan:new ShareAction (showwebviewactivity.this). Setplatform (share_ MEDIA.                        weixin_circle). Withtext (content). Withtitle (title). Withtargeturl (Linkhref). Withmedia (image)                . Setcallback (Umsharelistener). Share ();                Popupwindow.dismiss ();        Break }    }

This part of red is what you need to share, and you can initialize it yourself as needed.

    /**     * Share link, title, content */    String linkhref = "Share link";    String title = "Share title!" ";    String content = "Share content";    Share picture    private umimage image = null;

4-3-3 sharing pop-up windows

Everyone should have seen that my sharing panel was written by a Popupwindow

About Popupwindow I have written a related essay http://www.cnblogs.com/upwgh/p/5910261.html

The difference is because the need, sharing pop-up window, background to color, the window disappears when the background to restore, feel free to write a simple animation.

Initpopupwindow ():
private void Initpopupwindow () {        /**         * Instance Popupwindow Object */        Popupwindow = new Popupwindow (Mpopview, GridLayout.LayoutParams.MATCH_PARENT, GridLayout.LayoutParams.WRAP_CONTENT);        Set the item in Popupwindow to be clicked, this sentence is the popupwindow.setfocusable that must be added        (true);
Set animation Popupwindow.setanimationstyle (R.style.mypopwindow_anim_style); Setting the background of the Popupwindow //If you do not set the background, you will not be able to dismiss the Popupwindow colordrawable DW = new by clicking the external area or the back key. Colordrawable (0xb0000000); Popupwindow.setbackgrounddrawable (DW); }

Pop-up animations for popup windows:

    <style name= "Mypopwindow_anim_style" >        <!--Specify animated XML to display---        <item name= "Android: Windowenteranimation "> @anim/popu_show</item>        <!--specify vanishing animation XML--        <item name=" Android: Windowexitanimation "> @anim/popu_hide</item>    </style>

Popu_show.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <translate        android:duration= "android:fromydelta="        100%p "        android:toydelta=" 0 "/>    <alpha        android:duration= "$"        android:fromalpha= "0.0" android:toalpha= "1.0"        /></set >

Popu_hide.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <translate        android:duration= "android:fromydelta="        0 "        android:toydelta=" 50%p "/ >    <alpha        android:duration= "$"        android:fromalpha= "1.0" android:toalpha= "0.0"        /> </set>

Finally set the background change when the pop-up window pops up:

    /**     * Set the background transparency of the Add screen     * @param bgalpha *     /public    void Backgroundalpha (float bgalpha) {        Windowmanager.layoutparams LP = GetWindow (). GetAttributes ();        Lp.alpha = Bgalpha; 0.0-1.0        GetWindow (). SetAttributes (LP);        Popupwindow.setondismisslistener (New Popupwindow.ondismisslistener () {            @Override public            void Ondismiss () {                windowmanager.layoutparams LP = GetWindow (). GetAttributes ();                Lp.alpha = 1f;                GetWindow (). SetAttributes (LP);            }        );        GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_DIM_BEHIND);    }

The above is the main content of this sharing function, writing may not be very good, we forgive, if there are errors or do not understand the place, welcome message ha ~ ~ ~

Android allies share detailed integration process and problem solving

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.