Android Aurora Push and Share [including Tag and Alias settings]

Keywords: Android SDK xml network

STEP1: Effect Map

STEP2: Aurora Registered Account
https://www.jiguang.cn/accounts/platform
1. Enter the Personal Center 2. Create an Application 3. Click on the lower right corner of the application settings, and then click on the push settings.
4.

Here the package name must correspond, and the official also provides a Demo [but there's nothing to do with it........................................ ] Click on confirmation to generate an APPkey code to use

STEP3: Configure Android Manifest. XML
1. Authority

  <!-- Required -->
    <uses-permission android:name="com.lxkj.mchat.permission.JPUSH_MESSAGE"/>
    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
    <!-- Optional. Required for location feature -->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <!-- For opening debug Version 6.0 Overlay window permissions on the system -->
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.GET_TASKS"/>

2. Create a new class to inherit Application

 public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // TODO: 2016/12/28 Settings Open Log, Close Log When Published
        //Initialize Aurora Push
        JPushInterface.setDebugMode(false);
        JPushInterface.init(this);
        //Aurora Sharing
        JShareInterface.init(this);
    }
}

3. Register Application

android:name=".app.MyApplication"

4. Some configure the core functions of Required SDK. I think the official website has a lot of configurations to see their own needs.

<activity
            android:name="cn.jiguang.share.android.ui.JiguangShellActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:exported="true"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"

        <service
            android:name="cn.jpush.android.service.PushService"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTER"/>
                <action android:name="cn.jpush.android.intent.REPORT"/>
                <action android:name="cn.jpush.android.intent.PushService"/>
                <action android:name="cn.jpush.android.intent.PUSH_TIME"/>
            </intent-filter>
        </service>
        <receiver
            android:name="cn.jpush.android.service.PushReceiver"
            android:enabled="true">
            <intent-filter android:priority="1000">
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/> <!-- Required  Display notification bar -->
                <category android:name="My own package name"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.USER_PRESENT"/>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            </intent-filter>
            <!-- Optional -->
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>

                <data android:scheme="package"/>
            </intent-filter>
        </receiver>
        <receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
             <!-- User defined. User-defined broadcasting receiver registers broadcasting -->
        <receiver
            android:name=".receiver.JpushRecviver"
            android:enabled="true"
            android:exported="false"
            android:permission="1000">
            <intent-filter>

                <!-- Required User registration SDK Of intent -->
                <action android:name="cn.jpush.android.intent.REGISTRATION"/>
                <!-- Required User Receive SDK Message intent -->
                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
                <!-- Required User Receive SDK Notification column information intent -->
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
                <!-- Required User opens custom notification bar intent -->
                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
                <!-- Receiving Network Change Connection/To break off since 1.6.3 -->
                <action android:name="cn.jpush.android.intent.CONNECTION"/>
                <action android:name="cn.jpush.android.intent.NOTIFICATION_CLICK_ACTION"/>
                <action android:name="cn.jpush.android.intent.UNREGISTRATION"/>

                <category android:name="My own package name"/>
            </intent-filter>
        </receiver>

        <meta-data
            android:name="JPUSH_APPKEY"
            android:value="Just applied appkey Leave it here"/>

5. The class JpushRecviver.class that receives notification above

 public class JpushRecviver extends BroadcastReceiver {
    private static final String TAG = "JpushRecviver";


    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle bundle = intent.getExtras();

        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            /**
             * intent of user registration SDK
             */
            Log.e(TAG, "onReceive1: ");
        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            /**
             * intent for users to accept SDK messages
             */
            Log.e(TAG, "Received custom message message message 2");

        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
            /**
             * intent for users to receive SDK notification bar information
             */
            Log.e(TAG, "The custom message message received is 3");
            //Save the title of the message pushed down by the server.
            String extra1 = bundle.getString(JPushInterface.EXTRA_TITLE);
            //Message content
            String extra2 = bundle.getString(JPushInterface.EXTRA_MESSAGE);
            //Additional fields. This is a JSON string.
            String extra3 = bundle.getString(JPushInterface.EXTRA_EXTRA);
            //The ID that uniquely identifies the message can be used to report statistics, etc.
            String extra4 = bundle.getString(JPushInterface.EXTRA_MSG_ID);
            //Title of Notice
            String extra5 = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
            //Notification content
            String extra6 = bundle.getString(JPushInterface.EXTRA_ALERT);
            //Notification ID in the notification bar, which can be used to clear Notification
            //If the alert field is empty, notification id is 0
            String extra7 = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_ID);
            //Rich media notifications push downloaded HTML file paths for presenting WebView
            String extra8 = bundle.getString(JPushInterface.EXTRA_RICHPUSH_HTML_PATH);
            //Rich media notifies the file name of the downloaded image resource, and multiple file names are separated by "," respectively.
            // It is located in the same path as "JPushInterface.EXTRA_RICHPUSH_HTML_PATH".
            String extra9 = bundle.getString(JPushInterface.EXTRA_RICHPUSH_HTML_RES);
            //JSON
            String extra10 = bundle.getString(JPushInterface.EXTRA_EXTRA);

            //Here do your own operation, about EventBus follow-up talks
            //Send notifications matching the corresponding content
            if (extra6.contains("Hello World")) {
                Log.e(TAG, "onReceive Contain: ");
                EventBus.getDefault().post(new HomeRecviverEvent());
            }

            Log.e(TAG, "Received a custom message message content of 2:" + extra1);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra2);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra3);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra4);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra5);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra6);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra7);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra8);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra9);
            Log.e(TAG, "Received custom message message message extra It's 2.:" + extra10);
        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            /**
             * User opens intent of custom notification bar
             */
            String extra6 = bundle.getString(JPushInterface.EXTRA_ALERT);
            //If it includes jumping to the corresponding interface
            if (extra6.contains("Hello World")) {
                Log.e(TAG, "onReceive Contain: ");
                Log.e(TAG, "Received custom message message message extra It's 4.:");
                Intent in = new Intent(context, NewFriendActivity.class);
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(in);
            } else {
                Log.e(TAG, "onReceive Not included: ");
            }
        } else {
            Log.e(TAG, "Unhandled intent - " + intent.getAction());
            Log.e(TAG, "Received custom message message message extra It's 5.:");
        }
    }
}

6. Configuration in build. gradle

JPUSH_PKGNAME: Push Packet Name: JSHARE_PKGNAME Shared Packet Name applicationId: Refers to the Packet Name TENCENT_APPID above you: This is Tencent's

Relevant dependencies:

 compile 'cn.jiguang.sdk:jpush:3.0.3' // Take JPush version 3.0.3 as an example.
 compile 'cn.jiguang.sdk:jcore:1.1.1' // Take JCore Version 1.1.1 as an example.
 compile 'cn.jiguang.sdk:jshare:1.1.0' // Take version 1.1.0 of JShare as an example.
 compile 'cn.jiguang.sdk:jshare-qqmodel:1.1.0' // Take version 1.1.0 of jshare-qqmodel as an example
 compile 'cn.jiguang.sdk:jshare-wechatmodel:1.1.0' // Take version 1.1.0 of jshare-wechatmodel as an example.
 compile 'cn.jiguang.sdk:jshare-sinamodel:1.1.0    // Take version 1.1.0 of jshare-sinamodel as an example.

The configuration should be complete at this point.

7. Code snippets can actually be pushed here, but since there are single and group pushes, tags and Tag s should be set, otherwise it is acceptable to everyone.

1. Setting labels and aliases in Activity Initialization calls the following method [Ensure initial entry settings such as: Activity that jumps after successful login]

 /**
     * Setting labels and aliases
     */
    private void setTagAndAlias() {
        /**
         *Alias are set here to get information about user login.
         *At this point, the user's userId is obtained, and then the user's userId can be used to set the alias.
         **/
        //The false status is unsuccessful with no label and alias
        //if (UserUtils.getTagAlias(getHoldingActivity()) == false) {
        Set<String> tags = new HashSet<String>();
        //Here you can set up the person you want to push. Usually the user uid is not empty and can add more than one at the same time.
        if (!TextUtils.isEmpty(UserUtils.getUid(getHoldingActivity()))){
           tags.add(UserUtils.getUid(getHoldingActivity()));//Setting tag
           }
        //Context, alias [Sting line], label [Set type], callback 
        JPushInterface.setAliasAndTags(getHoldingActivity(), UserUtils.getUid(getHoldingActivity()), tags,
                mAliasCallback);
        // }
    }

2. Setting Label and Alias Callback

 /**
     * /**
     * TagAliasCallback Classes are classes in the JPush development kit jar for
     * Setting the callback interface of alias and label will call back the method if it succeeds or not.
     * Given the callback code at the same time. If code=0, the alias setting is successful.
     * /**
     * 6001   Invalid settings, tag/alias should not have parameters null
     * 6002   Setting timeout suggests retrying
     * 6003   alias Illegal and effective aliases and labels of strings: letters (case-sensitive), numbers, underscores, Chinese characters.
     * 6004   alias Excessive length. Up to 40 bytes Chinese UTF-8 is 3 bytes
     * 6005   Illegal and effective aliases and tag components of a tag string: letters (case-sensitive), numbers, underscores, and Chinese characters.
     * 6006   One tag is too long. A tag has a maximum of 40 bytes. Chinese UTF-8 is 3 bytes.
     * 6007   tags The quantity exceeds the limit. Up to 100 are the limitations of a single device. There is no limit to the number of tags that apply globally.
     * 6008   tag/alias Exceeding the total length limit. Total length up to 1K bytes
     * 6011   10s Setting tag or alias more than three times in a short time is too frequent
     **/
    private final TagAliasCallback mAliasCallback = new TagAliasCallback() {
        @Override
        public void gotResult(int code, String alias, Set<String> tags) {
            String logs;
            switch (code) {
                case 0:
                    //Here you can write a successful status in SharePreference. After a successful setup, there is no need to set it up again in the future.
                    //UserUtils.saveTagAlias(getHoldingActivity(), true);
                    logs = "Set tag and alias success Aurora Push Alias Set Successfully";
                    Log.e("TAG", logs);
                    break;
                case 6002:
                //Very low probability of settings failure I set up hundreds of times there are three failures. If you don't feel confident, you can continue to call that aspect above and repeat it three times. You can remember that return does not go into the dead cycle.
                    logs = "Failed to set alias and tags due to timeout. Try again after 60s.Aurora Push Alias Settings Failed, Retry 60 seconds later";
                    Log.e("TAG", logs);
                    break;
                default:
                    logs = "Aurora push setup failed. Failed with errorCode = " + code;
                    Log.e("TAG", logs);
                    break;
            }
        }
    };

3. The above effect chart is a group push, that is, the installed will receive. Now let's try to specify the UID, that is, set the user's uid above to return to the aurora console.

Click to send immediately after completion.

The tags and tags above are set to the uid you just had in your code, which is my UserUtils.getUid(getHoldingActivity()) 1010117
In this way, only the user can receive the message.

4. When users quit login and do not want to receive notification, they must cancel the settings as long as they wear null, the callback is the same.

 /**
     * Unlabel and alias
     */
    private void cancleTagAndAlias() {
        //TODO context, alias, label, callback exit empty array and empty string cancel the previous settings
        Set<String> tags = new HashSet<String>();
        JPushInterface.setAliasAndTags(getHoldingActivity(), "", tags, mAliasCallback);
    }

STEP8: Next up is the shared code segment sharing configuration, which has been configured above.

Provide tools to determine whether QQ Weixin Weibo is installed or not.

 /**
     * com.tencent.mm WeChat
     * com.sina.weibo Sina Weibo
     * Determine whether QQ "com. tencent. mobile qq" is installed
     * true app with the corresponding package name installed
     */
    public static boolean hasApp(Context context, String packName) {
        boolean is = false;
        List<PackageInfo> packages = context.getPackageManager()
                .getInstalledPackages(0);
        for (int i = 0; i < packages.size(); i++) {
            PackageInfo packageInfo = packages.get(i);
            String packageName = packageInfo.packageName;
            if (packageName.equals(packName)) {
                is = true;
            }
        }
        return is;
    }

//For example, QQ's micro-blog is the same as QQ's micro-blog.  
/**
     * The difference is QQ, Weixin and Weibo.
     * 1-2-3
     */
 if (Tools.hasApp(PersonalHomePageActivity.this, "com.tencent.mobileqq")) {
                                    typeCode = 1;
                                    ShareQQWeiXinWeiBo();
                                } else {
                                    showToast("Not installed QQ");
                                }

/**
* Share to the corresponding platform
*/

    private void ShareQQWeiXinWeiBo() {
        ShareParams shareParams = new ShareParams();
        //Name platform name, optional values Wechat.Name, WechatMoments.Name, WechatFavorite.Name, and
        // SinaWeibo.Name,SinaWeiboMessage.Name,QQ.Name,QZone.Name. 
        String otherName = null;
        if (typeCode == 1) {
            otherName = QQ.Name;
            //QQ Text
            shareParams.setShareType(Platform.SHARE_WEBPAGE);
            //Title
            shareParams.setTitle(name);
            //text
            shareParams.setText(motto);
            //Click on the link
            shareParams.setUrl("http://www.baidu.com");
            //Network address thumbnail
            shareParams.setImageUrl(image);
            Log.e(TAG, "ShareQQWeiXinWeiBo: " + name + "\n" + motto + "\n" + image);
        } else if (typeCode == 2) {
            otherName = Wechat.Name;
            shareParams.setTitle(name);
            shareParams.setText(motto);
            shareParams.setShareType(Platform.SHARE_WEBPAGE);
            //Jump links must start with http or https
            shareParams.setUrl("http://www.baidu.com");
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
            shareParams.setImageData(bitmap);
        } else if (typeCode == 3) {
            otherName = SinaWeibo.Name;
            shareParams.setShareType(Platform.SHARE_WEBPAGE);
            shareParams.setText(motto);
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
            shareParams.setImageData(bitmap);
            shareParams.setUrl("http://www.baidu.com");
        }

        Log.e(TAG, "Share: " + typeCode);
        Log.e(TAG, "Share: " + name);
        JShareInterface.share(otherName, shareParams, new PlatActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                Log.e(TAG, "onComplete: ");
                //There seems to be no idea that spinning must go to the main thread.
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showToast("Sharing Success");
                    }
                });
            }

            @Override
            public void onError(Platform platform, int i, int i1, Throwable throwable) {
                Log.e(TAG, "onError: " + platform + "\n" + i + "\n" + i1 + "\n" + throwable.getMessage());
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showToast("Sharing Failure");
                    }
                });
            }

            @Override
            public void onCancel(Platform platform, int i) {
                Log.e(TAG, "onCancel: ");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showToast("Sharing Cancel");
                    }
                });
            }
        });
    }

STEP9: Wechat Callback Class Not Used for the Time being

1.
/**
* Configuration of Wechat Platform Callback
*/

public class WXEntryActivity extends WeChatHandleActivity {

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
    }
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
    }
}

2.AndroidManifest.xml

Optional QQ Shared Callback
Scheme is prefixed with the "tencent" prefix plus the appID of the QQ developer application; for example, if the appID is 123456, scheme= "tencent 123456"

 <intent-filter>
                <data android:scheme="tencent1106218557"/>

               <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>

            <!-- Sina Weibo Sharing Callback -->
            <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=".wxapi.WXEntryActivity"
            android:exported="true"
            android:launchMode="singleInstance"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan|adjustUnspecified|stateHidden"/>```


STEP10: stay assets New Creation under Catalogue  JGShareSDK.xml This oneself goes to various websites to apply for, can be one of the micro-blog's somewhat troublesome stuff to fill in many examinations and strict app Screenshots also need to reflect the usefulness of Weibo.... All right, that's it!

<?xml version="1.0" encoding="utf-8"?>
<DevInfor>

    <!-- If you do not need to support a platform, you can default the configuration of the platform-->

    <SinaWeibo
        AppKey="Sina's AppId"
        AppSecret="Sina's AppSecretId"
        RedirectUrl="Authorized Callback Page Filled in Open Microblog Platform"/>

    <QQ
        AppId="QQ Of AppId"
        AppKey="QQ Of AppId"/>

    <Wechat
        AppId="Wechat AppId"
        AppSecret="Wechat AppSectet"/>

</DevInfor>

Posted by Confessions on Fri, 07 Jun 2019 18:12:24 -0700