Open ZhaoYidong opened 3 years ago
遇到这个问题+1,用了这个库基本上很难兼容到谷歌的AdActivity,因为调用加载广告的方法的时候,admob就会拿当前application的DisplayMetrics去上报平台获取对应尺寸的广告。然后展示广告的时候又会基于当前activity的dpi展示广告View。所以其实加载和填充都会影响到admob的广告展示大小。 实在需要兼容就只能是load广告前调用下cancelAdapt,然后在恢复adapt,但有坑
大牛,我也遇到了这个问题,用里面的方式制定尺寸config.getExternalAdaptManager().addExternalAdaptInfoOfActivity(com.google.android.gms.ads.AdActivity.class, new ExternalAdaptInfo(true, 540)); 或是去掉适配 config.getExternalAdaptManager().addCancelAdaptOfActivity(com.google.android.gms.ads.AdActivity.class);
都还是不行,不知道怎么解决,请帮忙。
Google 开屏广告类为 com.google.android.gms.ads.AdActivity,使用屏幕适配方案后,全屏广告不全屏了,如下图所示: 请问有什么方法能去掉第三方的 AdActivity 使用屏幕适配方案吗?
兄弟,问题解决了吗?
249
大牛,我进去看了 感觉没找到答案
看 这句话,使用 #249 的方案在 APP 启动时取消适配,然后在第一个页面 onCreate 前调用 AutoSize.checkAndInit(Application)
看 这句话,使用 #249 的方案在 APP 启动时取消适配,然后在第一个页面 onCreate 前调用 AutoSize.checkAndInit(Application)
不行啊大佬,application取消适配后,然后welcome页面设置 AutoSize.checkAndInit(getApplication()); super.onCreate(savedInstanceState); 直接就不能适配了,后面的页面 怎么办
是 welcome 页面能适配,只是后面的页面不能适配;还是 welcome 页面以及后面的页面都不能适配。
断点看看,是不是框架的启动慢于 super.onCreate(savedInstanceState); 了
如果是框架的启动慢于 super.onCreate(savedInstanceState); ,看能不能提早调用 AutoSize.checkAndInit(getApplication()); 提前初始化框架,或者延后第一个页面的启动,或者框架设置 density 后,手动重绘当前页面的所有view
是 welcome 页面能适配,只是后面的页面不能适配;还是 welcome 页面以及后面的页面都不能适配。
断点看看,是不是框架的启动慢于 super.onCreate(savedInstanceState); 了
如果是框架的启动慢于 super.onCreate(savedInstanceState); ,看能不能提早调用 AutoSize.checkAndInit(getApplication()); 提前初始化框架,或者延后第一个页面的启动,或者框架设置 density 后,手动重绘当前页面的所有view
对 我就是延迟搞的
这个问题我差不多解决了 加载广告的时候使用adjustAutoSize方法包装一下applicationContext
Context context = adjustAutoSize(applicationContext);
AppOpenAd.load(context, placementId,request,AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT, appOpenAdLoadCallback);
adjustAutoSize是下面CancelAdapterContextWrapper类的一个静态方法,注意除了这些代码还要配合
config.getExternalAdaptManager().addCancelAdaptOfActivity(com.google.android.gms.ads.AdActivity.class);
使用
public class CancelAdapterContextWrapper extends ContextWrapper {
private Resources mResources;
private Context applicationContext;
public CancelAdapterContextWrapper(Context context) {
super(context);
Resources oldResources = super.getResources();
mResources = new Resources(oldResources.getAssets(), oldResources.getDisplayMetrics(), oldResources.getConfiguration());
if (Looper.myLooper() == Looper.getMainLooper()) {
AutoSizeCompat.cancelAdapt(mResources);
} else {
Tools.post(() -> AutoSizeCompat.cancelAdapt(mResources));
}
applicationContext = new CancelAdapterApplication(context.getApplicationContext());
}
@Override
public Resources getResources() {
if (Looper.myLooper() == Looper.getMainLooper()) {
AutoSizeCompat.cancelAdapt(mResources);
}
Log.d("CancelAdapterContext", "CancelAdapterContextWrapper getResources: ");
return mResources;
}
@Override
public Context getApplicationContext() {
return applicationContext;
}
public static Context adjustAutoSize(Context context) {
return new CancelAdapterContextWrapper(context);
}
}
public class CancelAdapterApplication extends Application {
Application mApplication;
private Resources mResources;
public CancelAdapterApplication(Context applicationContext) {
super();
mApplication = (Application) applicationContext.getApplicationContext();
super.attachBaseContext(mApplication.getBaseContext());
TempoCrashFixer.fixCustomApplication(mApplication, this);
Resources resources = mApplication.getResources();
mResources = new Resources(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
if (Looper.myLooper() == Looper.getMainLooper()) {
AutoSizeCompat.cancelAdapt(mResources);
} else {
Tools.post(() -> AutoSizeCompat.cancelAdapt(mResources));
}
}
@Override
public void registerComponentCallbacks(ComponentCallbacks callback) {
mApplication.registerComponentCallbacks(callback);
}
@Override
public void unregisterComponentCallbacks(ComponentCallbacks callback) {
mApplication.unregisterComponentCallbacks(callback);
}
@Override
public void registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) {
mApplication.registerActivityLifecycleCallbacks(callback);
}
@Override
public void unregisterActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) {
mApplication.unregisterActivityLifecycleCallbacks(callback);
}
@Override
public void registerOnProvideAssistDataListener(OnProvideAssistDataListener callback) {
mApplication.registerOnProvideAssistDataListener(callback);
}
@Override
public void unregisterOnProvideAssistDataListener(OnProvideAssistDataListener callback) {
mApplication.unregisterOnProvideAssistDataListener(callback);
}
@Override
public Context getBaseContext() {
return mApplication.getBaseContext();
}
@Override
public AssetManager getAssets() {
return mApplication.getAssets();
}
@Override
public Resources getResources() {
if (Looper.myLooper() == Looper.getMainLooper()) {
AutoSizeCompat.cancelAdapt(mResources);
}
Log.d("CancelAdapterContext", "CancelAdapterApplication getResources: ");
return mResources;
}
@Override
public PackageManager getPackageManager() {
return mApplication.getPackageManager();
}
@Override
public ContentResolver getContentResolver() {
return mApplication.getContentResolver();
}
@Override
public Looper getMainLooper() {
return mApplication.getMainLooper();
}
@RequiresApi(api = Build.VERSION_CODES.P)
@Override
public Executor getMainExecutor() {
return mApplication.getMainExecutor();
}
@Override
public Context getApplicationContext() {
return mApplication.getApplicationContext();
}
@Override
public void setTheme(int resid) {
mApplication.setTheme(resid);
}
@Override
public Resources.Theme getTheme() {
return mApplication.getTheme();
}
@Override
public ClassLoader getClassLoader() {
return mApplication.getClassLoader();
}
@Override
public String getPackageName() {
return mApplication.getPackageName();
}
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public String getOpPackageName() {
return mApplication.getOpPackageName();
}
@Override
public ApplicationInfo getApplicationInfo() {
return mApplication.getApplicationInfo();
}
@Override
public String getPackageResourcePath() {
return mApplication.getPackageResourcePath();
}
@Override
public String getPackageCodePath() {
return mApplication.getPackageCodePath();
}
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
return mApplication.getSharedPreferences(name, mode);
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
return mApplication.moveSharedPreferencesFrom(sourceContext, name);
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public boolean deleteSharedPreferences(String name) {
return mApplication.deleteSharedPreferences(name);
}
@Override
public FileInputStream openFileInput(String name) throws FileNotFoundException {
return mApplication.openFileInput(name);
}
@Override
public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
return mApplication.openFileOutput(name, mode);
}
@Override
public boolean deleteFile(String name) {
return mApplication.deleteFile(name);
}
@Override
public File getFileStreamPath(String name) {
return mApplication.getFileStreamPath(name);
}
@Override
public String[] fileList() {
return mApplication.fileList();
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public File getDataDir() {
return mApplication.getDataDir();
}
@Override
public File getFilesDir() {
return mApplication.getFilesDir();
}
@Override
public File getNoBackupFilesDir() {
return mApplication.getNoBackupFilesDir();
}
@Override
public File getExternalFilesDir(String type) {
return mApplication.getExternalFilesDir(type);
}
@Override
public File[] getExternalFilesDirs(String type) {
return mApplication.getExternalFilesDirs(type);
}
@Override
public File getObbDir() {
return mApplication.getObbDir();
}
@Override
public File[] getObbDirs() {
return mApplication.getObbDirs();
}
@Override
public File getCacheDir() {
return mApplication.getCacheDir();
}
@Override
public File getCodeCacheDir() {
return mApplication.getCodeCacheDir();
}
@Override
public File getExternalCacheDir() {
return mApplication.getExternalCacheDir();
}
@Override
public File[] getExternalCacheDirs() {
return mApplication.getExternalCacheDirs();
}
@Override
public File[] getExternalMediaDirs() {
return mApplication.getExternalMediaDirs();
}
@Override
public File getDir(String name, int mode) {
return mApplication.getDir(name, mode);
}
@Override
public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
return mApplication.openOrCreateDatabase(name, mode, factory);
}
@Override
public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
return mApplication.openOrCreateDatabase(name, mode, factory, errorHandler);
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public boolean moveDatabaseFrom(Context sourceContext, String name) {
return mApplication.moveDatabaseFrom(sourceContext, name);
}
@Override
public boolean deleteDatabase(String name) {
return mApplication.deleteDatabase(name);
}
@Override
public File getDatabasePath(String name) {
return mApplication.getDatabasePath(name);
}
@Override
public String[] databaseList() {
return mApplication.databaseList();
}
@Override
public Drawable getWallpaper() {
return mApplication.getWallpaper();
}
@Override
public Drawable peekWallpaper() {
return mApplication.peekWallpaper();
}
@Override
public int getWallpaperDesiredMinimumWidth() {
return mApplication.getWallpaperDesiredMinimumWidth();
}
@Override
public int getWallpaperDesiredMinimumHeight() {
return mApplication.getWallpaperDesiredMinimumHeight();
}
@Override
public void setWallpaper(Bitmap bitmap) throws IOException {
mApplication.setWallpaper(bitmap);
}
@Override
public void setWallpaper(InputStream data) throws IOException {
mApplication.setWallpaper(data);
}
@Override
public void clearWallpaper() throws IOException {
mApplication.clearWallpaper();
}
@Override
public void startActivity(Intent intent) {
mApplication.startActivity(intent);
}
@Override
public void startActivity(Intent intent, Bundle options) {
mApplication.startActivity(intent, options);
}
@Override
public void startActivities(Intent[] intents) {
mApplication.startActivities(intents);
}
@Override
public void startActivities(Intent[] intents, Bundle options) {
mApplication.startActivities(intents, options);
}
@Override
public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException {
mApplication.startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
}
@Override
public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException {
mApplication.startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, options);
}
@Override
public void sendBroadcast(Intent intent) {
mApplication.sendBroadcast(intent);
}
@Override
public void sendBroadcast(Intent intent, String receiverPermission) {
mApplication.sendBroadcast(intent, receiverPermission);
}
@Override
public void sendOrderedBroadcast(Intent intent, String receiverPermission) {
mApplication.sendOrderedBroadcast(intent, receiverPermission);
}
@Override
public void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
mApplication.sendOrderedBroadcast(intent, receiverPermission, resultReceiver, scheduler, initialCode, initialData, initialExtras);
}
@SuppressLint("MissingPermission")
@Override
public void sendBroadcastAsUser(Intent intent, UserHandle user) {
mApplication.sendBroadcastAsUser(intent, user);
}
@SuppressLint("MissingPermission")
@Override
public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission) {
mApplication.sendBroadcastAsUser(intent, user, receiverPermission);
}
@SuppressLint("MissingPermission")
@Override
public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
mApplication.sendOrderedBroadcastAsUser(intent, user, receiverPermission, resultReceiver, scheduler, initialCode, initialData, initialExtras);
}
@SuppressLint("MissingPermission")
@Override
public void sendStickyBroadcast(Intent intent) {
mApplication.sendStickyBroadcast(intent);
}
@SuppressLint("MissingPermission")
@Override
public void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
mApplication.sendStickyOrderedBroadcast(intent, resultReceiver, scheduler, initialCode, initialData, initialExtras);
}
@Override
public void removeStickyBroadcast(Intent intent) {
mApplication.removeStickyBroadcast(intent);
}
@SuppressLint("MissingPermission")
@Override
public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
mApplication.sendStickyBroadcastAsUser(intent, user);
}
@SuppressLint("MissingPermission")
@Override
public void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
mApplication.sendStickyOrderedBroadcastAsUser(intent, user, resultReceiver, scheduler, initialCode, initialData, initialExtras);
}
@SuppressLint("MissingPermission")
@Override
public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
mApplication.removeStickyBroadcastAsUser(intent, user);
}
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
return mApplication.registerReceiver(receiver, filter);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags) {
return mApplication.registerReceiver(receiver, filter, flags);
}
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler) {
return mApplication.registerReceiver(receiver, filter, broadcastPermission, scheduler);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler, int flags) {
return mApplication.registerReceiver(receiver, filter, broadcastPermission, scheduler, flags);
}
@Override
public void unregisterReceiver(BroadcastReceiver receiver) {
mApplication.unregisterReceiver(receiver);
}
@Override
public ComponentName startService(Intent service) {
return mApplication.startService(service);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public ComponentName startForegroundService(Intent service) {
return mApplication.startForegroundService(service);
}
@Override
public boolean stopService(Intent name) {
return mApplication.stopService(name);
}
@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
return mApplication.bindService(service, conn, flags);
}
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public boolean bindService(Intent service, int flags, Executor executor, ServiceConnection conn) {
return mApplication.bindService(service, flags, executor, conn);
}
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public boolean bindIsolatedService(Intent service, int flags, String instanceName, Executor executor, ServiceConnection conn) {
return mApplication.bindIsolatedService(service, flags, instanceName, executor, conn);
}
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public void updateServiceGroup(ServiceConnection conn, int group, int importance) {
mApplication.updateServiceGroup(conn, group, importance);
}
@Override
public void unbindService(ServiceConnection conn) {
mApplication.unbindService(conn);
}
@Override
public boolean startInstrumentation(ComponentName className, String profileFile, Bundle arguments) {
return mApplication.startInstrumentation(className, profileFile, arguments);
}
@Override
public Object getSystemService(String name) {
return mApplication.getSystemService(name);
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public String getSystemServiceName(Class<?> serviceClass) {
return mApplication.getSystemServiceName(serviceClass);
}
@Override
public int checkPermission(String permission, int pid, int uid) {
return mApplication.checkPermission(permission, pid, uid);
}
@Override
public int checkCallingPermission(String permission) {
return mApplication.checkCallingPermission(permission);
}
@Override
public int checkCallingOrSelfPermission(String permission) {
return mApplication.checkCallingOrSelfPermission(permission);
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public int checkSelfPermission(String permission) {
return mApplication.checkSelfPermission(permission);
}
@Override
public void enforcePermission(String permission, int pid, int uid, String message) {
mApplication.enforcePermission(permission, pid, uid, message);
}
@Override
public void enforceCallingPermission(String permission, String message) {
mApplication.enforceCallingPermission(permission, message);
}
@Override
public void enforceCallingOrSelfPermission(String permission, String message) {
mApplication.enforceCallingOrSelfPermission(permission, message);
}
@Override
public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
mApplication.grantUriPermission(toPackage, uri, modeFlags);
}
@Override
public void revokeUriPermission(Uri uri, int modeFlags) {
mApplication.revokeUriPermission(uri, modeFlags);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void revokeUriPermission(String targetPackage, Uri uri, int modeFlags) {
mApplication.revokeUriPermission(targetPackage, uri, modeFlags);
}
@Override
public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
return mApplication.checkUriPermission(uri, pid, uid, modeFlags);
}
@Override
public int checkCallingUriPermission(Uri uri, int modeFlags) {
return mApplication.checkCallingUriPermission(uri, modeFlags);
}
@Override
public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
return mApplication.checkCallingOrSelfUriPermission(uri, modeFlags);
}
@Override
public int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags) {
return mApplication.checkUriPermission(uri, readPermission, writePermission, pid, uid, modeFlags);
}
@Override
public void enforceUriPermission(Uri uri, int pid, int uid, int modeFlags, String message) {
mApplication.enforceUriPermission(uri, pid, uid, modeFlags, message);
}
@Override
public void enforceCallingUriPermission(Uri uri, int modeFlags, String message) {
mApplication.enforceCallingUriPermission(uri, modeFlags, message);
}
@Override
public void enforceCallingOrSelfUriPermission(Uri uri, int modeFlags, String message) {
mApplication.enforceCallingOrSelfUriPermission(uri, modeFlags, message);
}
@Override
public void enforceUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags, String message) {
mApplication.enforceUriPermission(uri, readPermission, writePermission, pid, uid, modeFlags, message);
}
@Override
public Context createPackageContext(String packageName, int flags) throws PackageManager.NameNotFoundException {
return mApplication.createPackageContext(packageName, flags);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public Context createContextForSplit(String splitName) throws PackageManager.NameNotFoundException {
return mApplication.createContextForSplit(splitName);
}
@Override
public Context createConfigurationContext(Configuration overrideConfiguration) {
return mApplication.createConfigurationContext(overrideConfiguration);
}
@Override
public Context createDisplayContext(Display display) {
return mApplication.createDisplayContext(display);
}
@Override
public boolean isRestricted() {
return mApplication.isRestricted();
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public Context createDeviceProtectedStorageContext() {
return mApplication.createDeviceProtectedStorageContext();
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public boolean isDeviceProtectedStorage() {
return mApplication.isDeviceProtectedStorage();
}
}
这个问题我差不多解决了 加载广告的时候使用adjustAutoSize方法包装一下applicationContext
请问一下这个方案可以解决吗?能发个完整的解决方案吗?比如 TempoCrashFixer.fixCustomApplication(mApplication, this); 这个有什么处理吗?
这个问题我差不多解决了 加载广告的时候使用adjustAutoSize方法包装一下applicationContext
请问一下这个方案可以解决吗?能发个完整的解决方案吗?比如 TempoCrashFixer.fixCustomApplication(mApplication, this); 这个有什么处理吗?
没有完全解决,有时候还是有问题, TempoCrashFixer.fixCustomApplication(mApplication, this);的具体代码已经忘了,大概是就是反射修改了CancelAdapterApplication的mLoadedApk的mApplication参数为指定的前面的mApplication,也可能是反过来
Google 开屏广告类为 com.google.android.gms.ads.AdActivity,使用屏幕适配方案后,全屏广告不全屏了,如下图所示: 请问有什么方法能去掉第三方的 AdActivity 使用屏幕适配方案吗?