Google Billing导致我的应用崩溃,因为将屏幕模式更改为纵向。

huangapple go评论60阅读模式
英文:

Google Billing crash my app because change screen mode to portrate

问题

我有一个具有清晰架构的标准计费客户端,我的计费客户端不知道活动。我将活动作为参数发送给计费客户端的方法,仅此而已。
我的应用程序的屏幕模式为传感器横向。我在清单文件和BaseActivity中声明了它。

清单文件

android:screenOrientation="sensorLandscape"

BaseActivity onCreate

requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE

当我点击应用程序上的购买某些产品的按钮时,在某些旧设备上工作良好,但在新设备上崩溃,出现Resources$NotFoundException。这是因为当前我的应用程序位于纵向模式,在某些设备上购物菜单以横向模式调用,而在其他设备上以纵向模式调用,我无法理解为什么会出现这种情况。

我尝试在客户端的计费方法中设置横向传感器,其中我传递了活动参数,但没有帮助。最有可能的是,您需要查看库本身。

com.android.billingclient:billing-ktx:6.0.0

当我点击购买时,我的活动调用onPause导致崩溃。

日志如下图所示:

Google Billing导致我的应用崩溃,因为将屏幕模式更改为纵向。

尝试以下代码:

open class BaseApplication : Application.ActivityLifecycleCallbacks {

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

    override fun onActivityStarted(activity: Activity) {
        activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

    override fun onActivityResumed(activity: Activity) {
        activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

    override fun onActivityPaused(activity: Activity) {
        activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

    override fun onActivityStopped(activity: Activity) {
        activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
        activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

    override fun onActivityDestroyed(activity: Activity) {
        activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

}

class MyApplication : Application() {

    init {
        instance = this
    }

    companion object {
        private var instance: MyApplication? = null

        @JvmStatic
        fun getContext(): Context {
            return instance!!.applicationContext
        }
    }

    override fun onCreate() {
        super.onCreate()
        registerActivityLifecycleCallbacks(BaseApplication())
    }
}

但没有帮助。

英文:

I have standard billing client with clear architecture, my billing clieant does not know about activity. I Send to billing client activity like a param on his method no more.
My app has screen mode = sensore landscape. I declare that on manifest and on BaseActivity.

Manifest

android:screenOrientation="sensorLandscape"

BaseActivity onCreate

   requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE

When i click on btn for buy some products on my App
I have on some old device good working and on new device crash like Resources$NotFoundException. This is due to the fact that no resources were found for the portrait mode in which my application is currently located. I cannot understand why on some devices the shopping menu is called in landscape mode and on others in portrait mode.
I tried to set the Landscape sensor in the client's billing methods, where I transfer the activity parameter, but it did not help. Most likely, you have to go to the library itself

com.android.billingclient:billing-ktx:6.0.0

When I click BUY my activity call onPause that crash
LOG on picture
Google Billing导致我的应用崩溃,因为将屏幕模式更改为纵向。

TRY

open class BaseApplication : Application.ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
override fun onActivityStarted(activity: Activity) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
override fun onActivityResumed(activity: Activity) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
override fun onActivityPaused(activity: Activity) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
override fun onActivityStopped(activity: Activity) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
override fun onActivityDestroyed(activity: Activity) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
}

Myaplication

class MyApplication: Application() {
init {
instance = this
}
companion object {
private var instance: MyApplication? = null
@JvmStatic
fun getContext(): Context {
return instance!!.applicationContext
}
}
override fun onCreate() {
super.onCreate()
registerActivityLifecycleCallbacks(BaseApplication())
}
}

but don't help

答案1

得分: 1

这是Google的一个错误。Google计费客户端在纵向屏幕模式下调用。在Google计费库升级到6.0.1版本后,此错误已得到修复。但在此链接中没有关于此错误的任何信息。

英文:

It is Google bug. Google billing client called on portrait screen mode. After Google billing library update to 6.0.1 version this bug is fixed.
But on this link nothing information about this bug.

huangapple
  • 本文由 发表于 2023年6月5日 19:29:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405976.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定