All Products
Document Center

Privacy permission

Last Updated: Mar 10, 2021


The regulatory authority requires that the app cannot call related sensitive APIs before the user clicks the Agree button in the privacy agreement dialog box. In response to this regulatory requirement, the baselines of mPaaS Android or later versions and or later version are supported. Refer to this topic to modify the project according to the actual situation.


  1. Create a new callback class of privacy permission dialog box.
    Create a new class in the code and implement the PrivacyListener API operation. For the implementation of the class, see the following code:

    1. public class MyPrivacyListener implements PrivacyListener {
    2. // Make a privacy permission dialog box in this method
    3. @Override
    4. public void showPrivacy(final Activity activity, final PrivacyResultCallback privacyResultCallback) {
    5. if(null==privacyResultCallback){
    6. return;
    7. }
    8. if(null!=activity){
    9. new AlertDialog.Builder(activity)
    10. .setTitle("Privacy permission dialog box")
    11. .setMessage("Main content")
    12. .setPositiveButton("Agree to continue to use", new DialogInterface.OnClickListener() {
    13. @Override
    14. public void onClick(DialogInterface dialogInterface, int i) {
    15. // After you click OK, cancel the dialog box
    16. dialogInterface.cancel();
    17. // Set the dialog box result to true
    18. privacyResultCallback.onResult(true);
    19. }
    20. })
    21. .setNegativeButton("Disagree and exit", new DialogInterface.OnClickListener() {
    22. @Override
    23. public void onClick(DialogInterface dialogInterface, int i) {
    24. // After you click Disagree, cancel the dialog box
    25. dialogInterface.cancel();
    26. // Set the dialog box result to false
    27. privacyResultCallback.onResult(false);
    28. // End the current activity, the framework will kill the process
    29. if(null!=activity){
    30. activity.finish();
    31. }
    32. }
    33. })
    34. .setCancelable(false)
    35. .create()
    36. .show();
    37. }else{
    38. // If the activity is empty, the callback result is set to false
    39. privacyResultCallback.onResult(false);
    40. }
    41. }
    42. }
    • During the callback, a dialog box must be used to trigger windowFocusChange. The framework will perform subsequent operations after triggering.
    • Because the callback class will be reflectively initialized by the system framework and scheduled very early, do not add a constructor with a method name. In addition, do not add specific logic to the constructor.
    • If you need to use resources in the dialog box, you need to use different methods under different baselines.
      • Under the 32 baseline, you need to use the following method:
        Resources resource = QuinoxAgent.getInstance().getResourcesByBundle("bundlename of the Bundle where the resource is located");
        Note: The bundlename can be checked in /build/intermediates/bundle/META-INF/BUNDLE.MF in the main module of the Bundle project.
      • Under the 60 baseline, you need to create the res_slinks file under the main module of the Portal project, and write the group and artifact of the Bundle where your resources are located in the res_slinks file according to the rule. The rule is group-artifact.split("-")[0]. When the content is too long, you need to check whether the content is correct if you want to add a new line.
        For example:
        group = com.mpaas.demo.materialdesign
        artifact = materialdesign-build,
        The final configuration written into the res_slinks file is com.mpaas.demo.materialdesign-materialdesign.
      • After completing the preceding content, you can directly use LayoutInflator.inflate( to call resources.
  2. Register the callback class in AndroidManifest.
    Register the callback class of privacy permission dialog box in the AndroidManifest of portal, and value is the full path of the callback class implemented just now.The code is shown as follows. Note that you need to replace the full path and class name with your own callback class.

    1. <!--callback of privacy permission dialog box-->
    2. <meta-data
    3. android:name="privacy.listener"
    4. android:value="com.mpaas.demo.launcher.MyPrivacyListener" />
  3. The box is shown at startup.
    In MockLauncherApplicationAgent,preInit add the interception of the dialog box. The code is as follows:

    1. //Check if you want to display a privacy permission dialog box to the user
    2. if(! PrivacyUtil.isUserAgreed(getApplicationContext())){
    3. PermissionGate.getInstance().waitForUserConform(mContext, getMicroApplicationContext());
    4. }
  4. Start the first Activity.
    In the postInit of MockLauncherActivityAgent, make the first Activity jump. The code is as follows:

    1. // Determine whether the user privacy permission has been obtained
    2. if(PrivacyUtil.isUserAgreed(activity)){
    3. new Handler().postDelayed(new Runnable() {
    4. public void run() {
    5. Intent intent = new Intent(activity, MainActivity.class);
    6. activity.startActivity(intent);
    7. activity.finish();
    8. }
    9. }, 200);
    10. }