2

下面的google api調用不會產生任何回調。只有'FragmentActivity:活動結果爲未知片段傳遞'的警告。FragmentActivity:針對未知片段發送的活動結果

 mClient = new GoogleApiClient.Builder(this) 
        .addApi(Fitness.SENSORS_API) 
        .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) 
        .addConnectionCallbacks(
          new GoogleApiClient.ConnectionCallbacks() { 
           @Override 
           public void onConnected(Bundle bundle) { 
            Log.i(TAG, "Connected!!!"); 
            // Now you can make calls to the Fitness APIs. 
            findFitnessDataSources(); 
           } 

           @Override 
           public void onConnectionSuspended(int i) { 
            // If your connection to the sensor gets lost at some point, 
            // you'll be able to determine the reason and react to it here. 
            if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) { 
             Log.i(TAG, "Connection lost. Cause: Network Lost."); 
            } else if (i 
              == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) { 
             Log.i(TAG, 
               "Connection lost. Reason: Service Disconnected"); 
            } 
           } 
          } 
        ) 
        .enableAutoManage(this, 0, new GoogleApiClient.OnConnectionFailedListener() { 
         @Override 
         public void onConnectionFailed(ConnectionResult result) { 
          Log.i(TAG, "Google Play services connection failed. Cause: " + 
            result.toString()); 
          } 
       }) 
       .build(); 
     mClient.connect(); 
+0

您是否在findFitnessDataSources()中註冊了您的mClient? – uguboz

+0

這就是另一種情況,「連接!!」標籤沒有出現含義findFitnessDataSources()將不會執行 –

+0

.enableAutoManage需要extend,ng FragmentActivity在此活動/片段中擴展了什麼? – uguboz

回答

0

如果使用高於此值的任何值,請嘗試將支持庫降級到23.1.0。

0

在經歷了很多困難之後得到了解決這個問題的方法。新API已發佈,並且已解決此問題。所以只要更新您的build.gradle文件:

編譯「com.google.android.gms:播放服務的健身:10.0.0」

1

我不知道這是否是OP的問題,但如果其他人遇到上述警告,請檢查您在之內製作的任何startActivityForResult調用片段。就我而言,我將這些調用從活動轉移到了一個片段,並保持原樣。然而,從片段中作出時,則需要先調用getActivity(),如:

getActivity().startActivityForResult(intent, RESPONSE_CODE); 

如果不出錯的「未知片段傳遞活動結果」這樣做的結果,並沒有任何反應傳遞到要處理的活動。

相關問題