Skip to content

Commit

Permalink
处理用户关闭了广告标识符的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed May 14, 2021
1 parent 9389a63 commit bb2f4bf
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
## 4.1.0 - 2021/05/14

- 支持中兴及 Motorola、HTC、LG、Sony 等海外平台手机获取 AAID(安卓广告标识符)。
- 华为 OAID 获取优化,支持智能电视
- 华为 OAID 获取优化,支持大屏电视
- 修复努比亚支持情况识别。
- 处理用户关闭了广告标识符的情况。
- 通过云真机在线调试,更新更多真机实测效果图。

## 4.0.1 - 2021/05/13
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ dependencies {

### 不支持 OAID 或 AAID

- 用户关闭广告标识符 ![](/screenshot/oaid_disabled.png)

```text
锤子(Smartisan)、酷派(Yulong,Coolpad)、360(360)、奇酷(QiKu)、海信(Hisense)、金立(Gionee)、
美图(Meitu)、糖果(SOAP)、格力(Gree)、朵唯(Doov)、优思(Uniscope)、夏普(SHARP)、乐视(LeTV)、
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!--
<!--
~ Copyright (c) 2019-2021 gzu-liyujiang <[email protected]>
~
~ The software is licensed under the Mulan PSL v2.
Expand All @@ -12,7 +12,7 @@
~
-->

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -62,6 +62,4 @@

</LinearLayout>

</ScrollView>


</androidx.core.widget.NestedScrollView>
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void onServiceConnected(ComponentName name, IBinder service) {
OAIDLog.print("Google Play Service connected");
try {
IAdvertisingIdService anInterface = IAdvertisingIdService.Stub.asInterface(service);
if (anInterface.isLimitAdTrackingEnabled(true)) {
// 实测在系统设置中停用了广告化功能也是能获取到广告标识符的
OAIDLog.print("User has disabled advertising identifier");
}
String id = anInterface.getId();
if (id == null || id.length() == 0) {
throw new RuntimeException("Android Advertising ID get failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public void onServiceConnected(ComponentName name, IBinder service) {
OAIDLog.print("Huawei OPENIDS_SERVICE connected");
try {
OpenDeviceIdentifierService anInterface = OpenDeviceIdentifierService.Stub.asInterface(service);
if (anInterface.isOaidTrackLimited()) {
// 实测在系统设置中关闭了广告标识符,将获取到固定的一大堆0
getter.onOAIDGetError(new RuntimeException("User has disabled advertising identifier"));
return;
}
String oaid = anInterface.getOaid();
if (oaid == null || oaid.length() == 0) {
throw new RuntimeException("Huawei Advertising ID get failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public void onServiceConnected(ComponentName name, IBinder service) {
if (anInterface == null) {
throw new RuntimeException("IDeviceidInterface is null");
}
if (!anInterface.isSupport()) {
throw new RuntimeException("IDeviceidInterface#isSupport return false");
}
String oaid = anInterface.getOAID();
if (oaid == null || oaid.length() == 0) {
throw new RuntimeException("Lenovo OAID get failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public void onServiceConnected(ComponentName name, IBinder service) {
if (anInterface == null) {
throw new RuntimeException("MsaIdInterface is null");
}
if (!anInterface.isSupported()) {
throw new RuntimeException("MsaIdInterface#isSupported return false");
}
String oaid = anInterface.getOAID();
if (oaid == null || oaid.length() == 0) {
throw new RuntimeException("Msa oaid get failed");
Expand Down
Binary file added screenshot/oaid_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bb2f4bf

Please sign in to comment.