質問編集履歴

3

修正

2018/06/07 09:02

投稿

sena14
sena14

スコア109

test CHANGED
File without changes
test CHANGED
@@ -1,12 +1,8 @@
1
- [参考サイト](https://qiita.com/yamacraft/items/90bfb804538abd404b3e#googleapiclient%E3%81%AE%E6%8E%A5%E7%B6%9A%E8%A8%AD%E5%AE%9A)を見ているのですがリーダーボードを開く際にいくつかわからないことがあり困っています。
1
+ [参考サイト](https://qiita.com/yamacraft/items/90bfb804538abd404b3e#googleapiclient%E3%81%AE%E6%8E%A5%E7%B6%9A%E8%A8%AD%E5%AE%9A)を見ているのですがリーダーボードを開く際にわからないことがあり困っています。
2
-
3
- startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,getResources().getString(R.string.ranking_id))、1);
2
+
4
-
5
- という風に呼び出しているのですがREQUEST_CODEの部分はいま適当に1を入れているのですが何を渡す引数なのでしょうか?
3
+
6
-
7
-
8
-
4
+
9
- また上記のコードが呼ばれたところで
5
+ 記のコードが呼ばれたところで
10
6
 
11
7
  >
12
8
 
@@ -56,6 +52,10 @@
56
52
 
57
53
  といったエラーが出てしまいます。
58
54
 
55
+ mGoogleApiClient.isConnected()が常にfalseになってしまっているようです。
56
+
57
+ 原因が分からず困っています。
58
+
59
59
  よろしくお願いします
60
60
 
61
61
 

2

2018/06/07 09:02

投稿

sena14
sena14

スコア109

test CHANGED
File without changes
test CHANGED
File without changes

1

修正

2018/05/16 10:33

投稿

sena14
sena14

スコア109

test CHANGED
File without changes
test CHANGED
@@ -1,11 +1,279 @@
1
- [参考サイト](https://qiita.com/yamacraft/items/90bfb804538abd404b3e#googleapiclient%E3%81%AE%E6%8E%A5%E7%B6%9A%E8%A8%AD%E5%AE%9A)を見ているのですがstartActivityForResult()の引数がよくわかりません
1
+ [参考サイト](https://qiita.com/yamacraft/items/90bfb804538abd404b3e#googleapiclient%E3%81%AE%E6%8E%A5%E7%B6%9A%E8%A8%AD%E5%AE%9A)を見ているのですがリーダーボードを開際にいくつかわからないことがあ困っていす。
2
-
2
+
3
- startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,getResources().getString(R.string.ranking_id), /*REQUEST_CODE*/));
3
+ startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,getResources().getString(R.string.ranking_id))、1);
4
-
4
+
5
- REQUEST_CODE何を入れればよのか(適当な数字を入れてみたけどエラーになってしまった)そ引数はこれよいの
5
+ という風に呼び出しているのですがREQUEST_CODEの部分はい適当に1を入れているですが何を渡す引数なのしょう
6
+
7
+
8
+
6
-
9
+ また上記のコードが呼ばれたところで
10
+
11
+ >
12
+
13
+ Caused by: java.lang.IllegalStateException: GoogleApiClient must be connected.
14
+
15
+ at com.google.android.gms.common.internal.zzab.zza(Unknown Source)
16
+
17
+ at com.google.android.gms.games.Games.zzb(Unknown Source)
18
+
19
+ at com.google.android.gms.games.Games.zzi(Unknown Source)
20
+
21
+ at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
22
+
23
+ at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
24
+
25
+ at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
26
+
27
+ at package.MainActivity.worldRanking(MainActivity.java:186)
28
+
7
- R.string.ranking_idに関しては正しいリーダーボードのIDをいれています。
29
+ at java.lang.reflect.Method.invoke(Native Method
30
+
8
-
31
+ at java.lang.reflect.Method.invoke(Method.java:372) 
32
+
9
-
33
+ at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
34
+
35
+ at android.view.View.performClick(View.java:5197) 
36
+
37
+ at android.view.View$PerformClick.run(View.java:20926) 
38
+
39
+ at android.os.Handler.handleCallback(Handler.java:739) 
40
+
41
+ at android.os.Handler.dispatchMessage(Handler.java:95) 
42
+
43
+ at android.os.Looper.loop(Looper.java:145) 
44
+
45
+ at android.app.ActivityThread.main(ActivityThread.java:5951) 
46
+
47
+ at java.lang.reflect.Method.invoke(Native Method) 
48
+
49
+ at java.lang.reflect.Method.invoke(Method.java:372) 
50
+
51
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
52
+
53
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
54
+
55
+
56
+
57
+ といったエラーが出てしまいます。
10
58
 
11
59
  よろしくお願いします
60
+
61
+
62
+
63
+ ```ここに言語を入力
64
+
65
+ import android.content.Intent;
66
+
67
+ import android.content.IntentSender;
68
+
69
+ import android.os.Handler;
70
+
71
+ import android.support.v7.app.AppCompatActivity;
72
+
73
+ import android.os.Bundle;
74
+
75
+ import android.view.View;
76
+
77
+ import android.widget.Button;
78
+
79
+ import android.widget.ImageView;
80
+
81
+ import android.widget.LinearLayout;
82
+
83
+ import android.widget.TextView;
84
+
85
+ import android.widget.Toast;
86
+
87
+
88
+
89
+ import com.google.android.gms.common.ConnectionResult;
90
+
91
+ import com.google.android.gms.common.api.GoogleApiClient;
92
+
93
+ import com.google.android.gms.games.Games;
94
+
95
+ import com.google.android.gms.games.Player;
96
+
97
+
98
+
99
+ public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener{
100
+
101
+
102
+
103
+
104
+
105
+ private GoogleApiClient mGoogleApiClient;
106
+
107
+ private boolean mIntentInProgress;
108
+
109
+
110
+
111
+
112
+
113
+ @Override
114
+
115
+ protected void onCreate(Bundle savedInstanceState) {
116
+
117
+ super.onCreate(savedInstanceState);
118
+
119
+ setContentView(R.layout.activity_main);
120
+
121
+
122
+
123
+ init();
124
+
125
+
126
+
127
+ }
128
+
129
+
130
+
131
+
132
+
133
+ //初期設定
134
+
135
+ public void init() {
136
+
137
+ // 各種リスナー登録とGoogleAPIで利用するAPIやスコープの設定
138
+
139
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
140
+
141
+ .addConnectionCallbacks(this)
142
+
143
+ .addOnConnectionFailedListener(this)
144
+
145
+ .addApi(Games.API).addScope(Games.SCOPE_GAMES)
146
+
147
+ .build();
148
+
149
+ }
150
+
151
+
152
+
153
+ @Override
154
+
155
+ protected void onStart() {
156
+
157
+ super.onStart();
158
+
159
+ // 今回は画面が表示されるたびに必ず接続させる
160
+
161
+ mGoogleApiClient.connect();
162
+
163
+ }
164
+
165
+
166
+
167
+ @Override
168
+
169
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
170
+
171
+ super.onActivityResult(requestCode, resultCode, data);
172
+
173
+ if (requestCode == 100) {
174
+
175
+ mIntentInProgress = false;
176
+
177
+ if (resultCode != RESULT_OK) {
178
+
179
+ // エラーの場合、resultCodeにGamesActivityResultCodes内の値が入っている
180
+
181
+ return;
182
+
183
+ }
184
+
185
+ if (!mGoogleApiClient.isConnected()) {
186
+
187
+ mGoogleApiClient.reconnect();
188
+
189
+ }
190
+
191
+ }
192
+
193
+ }
194
+
195
+
196
+
197
+ @Override
198
+
199
+ public void onConnected(Bundle bundle) {
200
+
201
+ // プレイヤー情報取得
202
+
203
+ Player p = Games.Players.getCurrentPlayer(mGoogleApiClient);
204
+
205
+
206
+
207
+ // 試しにプレイヤー名を表示
208
+
209
+ String displayName = "???";
210
+
211
+ if (p != null) {
212
+
213
+ displayName = p.getDisplayName();
214
+
215
+ }
216
+
217
+ Toast.makeText(this, String.format("%s でログインしています。", displayName), Toast.LENGTH_SHORT).show();
218
+
219
+ }
220
+
221
+
222
+
223
+ @Override
224
+
225
+ public void onConnectionSuspended(int i) {
226
+
227
+ mGoogleApiClient.connect();
228
+
229
+ }
230
+
231
+
232
+
233
+ @Override
234
+
235
+ public void onConnectionFailed(ConnectionResult connectionResult) {
236
+
237
+ int errorCode = connectionResult.getErrorCode();
238
+
239
+
240
+
241
+ // サインインしていない場合、サインイン処理を実行する
242
+
243
+ if (errorCode == ConnectionResult.SIGN_IN_REQUIRED
244
+
245
+ && !mIntentInProgress && connectionResult.hasResolution()) {
246
+
247
+ try {
248
+
249
+ mIntentInProgress = true;
250
+
251
+ connectionResult.startResolutionForResult(this, 100);
252
+
253
+ } catch (IntentSender.SendIntentException e) {
254
+
255
+ mIntentInProgress = false;
256
+
257
+ mGoogleApiClient.connect();
258
+
259
+ }
260
+
261
+ }
262
+
263
+ }
264
+
265
+
266
+
267
+ //全国ランキング表示
268
+
269
+ public void worldRanking(View view){
270
+
271
+ startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,getResources().getString(R.string.ranking_id)),1);
272
+
273
+ }
274
+
275
+
276
+
277
+ }
278
+
279
+ ```