summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-22 15:33:59 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-22 15:33:59 +0100
commit76b036db2e9f632fb8315f7ff925434912671940 (patch)
treecff1d50aa8a32f9f57c0618b81ca9c0c510faee8
parent09ee4433efc9a62211bca3aff60415ba6d187ab0 (diff)
downloadRustAndDust-76b036db2e9f632fb8315f7ff925434912671940.zip
RustAndDust-76b036db2e9f632fb8315f7ff925434912671940.tar.gz
AndroidBackend: fetch owner's google account
-rw-r--r--android/AndroidManifest.xml1
-rw-r--r--android/src/ch/asynk/rustanddust/android/AndroidBackend.java14
2 files changed, 14 insertions, 1 deletions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index 052ffcf..c3bf902 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -5,6 +5,7 @@
android:versionName="1.0.1" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="20" />
+ <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<application
android:allowBackup="true"
diff --git a/android/src/ch/asynk/rustanddust/android/AndroidBackend.java b/android/src/ch/asynk/rustanddust/android/AndroidBackend.java
index f61a1b5..f042894 100644
--- a/android/src/ch/asynk/rustanddust/android/AndroidBackend.java
+++ b/android/src/ch/asynk/rustanddust/android/AndroidBackend.java
@@ -1,6 +1,10 @@
package ch.asynk.rustanddust.android;
import android.app.Application;
+import android.content.Context;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.util.Backend;
@@ -19,9 +23,17 @@ public class AndroidBackend implements Backend
public int getMyId() { return me; }
public int getOpponentId() { return opponent; }
+ @Override
public void init(RustAndDust game)
{
- me = game.db.storePlayerGetId("me", "myself");
+ AccountManager aMgr = (AccountManager) app.getSystemService(Context.ACCOUNT_SERVICE);
+ Account[] accounts = aMgr.getAccountsByType("com.google");
+ for (Account account : accounts)
+ RustAndDust.debug("account : " + account.toString());
+ if (accounts.length > 0)
+ me = game.db.storePlayerGetId(accounts[0].name.toString(), "myself");
+ else
+ me = game.db.storePlayerGetId("me", "myself");
opponent = game.db.storePlayerGetId("opponent", "other");
}
}