私はこれで1週間以上立ち往生しており、私が間違っていることを正確に理解できないようです。私は私のために働くように見えるいずれも、次の質問に、読んだことがある:私は何をしようとしているGoogle APIクライアントに接続できません。
Fatal Exception: java.lang.IllegalStateException GoogleApiClient is not connected yet
google api client callback is never called
Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet
が使用されLocationServices APIをGeofenceクラスと組み合わせて使用して、ユーザーが指定された領域にいるかどうかを確認します。この問題は、Google APIクライアントおよび/またはLocationservices APIとの通信にあるように見えます。
私は私のマニフェストに次のように宣言した:
<service android:name=".GeofenceTransitionsIntentService" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="value of my key" />
</application>
私はGoogleApiClientと対話する私のプロジェクトで宣言された2つのJavaメソッドがあります:
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
public void startApiClient(){
if (mGoogleApiClient.isConnected()) {
Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show();
return;
//Of course the Toast is supposed to fire of when the user cannot
//connect to the google api. However when I make this code to run
//when the user cannot connect to google play services it just shows
//the toast and does not report me the error which is why I in this
//case made this code to run when the user is connected to google play services
}
try {
LocationServices.GeofencingApi.addGeofences
(mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent()).setResultCallback(this); // Result processed in onResult(). This is also the line where the app seems to crash because it is unable to connect to the google api client
} catch (SecurityException securityException) {
securityException.notify();
}
}
を私はその後、buildGoogleApiClient(コール)で私のonStart()メソッドでonCreate()メソッドとstartApiClient()を呼び出します。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer);
…
buildGoogleApiClient();
}
_
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
startApiClient();
}
とケースneccessaryで、はonResult()メソッド:
public void onResult(Status status) {
if (status.isSuccess()) {
// Update state and save in shared preferences.
mGeofencesAdded = !mGeofencesAdded;
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.GEOFENCES_ADDED_KEY, mGeofencesAdded);
editor.apply();
}
は、このことについて奇妙なことは、接続が実際にいくつかの時間のためにインスタンスを取得んということです。ユーザーが接続されていないときにトーストを表示するようにプログラムに指示すると、Androidモニターは接続が確立されたが、トーストは引き続きトリガーされると通知します。しかし、ユーザーがGoogle APIクライアントに接続しているときにトーストを表示するようにプログラムに指示すると、アプリがクラッシュし、Google APIクライアントがまだ接続されていないことがわかります。
お手数ではございますが、お手数をおかけしますようお願い申し上げます。私が非常に明白な何かを監督しているなら、私を許してください。