小编Use*_*163的帖子

您应该在“onBillingServiceDisconnected()”中放入什么?

这是我的方法:

public void setupBillingClient() { //connect to google play
    
        billingClient = BillingClient.newBuilder(context)
                .enablePendingPurchases()
                .setListener(this)
                .build();

        billingClient.startConnection(new BillingClientStateListener() {

            @Override
            public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    //The BillingClient is setup successfully
                    loadAllSkus();
                }
            }

            @Override
            public void onBillingServiceDisconnected() {
                //TODO: implement retry logic to handle lost connections to Google Play by calling startConnection() again
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

谷歌说我应该“实现重试逻辑”,但没有说明如何实现。我想也许只是打电话setupBillingClient()进去onBillingServiceDisconnected(),但有些人说这会导致崩溃。另外,我觉得如果有那么简单,那么谷歌就会告诉我们这样写,而不是模糊的指令来实现重试逻辑。

java android in-app-billing

7
推荐指数
1
解决办法
1487
查看次数

每当用户打开应用程序时,如何检查用户是否购买了应用内购买?

注意:我说的是一次性购买,可以从应用程序中删除广告。

谷歌说你应该打电话BillingClient.queryPurchases()给你onResume()的,onCreate()但我不知道该怎么做。

首先,这是实际应用内购买的代码,我刚刚从 YouTube 教程中获得它,我什至不知道它是否完整:

private void setupBillingClient(Context c) { //connect to google play
    billingClient = BillingClient.newBuilder(c)
            .enablePendingPurchases()
            .setListener(this)
            .build();
    billingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                //The BillingClient is setup successfully
                loadAllSkus();
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
            //TODO: implement retry logic to handle lost connections to Google Play by calling startConnection() again
        }
    });
}

private void loadAllSkus() {
    if (billingClient.isReady()) { //first …
Run Code Online (Sandbox Code Playgroud)

java android in-app-purchase in-app-billing

5
推荐指数
1
解决办法
4730
查看次数

如何在 Android 10 中以编程方式重新启动应用程序?

我想要一种在用户进行任何删除广告横幅的应用内购买后重新启动应用程序的方法,以便onCreate()再次调用这些方法。

\n

问题是,我不\xe2\x80\x99不希望任何服务被终止,我只想应用程序以更改的限制重新启动

\n

我在 Stack Overflow 上找到了这段代码:

\n
Intent mStartActivity = new Intent(getApplicationContext(), MainActivity.class);\nint mPendingIntentId = 123456;\nPendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);\nAlarmManager mgr = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);\nmgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);\nSystem.exit(0);\n
Run Code Online (Sandbox Code Playgroud)\n

java android

4
推荐指数
1
解决办法
9611
查看次数

如何为自定义对话框设置圆角?

这是我的自定义对话框的代码:

public class DialogBrightness extends AppCompatDialogFragment {

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.layout_dialog, null);
    
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    /*Build and create the dialog here*/
    
    }
}
Run Code Online (Sandbox Code Playgroud)

我按照其他答案的说明首先创建了这个称为 dialog_bg 的可绘制 xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid
            android:color="#fff5ee"/>
        <corners
            android:radius="30dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

然后将其设置为 layout_dialog xml 的背景:

android:background="@drawable/dialog_bg"
Run Code Online (Sandbox Code Playgroud)

但我无法完成将对话框的根视图设置为透明的最后一步:

dialogBrightness.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Run Code Online (Sandbox Code Playgroud)

因为没有 getWindow() 函数。

另外,当他们说 root view 时,他们的意思是我在上面的 inflate 函数中设置为 null 的那个吗?

java android android-alertdialog android-dialogfragment material-components-android

3
推荐指数
1
解决办法
279
查看次数

如何为工具栏制作圆角?

我看过其他答案,它们都适用于操作栏而不是工具栏,并且它们需要创建新形状。

有没有一种简单的方法可以使用 来做到这一点styles.xml

android android-layout android-toolbar android-shapedrawable material-components-android

2
推荐指数
1
解决办法
5597
查看次数