在我的应用中,我在这里得到RESulT_CANCELED:
@OverrIDeprotected voID onActivityResult(int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode,resultCode,data); if( requestCode == REQUEST_OAUTH ) { authInProgress = false; if( resultCode == RESulT_OK ) { if( !mClIEnt.isConnecting() && !mClIEnt.isConnected() ) { mClIEnt.connect(); } } else if( resultCode == RESulT_CANCELED ) {/// HERE Toast.makeText(MainActivity.this,"RESulT_CANCELED",Toast.LENGTH_SHORT).show(); Log.e("GoogleFit","RESulT_CANCELED"); Log.e("GoogleFit",data.getExtras().toString()); } }else if(requestCode == CALL_END){ if (resultCode == Activity.RESulT_OK){ //pass }else{ } } else { Log.e("GoogleFit","requestCode NOT request_oauth"); }}
试着找出过去两天的问题.我在androID studio中添加了正确的播放服务库:compile’com.Google.androID.gms:play-services-fitness:8.4.0′
建立客户:
private voID buildfitnessClIEnt() { if (mClIEnt == null && checkPermissions()) { Log.i(TAG,"Building fitness ClIEnt"); mClIEnt = new Googleapiclient.Builder(this) .addAPI(fitness.SENSORS_API) .addScope(new Scope(Scopes.fitness_ACTIVITY_READ_WRITE)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mClIEnt.connect(); }}
回调:
/** * Google FIT METHODS */@OverrIDepublic voID onConnected(@Nullable Bundle bundle) { DataSourcesRequest dataSourceRequest = new DataSourcesRequest.Builder() .setDataTypes( DataType.TYPE_STEP_COUNT_CUMulATIVE ) .setDataSourceTypes( DataSource.TYPE_RAW ) .build(); ResultCallback<DataSourcesResult> dataSourcesResultCallback = new ResultCallback<DataSourcesResult>() { @OverrIDe public voID onResult(DataSourcesResult dataSourcesResult) { for( DataSource dataSource : dataSourcesResult.getDataSources() ) { if( DataType.TYPE_STEP_COUNT_CUMulATIVE.equals( dataSource.getDataType() ) ) { registerfitnessDataListener(dataSource,DataType.TYPE_STEP_COUNT_CUMulATIVE); } } } }; fitness.SensorsAPI.findDataSources(mClIEnt,dataSourceRequest) .setResultCallback(dataSourcesResultCallback);}@OverrIDepublic voID onConnectionSuspended(int i) {}@OverrIDepublic voID onConnectionFailed(@NonNull ConnectionResult connectionResult) { if( !authInProgress ) { try { authInProgress = true; connectionResult.startResolutionForResult( MainActivity.this,REQUEST_OAUTH ); } catch(IntentSender.SendIntentException e ) { } } else { Log.e( "GoogleFit","authInProgress" ); }}@OverrIDepublic voID onDataPoint(DataPoint dataPoint) { for( final FIEld fIEld : dataPoint.getDataType().getFIElds() ) { final Value value = dataPoint.getValue( fIEld ); runOnUiThread(new Runnable() { @OverrIDe public voID run() { Toast.makeText(getApplicationContext(),"FIEld: " + fIEld.getname() + " Value: " + value,Toast.LENGTH_SHORT).show(); HealthRecordFragment.mStepsWalking.setText(value.toString()); } }); }}
在Gradle中:
apply plugin: 'com.androID.application'androID { compileSdkVersion 23 buildToolsversion "23.0.1" defaultConfig { applicationID "com.xxxx.xxxx" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionname "1.0" } signingConfigs { release { storefile file("C:\Users\xxxxx\AndroIDStudioProjects\HBEAT2\app\hbeat_androID") storePassword "password" keyAlias "hbeat_androID" keyPassword "password" } } buildTypes { release { MinifyEnabled false proguardfiles getDefaultProguardfile('proguard-androID.txt'),'proguard-rules.pro' } }}dependencIEs { compile filetree(dir: 'libs',include: ['*.jar']) compile 'com.Google.androID.gms:play-services-fitness:8.4.0' compile 'com.androID.support:appcompat-v7:23.1.1' compile "com.androID.support:design:23.2.1" compile 'com.github.rahatarmanahmed:circularprogressvIEw:2.4.0' compile 'de.timroes.androID:EnhancedListVIEw:0.3.0'}解决方法 我刚才遇到过这个问题.花了几个小时才弄清楚,所以我想指出那些犯同样错误的人.
我的Google Api客户端无法仅在生产环境中连接,在开发环境中一切正常.
这是因为我的应用程序设置为使用“App Signing”.这样,如果您使用生产密钥库的SHA1(或图片中的上载证书的SHA1)创建了Oauth客户端ID,则不会使用它,因为谷歌将删除此证书并更改为“应用程序签名”证书
因此,我们需要做的就是修复问题只需使用这个新的SHA1创建一个新的OAuth客户端ID,如下所示:
这个问题很容易遇到,因为大多数教程都会告诉您找到您的Production SHA1并在API控制台中使用它.但是,除非您使用“应用程序签名”,否则它将不再起作用.
总结以上是内存溢出为你收集整理的android – 使用Google Fit api时谷歌Oauth 2.0 RESULT_CANCELED全部内容,希望文章能够帮你解决android – 使用Google Fit api时谷歌Oauth 2.0 RESULT_CANCELED所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)