Some Problems in Opening pdf Online by Tencent x5

Keywords: Mobile Android SDK

1. Use QbSdk or choose TbsReaderView

  • Using Qbsdk

      int i = QbSdk.openFileReader(context, filePath, null, new ValueCallback<String>() {
      	@Override
      	public void onReceiveValue(String s) {
      		KLog.d("onReceiveValue==" + s);
      	}
      }); 
    
  • Using TbsReaderView

      TbsReaderView mTbsReaderView = new TbsReaderView(presenter.exposeActivity(), new TbsReaderView.ReaderCallback() {
      	@Override
      	public void onCallBackAction(Integer integer, Object o, Object o1) {
      		Log.d("lm", "onCallBackAction: " + integer);
      	}
      });
      
      //Note: To show the effect, you need to add to the content layout. If not added, the display page will have offset error.
      ViewGroup viewGroup = presenter.exposeActivity().findViewById(android.R.id.content);
      viewGroup.addView(mTbsReaderView);
      
      //Prevent Layout Parameter Settings from Failing
      mTbsReaderView.post(new Runnable() {
      	@Override
      	public void run() {
      	//Add title
      		FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
      		layoutParams.topMargin = actionBar height+Status bar height
      		mTbsReaderView.setLayoutParams(layoutParams);
      	}
      });
      
      //First parameter: file type
      boolean bool = mTbsReaderView.preOpen("pdf", false);
      if (bool) {
      	Bundle bundle = new Bundle();
      	bundle.putString("filePath", path);//Files for storing pdf
      	//A directory for temporary files. After running, files of.tbs... will be generated in the directory of path2.
      	bundle.putString("tempPath", path2);
      	mTbsReaderView.openFile(bundle);
      }
      
      //At the end of the presentation, be sure to call it. Otherwise, it will always be loaded.
      mTbsReaderView.onStop();
    
  • Difference

    • Qbsdk: On the first load, the pop-up window of the selected application will pop up. It needs to be closed and reopened before the plug-in can be loaded. The pages displayed will have other contents: for example, the bottom display directory (need to download QQ browser)
    • TbsReaderView: Load the plug-in directly for the first time. Experience better
  • Same points

    You can only view local pdf, so for online files, you need to download them locally first.

  • Be careful

    After accessing TBS, TBS will share the x5 kernel using Weixin and Hand Q. Often, developers'test phones do not install the x5 kernel because they do not often use Weixin or debug it. In addition, the remaining 2% of users who do not have the Weixin kernel source online, TBS will download the kernel itself under the condition of wifi (which is also the reason why it is slower to load for the first time).

2. Problems in Use

  • Red Rice Mobile Phone Failed to Load Plug-ins
    1. See if the so file is added
    2. Whether to add "arm64-v8a" in NDK {abiFilters}. If so, delete it.
      Specific reasons for reference Add Link Description
    3. Check dependencies for jar packages that depend on tbs. (On other mobile phones, even if there is no dependencies, it can run normally. This is the case when the dependency is removed after the first load, and then the dependency can run properly without dependency.

Posted by NiGHTFiRE on Thu, 31 Jan 2019 22:21:15 -0800