Detected problems with API pop shielding solutions android

 

 Recent test project MM feedback every time you enter app, will prompt a pop.

The survey found that the test is generated on the android9.0 system, information is shared Pit comprehensive online before you. First pro-test solutions available for everyone to share the hope that a small partner encountered such problems can be resolved quickly

Cause Analysis

Android P is android9.0 Google restrict developers call the unofficial public API or interface method (using @hide annotation system source code), when the developer calls the source code will be reflected directly above tips box. Google aims to prompt developers to minimize the use of reflection only call the system api, so as to avoid unnecessary trouble. But the project, to use some functions realized how to do? Even if we do not, rely on third-party libraries, use how to do? This pit. Therefore, negative negative positive, ha, hate back in a reflective shield tips.

//在app初始化时调用即可
public class MyApplication extends Application {

    public JoyApplication() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        disableAPIDialog();
    } 
     /**
      * 反射 禁止弹窗
     */
    private void disableAPIDialog(){
       if (Build.VERSION.SDK_INT < 28)return;
       try {
            Class clazz = Class.forName("android.app.ActivityThread");
         Method currentActivityThread = clazz.getDeclaredMethod("currentActivityThread");
         currentActivityThread.setAccessible(true);
         Object activityThread = currentActivityThread.invoke(null);
         Field mHiddenApiWarningShown = clazz.getDeclaredField("mHiddenApiWarningShown");
         mHiddenApiWarningShown.setAccessible(true);
         mHiddenApiWarningShown.setBoolean(activityThread, true);
       } catch (Exception e) {
           e.printStackTrace();
       }
   }

}

 

Released four original articles · won praise 15 · views 10000 +

Guess you like

Origin blog.csdn.net/zpjsmalltime/article/details/86577058