diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-01-24 19:55:58 +0100 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-01-24 19:55:58 +0100 |
commit | a6dd8e45fa2c1c3b0a3473361ddd9f21d604fab8 (patch) | |
tree | d7a2e0d5438c14ae8e451fa60d91267caa429351 /src/playstore | |
parent | 04595db099f2c1107fc58420a1e8fa5ef207195d (diff) |
use installreferrer libray instead of broadcast listener
Diffstat (limited to 'src/playstore')
-rw-r--r-- | src/playstore/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java | 62 |
2 files changed, 62 insertions, 9 deletions
diff --git a/src/playstore/AndroidManifest.xml b/src/playstore/AndroidManifest.xml index 767fb4581..a54f8bee1 100644 --- a/src/playstore/AndroidManifest.xml +++ b/src/playstore/AndroidManifest.xml @@ -28,14 +28,5 @@ <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> - - <receiver - android:name=".services.InstallReferrerService" - android:enabled="true" - android:exported="true"> - <intent-filter> - <action android:name="com.android.vending.INSTALL_REFERRER" /> - </intent-filter> - </receiver> </application> </manifest> diff --git a/src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java b/src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java new file mode 100644 index 000000000..05824b9b2 --- /dev/null +++ b/src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java @@ -0,0 +1,62 @@ +package de.pixart.messenger.utils; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.os.RemoteException; +import android.preference.PreferenceManager; +import android.util.Log; + +import com.android.installreferrer.api.InstallReferrerClient; +import com.android.installreferrer.api.InstallReferrerStateListener; +import com.android.installreferrer.api.ReferrerDetails; + +import de.pixart.messenger.Config; +import de.pixart.messenger.ui.WelcomeActivity; + +public class InstallReferrerUtils implements InstallReferrerStateListener { + + private static final String PROCESSED_INSTALL_REFERRER = "processed_install_referrer"; + + + private final WelcomeActivity welcomeActivity; + private final InstallReferrerClient installReferrerClient; + + + public InstallReferrerUtils(WelcomeActivity welcomeActivity) { + this.welcomeActivity = welcomeActivity; + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(welcomeActivity); + if (preferences.getBoolean(PROCESSED_INSTALL_REFERRER, false)) { + Log.d(Config.LOGTAG, "install referrer already processed"); + this.installReferrerClient = null; + return; + } + this.installReferrerClient = InstallReferrerClient.newBuilder(welcomeActivity).build(); + this.installReferrerClient.startConnection(this); + } + + public static void markInstallReferrerExecuted(final Activity context) { + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + preferences.edit().putBoolean(PROCESSED_INSTALL_REFERRER, true).apply(); + } + + @Override + public void onInstallReferrerSetupFinished(int responseCode) { + switch (responseCode) { + case InstallReferrerClient.InstallReferrerResponse.OK: + try { + final ReferrerDetails referrerDetails = installReferrerClient.getInstallReferrer(); + final String referrer = referrerDetails.getInstallReferrer(); + welcomeActivity.onInstallReferrerDiscovered(referrer); + } catch (RemoteException e) { + Log.d(Config.LOGTAG, "unable to get install referrer", e); + } + break; + default: + Log.d(Config.LOGTAG, "unable to setup install referrer client. code=" + responseCode); + } + } + + @Override + public void onInstallReferrerServiceDisconnected() { + } +}
\ No newline at end of file |