- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在我的 Android 应用中实现应用内结算。一切正常,但是,我正在尝试将广播接收器从 Activity 中解耦到 list 中。特别是在 Android 的 trivialdrive 示例中有这个建议:
// Important: Dynamically register for broadcast messages about updated purchases.
// We register the receiver here instead of as a <receiver> in the Manifest
// because we always call getPurchases() at startup, so therefore we can ignore
// any broadcasts sent while the app isn't running.
// Note: registering this listener in an Activity is a bad idea, but is done here
// because this is a SAMPLE. Regardless, the receiver must be registered after
// IabHelper is setup, but before first call to getPurchases().
目前有一个扩展 BroadcastReceiver
的类:
public class IabBroadcastReceiver extends BroadcastReceiver {
/**
* The Intent action that this Receiver should filter for.
*/
public static final String ACTION = "com.android.vending.billing.PURCHASES_UPDATED";
private final IabBroadcastListener mListener;
public IabBroadcastReceiver(IabBroadcastListener listener) {
mListener = listener;
}
@Override
public void onReceive(Context context, Intent intent) {
if (mListener != null) {
mListener.receivedBroadcast();
}
}
/**
* Listener interface for received broadcast messages.
*/
public interface IabBroadcastListener {
void receivedBroadcast();
}
}
还有一个实现IabBroadcastReceiver.IabBroadcastListener
的类:
public class Subscription extends AppCompatActivity implements
IabBroadcastReceiver.IabBroadcastListener {
IabHelper mHelper;
// Provides purchase notification while this app is running
IabBroadcastReceiver mBroadcastReceiver;
...
// Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d("IAB", "Query inventory finished.");
if (mHelper == null) return;
if (result.isFailure()) {
Log.d("IAB", "Failed to query inventory: " + result);
return;
}
if (inventory.getSkuDetails(SKU_MONTHLY_TTS) != null
&& inventory.getSkuDetails(SKU_YEARLY_TTS) != null) {
...
}
Log.d("IAB", "Query inventory was successful.");
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
...
Log.d("IAB", "Initial inventory query finished; enabling main UI.");
}
};
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d("IAB", "Purchase finished: " + result + ", purchase: " + purchase);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
Log.d("IAB", "Error purchasing: " + result);
return;
}
if (!verifyDeveloperPayload(purchase)) {
Log.d("IAB", "Error purchasing. Authenticity verification failed.");
return;
}
Log.d("IAB", "Purchase successful.");
...
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subscription);
mHelper = new IabHelper(this, compiledKy);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
Log.d("Subscription", "InSetUpFinished: " + result);
if (!result.isSuccess()) {
Log.d("Subscription", "Problem setting up In-app Billing: " + result);
return;
}
if (mHelper == null) return;
// Important: Dynamically register for broadcast messages about updated purchases.
// We register the receiver here instead of as a <receiver> in the Manifest
// because we always call getPurchases() at startup, so therefore we can ignore
// any broadcasts sent while the app isn't running.
// Note: registering this listener in an Activity is a bad idea, but is done here
// because this is a SAMPLE. Regardless, the receiver must be registered after
// IabHelper is setup, but before first call to getPurchases().
mBroadcastReceiver = new IabBroadcastReceiver(Subscription.this);
IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);
registerReceiver(mBroadcastReceiver, broadcastFilter);
// IAB is fully set up. Now, let's get an inventory of stuff we own.
Log.d("IAB", "Setup successful. Querying inventory.");
try {
List<String> additionalSkuList = new ArrayList<String>();
...
mHelper.queryInventoryAsync(true, null, additionalSkuList, mGotInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
Log.d("IAB", "Error querying inventory. Another async operation in progress.");
}
}
});
Button monthlySubButton = (Button) findViewById(R.id.monthlySubButton);
monthlySubButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!mHelper.subscriptionsSupported()) {
Log.d("IAB","Subscriptions not supported on your device yet. Sorry!");
return;
}
try {
...
mHelper.launchPurchaseFlow(Subscription.this, ..., IabHelper.ITEM_TYPE_SUBS,
oldSku, 10001, mPurchaseFinishedListener, "");
} catch (IabHelper.IabAsyncInProgressException e) {
Log.d("IAB", e.getMessage());
}
}
});
...
}
/** Verifies the developer payload of a purchase. */
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
...
return true;
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mBroadcastReceiver != null) {
unregisterReceiver(mBroadcastReceiver);
}
Log.d("IAB", "Destroying helper.");
if (mHelper != null) {
mHelper.disposeWhenFinished();
mHelper = null;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("IAB", "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mHelper == null) return;
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
else {
Log.d("IAB", "onActivityResult handled by IABUtil.");
}
}
@Override
public void receivedBroadcast() {
// Received a broadcast notification that the inventory of items has changed
Log.d("IAB", "Received broadcast notification. Querying inventory.");
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
Log.d("IAB", "Error querying inventory. Another async operation in progress.");
}
}
}
我试图在 list 中添加一个接收器,但它给了我一个错误:
</application>
...
<activity
android:name=".controller.Subscription"
android:label="Subscription"
android:parentActivityName=".controller.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".controller.MainActivity" />
</activity>
<receiver android:name=".controller.Subscription" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.INPUT_METHOD_CHANGED" />
</intent-filter>
</receiver>
</application>
错误消息:.controller.Subscription 不可分配给“android.content.BroadcastReceiver”
Subscription
类位于正确的目录中(在 Controller 包下)。我的 Subscription
类是否必须扩展 IabBroadcastReceiver 类而不是实现 IabBroadcastReceiver.IabBroadcastListener
?我仍然想扩展 AppCompactActivity
,想知道是否有任何方法可以解决这个问题。似乎没有在线示例显示如何使用 list 中注册的广播接收器实现 inApp billing api。提前感谢您的帮助!
最佳答案
controller.Subscription is not assignable to 'android.content.BroadcastReceiver'
这意味着 Subscription
不是 BroadcastReceiver
的后代.您已注册Subscription
显示为 receiver
, 但实际上它不是 BroadcastReceiver
的子类.
Does my
Subscription
class have to extendIabBroadcastReceiver
class and not be implementingIabBroadcastReceiver.IabBroadcastListener
instead?
为了将一个类注册为 receiver
在 list 中,它应该是 BroadcastReceiver
的后代(直接或间接) .因此,Subscription
应该 extends BroadcastReceiver
或 extends IabBroadcastReceiver
.
I'll still like to extend AppCompactActivity.
你不能让一个类既是 Activity 又是接收者(Java 不支持多重继承)。
还可以注册IabBroadcastReceiver
通过 list 显示为 <receiver>
.但我想知道这背后的原因是什么?显然,当您的应用处于非 Activity 状态时,您永远不会收到任何广播,因为您应该在您的应用内启动购买流程,这就是为什么注册和注销 BroadcastReceiver
更有意义的原因。动态地。请注意,通过 list 注册接收器会让您收到来自其他应用程序的购买广播,您很可能对此不感兴趣。
参见 docs :
Don't register this broadcast receiver in the app manifest. Declaring the receiver in the manifest can cause the system to launch the app to handle the intent if the user makes a purchase while the app isn't running. This behavior is not necessary and may be annoying to the user. To find out about any purchases the user made while the app wasn't running, call getPurchases() when the user launches the app.
关于android - InAppBilling 在 AndroidManifest 中注册 BroadcastReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45686172/
我有一个问题,想知道如何在已经使用常规登录/注册系统的网站上集成第 3 方登录(也进行静默注册)。 基本上当前登录还是比较规律的: 当用户进入网站 session 时类(class)决定他是否需要重新
我在学习 Hyperledger Fabric 并运行示例代码。 我仍在尝试正确了解事情的运作方式,尤其是在使用证书和加密 Material 的用户/管理员注册和注册中。 我想知道以下如何工作。 1)
我正在尝试使用从我的 Android 设备的 PassWallet 应用程序中保存的票证中获取的 token 向我的设备发送消息。 设备发送使用苹果钱包规范更新通行证所需的所有信息。但是,我正在使用
使用 Passport 本地示例,我可以登录工作。没有关于如何注册用户的文档。 我想为用户提供一个“电子邮件”和“密码”字段,他们可以使用它们来注册该网站。我怎样才能做到这一点?有什么原因没有记录下来
在之前的一些 WSO2IS 版本中,有一个默认的 self 注册功能。但是,我在 5.0 版本中找不到它。 阅读 WSO2IS 5.0 文档,我发现有 2 个用于此功能的 API: getUserId
我已将 Airship SDK 集成到 Android 应用程序中。在应用程序启动和飞艇起飞后,我在日志中得到以下调试信息: 07-27 12:46:31.916 XXX - UALib( 1545)
Delphi 中设计时包的可怕错误之一是以下错误,这意味着注册安装新组件到您的 Palette 上的包: Component TSomething can't be registered by pac
我发现的大部分内容都使用 php 或类似的东西。 我有一个 Angular 前端和 Node/express 服务器代码。还没有后端。我不确定如何继续用户注册。 最佳答案 在没有后端的情况下进行注册等
我正在使用 Drupal 6 开发一个网站。我正在使用我自己的主题,并且一切正常。现在我需要使用我的自定义主题在我的网站上创建一个自定义登录/注册表单。我尝试了很多方法,但一切都重定向到我的管理主题,
我在运行此代码时收到 Sip 异常。这是因为 manager.register(me,20,listener)。 下面是我的代码,所以请帮我更正这段代码。我正在使用 SipDemo 代码注册我的帐户。
在过去的几天里,我一直在尝试为基于 VUE 的 excel 制作任务 Pane 插件。 我已按照 link 的指南进行操作我试图为 onSelectionChange 注册一个事件处理程序。它已经有些
我需要在使用 django-registration 应用程序的登录表单中实现一个“记住我”按钮。任何ane可以帮助我向我展示这样做的方法吗? 谢谢 最佳答案 一种方法是更改 session 到期
我发现,如果您使用 Django 1.5 版本,则 django 注册模块会中断,因为在最新的 django 开发版本中,simple.py 类已被删除。 最佳答案 此问题现已修复: hg clone
我正在尝试将 facebook connect 实现到我的网站,但有几个问题。 1:是否可以使用用户当前的 Facebook 电子邮件/密码在我的网站上注册用户。 假设用户点击链接通过 faceboo
我使用 Facebook 注册来允许人们在我的网站上注册。有没有可能,在注册后,他在我的网站注册的成员(member)墙上会张贴? 最佳答案 这可能不是您正在寻找的答案,但我强烈建议您不要这样做。用户
I would like to use a slash (/) for a search during a vimscript, but I don't want to overwrite the "
我正在使用 jqgrid 并且有显示日期的列,但是来自服务器的日期以 json 格式出现,如下所示, "CommentedDate": "\/Date(1304324941000+0530)\/" 如
我希望用户可以直接登录主页,而不是在“../account/login/”页面上登录。我应该做什么才能使它成为可能?如何将主页上的输入字段与 allauth 连接?我不知道这样是否太复杂而无法以这种方
This question already has answers here: Understanding NSString comparison (7个答案) 5年前关闭。 我正在尝试制作注册表。有
我正在使用 Django 注册。它提供了处理 registration_form.html 的 View ,该 html 当前包含用户名、密码 1、密码 2 和电子邮件作为我的应用程序中的用户可输入字
我是一名优秀的程序员,十分优秀!