SDK Debugging Guide

Last updated:2021-12-15
Expand all
SDK Debugging Guide

SDK Startup process

  • examine AndroidManifest.xml Is there any configuration in AppKey, if not, the startup fails
  • examine Androidmanifest.xml The correctness of the file configuration must be ensured.Android SDK All notes in the "Integration Guide"Required” parts are configured correctly, otherwise the startup will fail.
  • examine JPush SDK The validity of the library file. If the library file is invalid, the startup will fail.
  • Check whether the network is available. It is recommended to use 4G test. If the network is available, connect to the server and log in. Otherwise, the startup fails.
  • After successful login, you can logcat See below in log

Test confirmation

  • confirm Androidmanifest.xml All needed in "Required" items have been added. If there are "Required" item is not added, the log will prompt an error.
  • confirm AppKey (exist Portal generated on) has been written correctly Androidmanifest.xml, there will be a log prompt error if not written.
  • Confirm that it is called when the program starts init(context)interface
  • Confirm that the network of the test mobile phone (or simulator) is available. If the network is available normally, the client calls init Shortly after, there should be a successful login (Login succeed) log information, such as SDK The startup process is shown
  • Start the application and log in Portal system and send customized messages or notification bar prompts to the application. Within a few seconds, the client should receive the delivered notification or definition message.

Alias ​​and label setting exception handling

Due to unstable network connection, there is a certain probability JPush SDK Setting aliases and tags will fail. App Developers handle setup failures appropriately and occasionally fail normal use of the app JPush The impact is limited.

The following is Android SDK As an example.

Basic idea:

  • When the setting is successful, go to SharePreference Write the status here, you don’t need to set it again in the future

  • meet 6002 If it times out, try again with a slight delay.

    // This is from JPush Example set alias Activity code inside. generally App The setting call entrance can be called from any convenient place. private void setAlias() {     EditText aliasEdit = (EditText) findViewById(R.id.et_alias);     String alias = aliasEdit.getText().toString().trim();     if (TextUtils.isEmpty(alias)) {         Toast.makeText(PushSetActivity.this,R.string.error_alias_empty, Toast.LENGTH_SHORT).show();         return;     }     if (!ExampleUtil.isValidTagAndAlias(alias)) {         Toast.makeText(PushSetActivity.this,R.string.error_tag_gs_empty, Toast.LENGTH_SHORT).show();         return;     }     // call Handler To set the alias asynchronously     mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_ALIAS, alias)); } private final TagAliasCallback mAliasCallback = new TagAliasCallback() {     @Override     public void gotResult(int code, String alias, Set<String> tags) {         String logs ;         switch (code) {         case 0:             logs = "Set tag and alias success";             Log.i(TAG, logs);             // It is recommended to go here SharePreference Write a status of successful setting. Once you successfully set it up once, you don't have to set it up again in the future.             break;         case 6002:             logs = "Failed to set alias and tags due to timeout. Try again after 60s.";             Log.i(TAG, logs);             // Delay 60 seconds to call Handler Set alias             mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SET_ALIAS, alias), 1000 * 60);             break;         default:             logs = "Failed with errorCode = " + code;             Log.e(TAG, logs);         }         ExampleUtil.showToast(logs, getApplicationContext());     } }; private static final int MSG_SET_ALIAS = 1001; private final Handler mHandler = new Handler() { @Override     public void handleMessage(android.os.Message msg) {         super.handleMessage(msg);         switch (msg.what) {          case MSG_SET_ALIAS:          Log.d(TAG, "Set alias in handler.");              // call JPush interface to set aliases.              JPushInterface.setAliasAndTags(getApplicationContext(),              (String) msg.obj,              null,              mAliasCallback);             break;         default:             Log.i(TAG, "Unhandled msg - " + msg.what);         }     }                   };
                // This is from JPush Example set alias Activity code inside. generally App The setting call entrance can be called from any convenient place.
      private void setAlias() {
          EditText aliasEdit = (EditText) findViewById(R.id.et_alias);
          String alias = aliasEdit.getText().toString().trim();
          if (TextUtils.isEmpty(alias)) {
              Toast.makeText(PushSetActivity.this,R.string.error_alias_empty, Toast.LENGTH_SHORT).show();
              return;
          }
          if (!ExampleUtil.isValidTagAndAlias(alias)) {
              Toast.makeText(PushSetActivity.this,R.string.error_tag_gs_empty, Toast.LENGTH_SHORT).show();
              return;
          }
    
          // call Handler To set the alias asynchronously
          mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_ALIAS, alias));
      }
    
      private final TagAliasCallback mAliasCallback = new TagAliasCallback() {
          @Override
          public void gotResult(int code, String alias, Set<String> tags) {
              String logs ;
              switch (code) {
              case 0:
                  logs = "Set tag and alias success";
                  Log.i(TAG, logs);
                  // It is recommended to go here SharePreference Write a status of successful setting. Once you successfully set it up once, you don't have to set it up again in the future.
                  break;
              case 6002:
                  logs = "Failed to set alias and tags due to timeout. Try again after 60s.";
                  Log.i(TAG, logs);
                  // Delay 60 seconds to call Handler Set alias
                  mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SET_ALIAS, alias), 1000 * 60);
                  break;
              default:
                  logs = "Failed with errorCode = " + code;
                  Log.e(TAG, logs);
              }
              ExampleUtil.showToast(logs, getApplicationContext());
          }
      };
      private static final int MSG_SET_ALIAS = 1001;
      private final Handler mHandler = new Handler() {
      @Override
          public void handleMessage(android.os.Message msg) {
              super.handleMessage(msg);
              switch (msg.what) {
                  case MSG_SET_ALIAS:
                      Log.d(TAG, "Set alias in handler.");
                      // call JPush interface to set aliases.
                      JPushInterface.setAliasAndTags(getApplicationContext(),
                                                      (String) msg.obj,
                                                       null,
                                                       mAliasCallback);
                  break;
              default:
                  Log.i(TAG, "Unhandled msg - " + msg.what);
              }
          }                                        
      };
    
            
    This code block is shown in the floating window

Android SDK Network problem analysis

Android The client network is unstable, which may cause App Sometimes it is not received in time Push information. Many developers think this is because JPush The push is unstable, delayed, and sometimes even JPush There is a problem with the background push system. The purpose of this article is to analyze from various aspects Android Caused by the Internet JPush Not working properly.

JPush Necessary conditions for normal operation

First, we need to know,JPush SDK is not integrated into App You will definitely have to work from now on.

The necessary conditions for its normal operation are:JPush SDK and JPush Server network remains connected. Please refer to this article for further understanding:JPushTechnical principle: Long-term connection of mobile wireless network.

and Android The complexity and instability of the device network are Android One of the most complex aspects of device development.

In addition, the network capabilities of each mobile phone vary widely. Many domestic no-name mobile phones even have serious network problems. Mobile phones from big brand manufacturers are much better.

if only JPush The network connection is normal, then:

  • JPush The message must be received promptly. The delay is on the second level, generally within 1 second. If it takes more than 10 seconds, there must be a problem with the client network.
  • Even when your phone is sleeping, you can receive push messages in a timely manner.

Special processing of some systems causes problems

MIUI V5 system

  • Self-startup management: By default, after the phone is turned on, only the system's default services can be started. Unless in the self-start management interface, the settings allow third-party programs to start automatically.
  • Network Assistant: You can manually block access to installed third-party programs 2G/3G and WIFI network and settings to allow new installers to access in the future. 2G/3G and WIFI network.

4.0 above android system

  • In Settings->Applications, force stop the application and the program will no longer be able to start automatically, even if you restart the computer, it must be started manually before it can run.

Let us sort out debugging ideas based on the feedback we have received so far.

1. Cannot receive when the phone is sleeping JPush The message can be received successfully if it is unlocked or the screen light is on

This phenomenon shows that when the phone is sleeping,JPush SDK "Forced" to lose connection with the server-side network.

JPush SDK The working principle is to ensure that the phone can work normally when it is sleeping, that is, it can receive messages in time even when it is sleeping. Push information. actually JPush This effect can be achieved on most mobile phones.

This "forced" is caused by Android Caused by the environment of the device. The reasons involved are as follows:

  • The network settings of the phone itself. standard version Android ROM There is no such setting, but some special ROM There may be settings for this.
  • Additional things that security and power-saving tool software on mobile phones do

The special mechanism described above will shut down the network. Once the network is connected,JPush will also connect to the server, thus Push The message will be received.

2. Sometimes I receive JPush The news is very timely, sometimes it takes a few minutes

JPush Will listen for network switching broadcasts. When the network is shut down, the original JPush The connection is closed. When there is a new network, create JPush connect.

in addition,RTC Heartbeats will be sent regularly. If the previous network was disconnected, it will be reconnected.

It should be said that the current network connection strategy is relatively simple, and the purpose of this is to save power and traffic.

The bad thing is: when the network is not switched, because the network is too poor at that time,JPush The connection will be interrupted. In this case, all you can do is wait RTC Heartbeat to trigger connection. This is also sometimes JPush Unable to receive in time Push The reason for the message. Depending on the network conditions, the probability of this happening will also be different. But according to our own testing, 90% of the time it can be received in time. Push news.

JPush Currently, no chat tool like WeChat is doing as aggressively in terms of network strategy. If this is done, the consumption of power and traffic will inevitably increase exponentially.

3. Can’t receive it at all JPush information

If you integrate it, you won’t be able to receive it at all. Push message, it is likely that there is a configuration error somewhere. Check the client log first and coordinate with the documentation to locate: Android SDK Integration GuideiOS SDK Integration Guide, Or refer to the tutorial: Android SDK Debugging GuideiOS SDK Debugging Guide

Was this document helpful?

Copyright 2011-2026, jiguang.cn, All Rights Reserved. 粤ICP备12056275号-13 Shenzhen Hexun Huagu Information Technology Co., Ltd.

Open in Docs Center