ユーザー同意¶
ヒューマンスコアリングユースケースの一部です。
SDK はユーザーがアプリをどのように操作するかを記録するため、デフォルトではユーザーが同意するまで何も 記録しません。アプリが SDK の既製ダイアログか独自の UI で質問し、SDK が回答を保存して適用します。
使いどころ¶
- 常に。ただし、アプリが
DeaSdk.initを呼び出す前にすでに同意を得ている場合を除きます。その場合はrequireConsent = falseを設定してください - 設定画面からユーザーが同意を撤回できるようにするとき
- 再度尋ねるとき。たとえば別のアカウントがサインインしたとき
前提条件¶
- SDK がインストールされ、初期化されている。クイックスタートを参照してください。
使い方¶
組み込みダイアログで尋ねる¶
import ai.dea.sdk.DeaConsentDialog
// In an Activity, on the main thread:
DeaConsentDialog.show(this) { granted ->
// The user's answer, or the answer already on file.
}
- 回答がすでに保存されている場合、ダイアログは表示されず、
onResultがその回答で即座に呼び出されます。 この呼び出しはセッションの前に無条件に置いてください。ユーザーの操作を妨げるのは初回だけです。 - ダイアログは外側をタップしても閉じません。戻るボタンで閉じると
onResultがfalseで呼び出されますが、 何も保存されないため、次回また尋ねられます。 - SDK が初期化されていない場合、
showは何も表示せずonResult(false)を呼び出します。回答が保存されて いない状態で終了中のアクティビティを渡した場合も同様です。 - ダイアログを一切表示せずに保存された回答を読むには
ask = falseを渡します。
ダイアログの文言は渡した ConsentCopy です。英語のデフォルトは、何が記録され、何が決して記録されないかを
述べています。
| フィールド | デフォルト |
|---|---|
title |
Record this session? |
body |
This app measures how a real person moves, so that people can be told apart from bots. |
recorded |
Where you touch, and how hard · How fast your finger travels · How the handset moves in your hand |
notRecorded |
What you type · What's on your screen · Anything you say |
closing |
Nothing is recorded until you agree, and you can stop at any time. |
accept, decline |
I agree · Not now |
これらのリストはアプリについての主張です。アプリに当てはまらない場合(たとえばアプリが
captureKey でキーの押下を報告している場合)は、独自の文言を渡してください。
import ai.dea.sdk.ConsentCopy
import ai.dea.sdk.DeaConsentDialog
DeaConsentDialog.show(
this,
copy = ConsentCopy(
title = "Help us keep bots out",
notRecorded = listOf("What's on your screen", "Anything you say"),
),
) { granted -> }
空のリストを渡すと、ダイアログのそのセクションは省略されます。
独自の UI で尋ねてから回答を記録する¶
import ai.dea.sdk.DeaSdk
val dea = DeaSdk.instance ?: return
if (!dea.consent.isAnswered) {
// Show your prompt, then:
dea.setConsent(true) // the user agreed
// or
dea.setConsent(false) // the user declined
}
setConsentが呼び出されるとすぐに記録が開始または停止します。- 回答は端末に保存されるため、以後の起動でも
isAnsweredはtrueのままで、尋ねるのは一度だけです。 - 拒否も回答であり、同様に保存されます。拒否の後に起動ごとに尋ね直さないでください。
現在の回答を読む¶
val consent = DeaSdk.instance!!.consent
consent.isAnswered // false until the user has answered
consent.isGranted // true only if the user agreed
consent.decision // ConsentDecision.UNKNOWN, GRANTED or DENIED
同意を撤回する¶
記録は即座に停止し、取得済みでまだ処理されていないものは破棄されます。セッションは維持されるため、 ユーザーが再び同意すると同じセッションで記録が続きます。
再度尋ねる¶
forget() は保存された回答を消去するため、isAnswered は再び false になり、アプリは次回尋ねます。
たとえば同じ端末で別のアカウントがサインインしたときに使います。拒否とは異なり、これは回答ではありません。
ユーザーが再び回答するまで何も記録されません。
回答の変更を通知される¶
import ai.dea.base.ConsentDecision
val unsubscribe = DeaSdk.instance!!.consent.onChange { decision: ConsentDecision ->
updateConsentSwitch(decision == ConsentDecision.GRANTED)
}
// Later, when you no longer need updates:
unsubscribe()
共有端末¶
セッションごとに別の人が端末を使う可能性がある場合(キオスク、テスト端末)、回答を保存しないでください。
この起動の間だけ保持される Consent を渡します。
import ai.dea.base.Consent
import ai.dea.sdk.DeaConfig
import ai.dea.sdk.DeaSdk
DeaSdk.init(this, DeaConfig(appId = "YOUR_APP_ID", appKey = "YOUR_APP_KEY", consent = Consent()))
または、デフォルトのストアを維持したまま、各回答をこの起動の間だけ記録します。
組み込みダイアログも remember = false で同じことを行います。さらに、保存された回答は以前に端末を持っていた人の
ものであるため、まずそれを消去し、呼び出しごとに尋ねます。
すでに得ている同意¶
独自の同意記録がすでに「はい」を示している場合は、再度尋ねる代わりにそれを渡します。
import ai.dea.base.Consent
import ai.dea.sdk.DeaConfig
import ai.dea.sdk.DeaSdk
DeaSdk.init(this, DeaConfig(appId = "YOUR_APP_ID", appKey = "YOUR_APP_KEY", consent = Consent.granted()))
回答を SDK ではなく自分の記録に保持するには、ConsentStore を実装して Consent(store = yourStore) を
渡します。Consent を作成したときに回答がストアから読み取られ、remember = true で記録されたすべての回答が
ストアに書き込まれます。
例¶
最初の画面で尋ねる¶
import ai.dea.sdk.DeaSdk
import android.app.AlertDialog
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
val dea = DeaSdk.instance ?: return
if (dea.consent.isAnswered) return
AlertDialog.Builder(this)
.setTitle("Help us keep bots out")
.setMessage(
"We measure how you touch the screen and how the phone moves in your hand, to " +
"tell people apart from bots. We never record what you type or what is on " +
"your screen. You can change this at any time in Settings.",
)
.setCancelable(false)
.setPositiveButton("Allow") { _, _ -> dea.setConsent(true) }
.setNegativeButton("Not now") { _, _ -> dea.setConsent(false) }
.show()
}
}
文言がアプリにとって正しいままであることを確認してください。
設定のスイッチ¶
import ai.dea.sdk.DeaSdk
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
val dea = DeaSdk.instance
val toggle = findViewById<SwitchCompat>(R.id.bot_protection)
toggle.isEnabled = dea != null
toggle.isChecked = dea?.consent?.isGranted ?: false
toggle.setOnCheckedChangeListener { _, checked -> dea?.setConsent(checked) }
}
}
API¶
| メンバー | 戻り値 | 説明 |
|---|---|---|
DeaConsentDialog.show(activity, sdk, copy, remember, ask, onResult) |
Unit |
回答が保存されていなければ組み込みダイアログを表示し、回答を記録して onResult を呼び出します |
DeaSdk.setConsent(granted, remember = true) |
Unit |
回答を記録して即座に適用します。remember = false ではこの起動の間だけ保持します |
DeaSdk.consent |
Consent |
現在の回答 |
Consent.isAnswered |
Boolean |
ユーザーが回答したかどうか |
Consent.isGranted |
Boolean |
ユーザーが同意したかどうか |
Consent.decision |
ConsentDecision |
UNKNOWN、GRANTED、DENIED のいずれか |
Consent.forget() |
Unit |
保存された回答を消去します |
Consent.onChange(listener) |
() -> Unit |
回答が変わったときに listener を呼び出します。購読解除関数を返します |
Consent() |
Consent |
この起動の間だけ保持される回答 |
Consent.granted() |
Consent |
すでに「はい」である回答 |
Consent(store) |
Consent |
独自の ConsentStore に保持される回答 |