100% Perfect Friend Sharing

Keywords: Android SDK Java

Step 1:

go Federation Official Website Register an account to create an application (the application name matches the project name), a detailed step you can refer to Friends QQ Login Skipping this time,

text

Import jar package

add permission

 <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" />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Inventory Configuration

 <!-- WeChat  start -->//This is a self-created version of the last detail of this article
        <activity
            android:name=".wxapi.WXEntryActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:exported="true"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <!-- WeChat  end -->
        <!-- Sina Weibo  start -->
        <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: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>
        <!-- micro-blog  end -->
        <!-- QQ  start -->
        <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.socialize.editorpage.ShareActivity"
            android:excludeFromRecents="true"
            android:theme="@style/Theme.Design.Light.NoActionBar" />
        <activity
            android:name="com.umeng.qq.tencent.AssistActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <!-- QQ  end -->
        <!-- umeng key  -->
        <meta-data
            android:name="UMENG_APPKEY"
            android:value="5a27ca7c8f4a9d0c24000195"></meta-data>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

Configuring in Application

{
        //QQ, WeChat, Weibo and other platforms are just made here.
        PlatformConfig.setWeixin("wx967daebe835fbeac", "5bb696d9ccd75a38c8a0bfe0675559b3");
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com");
    }
    @Override
    public void onCreate() {
        super.onCreate();
        UMShareAPI.get(this);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Sharing panel needs to be called to copy socialize_from the downloaded SDK Share_Menu_Item Layout File
Sharing panel application name shows unknown copy umeng_from value folderSocialize_Strings
Layout files have some resource files that come with them and need to be copied from drowable
Bar in SDK Debug.keystoreCopy to Project Directory

java code

Android 6.0 Rights Adaptation

if(Build.VERSION.SDK_INT>=23){
                  String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.CALL_PHONE,Manifest.permission.READ_LOGS,Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.SET_DEBUG_APP,Manifest.permission.SYSTEM_ALERT_WINDOW,Manifest.permission.GET_ACCOUNTS,Manifest.permission.WRITE_APN_SETTINGS};
                  ActivityCompat.requestPermissions(this,mPermissionList,123);
              }
  • 1
  • 2
  • 3
  • 4
  • 5

When you click Share: Raise the Share Panel

new ShareAction(getActivity()).setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.QZONE,SHARE_MEDIA.WEIXIN)
                        .setContentList(new ShareContent(),new ShareContent())
                        .withText("title")
                        .setListenerList(shareListener,shareListener)
                        .setShareboardclickCallback(shareBoardlistener)
                        .open();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

There are two monitors, one is shared listening success/failure, the other is multi-platform sharing.
So create these two listening events

private ShareBoardlistener shareBoardlistener = new  ShareBoardlistener() {

        @Override
        public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
            if (share_media==null){
                if (snsPlatform.mKeyword.equals("11")){
                    Toast.makeText(getActivity(),"add button success",Toast.LENGTH_LONG).show();
                }

            }
            else {
                UMImage image = new UMImage(getActivity(),
                        BitmapFactory.decodeResource(getResources(), R.drawable.datu));

                new ShareAction(getActivity()).setPlatform(share_media).withMedia(image).setCallback(shareListener)
                        .withText("Multi-Platform Sharing")
                        .share();
            }
        }
    };
    private UMShareListener shareListener = new UMShareListener() {
        /**
         * @descrption Share callbacks from start
         * @param platform Platform type
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        /**
         * @descrption Share successful callbacks
         * @param platform Platform type
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(getActivity(),"Succeed",Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption Sharing failed callbacks
         * @param platform Platform type
         * @param t Error Reason
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(getActivity(),"fail"+t.getMessage(),Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption Share cancelled callbacks
         * @param platform Platform type
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(getActivity(),"Cancelled",Toast.LENGTH_LONG).show();

        }
    };
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

Last add-drop method

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(getActivity()).onActivityResult( requestCode, resultCode, data);
    }
  • 1
  • 2
  • 3
  • 4
  • 5

Perfect multi-platform sharing, idea WeChat needs to create an activity to inherit from the alliance WeChat activity

Posted by loki1664 on Fri, 03 Jul 2020 08:12:09 -0700