- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
google play 服务适用于 Lollipop ,但当涉及到 kitkat 和更低版本时,即使设备上安装了 google-play-services,它也会给出 ConnectionResult 错误=1。
这是我的代码。
顶层 Build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.yembrace.android.app"
minSdkVersion 19
targetSdkVersion 21
maxSdkVersion 22
versionCode 4
versionName "1.0.3"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile "com.google.android.gms:play-services-gcm:8.3.0"
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.android.support:cardview-v7:23.1.0'
//beacons sdk
compile 'com.estimote:sdk:0.8.8@aar'
compile 'com.github.clans:fab:1.6.2'
//Cards
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
}
public class LoginActivity extends Activity implements
View.OnClickListener,
ActivityCompat.OnRequestPermissionsResultCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "TAG";
private static final int RC_SIGN_IN = 1;
private static final int RC_PERM_GET_ACCOUNTS = 2;
private static final String KEY_IS_RESOLVING = "is_resolving";
private static final String KEY_SHOULD_RESOLVE = "should_resolve";
private GoogleApiClient mGoogleApiClient;
private boolean mIsResolving = false;
private boolean mShouldResolve = false;
SharedPreferences sharedPreferences;
private ViewPager mViewPager;
PageIndicator mIndicator;
private String message;
private SignInButton google_signin;
private ProgressBar progressBar;
private ServiceUtils serviceUtils;
private ProfileData profileData;
private BroadcastReceiver mRegistrationBroadcastReceiver;
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
{
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.INVISIBLE);
}
profileData = new ProfileData();
serviceUtils = new ServiceUtils(this);
initGoogle();
sharedPreferences = getSharedPreferences("app_pref", MODE_PRIVATE);
if (savedInstanceState != null) {
mIsResolving = savedInstanceState.getBoolean(KEY_IS_RESOLVING);
mShouldResolve = savedInstanceState.getBoolean(KEY_SHOULD_RESOLVE);
}
}
private void initGoogle() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
.addScope(new Scope(Scopes.EMAIL))
.build();
google_signin = (SignInButton) findViewById(R.id.sign_in_button);
google_signin.setSize(SignInButton.SIZE_WIDE);
google_signin.setColorScheme(SignInButton.COLOR_DARK);
for (int i = 0; i < google_signin.getChildCount(); i++) {
View v = google_signin.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setPadding(0, 0, 20, 0);
}
}
google_signin.setOnClickListener(this);
}
private void updateUI(boolean isSignedIn) {
if (isSignedIn) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
if (currentPerson != null) {
profileData.setEmail(Plus.AccountApi.getAccountName(mGoogleApiClient));
profileData.setPlatform("google");
if (currentPerson.hasName()) profileData.setFullName(currentPerson.getDisplayName());
if (currentPerson.hasImage()) profileData.setProfileImgUrl(currentPerson.getImage().getUrl());
if (currentPerson.hasId()) profileData.setPlatformProfileId(currentPerson.getId());
if (currentPerson.hasCover() && currentPerson.getCover().hasCoverPhoto()) profileData.setProfileCoverUrl(currentPerson.getCover().getCoverPhoto().getUrl());
if (currentPerson.hasBirthday()) profileData.setBirthday(currentPerson.getBirthday());
if (currentPerson.hasGender()) profileData.setGender(String.valueOf(currentPerson.getGender()));
if (currentPerson.hasRelationshipStatus()) profileData.setRelationshipStatus(String.valueOf(currentPerson.getRelationshipStatus()));
if (currentPerson.hasAgeRange()){ profileData.setMaxAge(String.valueOf(currentPerson.getAgeRange().getMax()));profileData.setMinAge(String.valueOf(currentPerson.getAgeRange().getMin()));}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("platform", profileData.getPlatform());
editor.putString("userName", profileData.getFullName());
editor.putString("userEmail", profileData.getEmail());
editor.putString("profileImage", profileData.getProfileImgUrl());
editor.putString("profileCover",profileData.getProfileCoverUrl());
editor.commit();
registerUser();
} else {
Log.d(TAG, "Null Person, check the api-key");
handleError("Connection Error");
}
} else {
Log.d(TAG, "In UpdateUI: User not signedIn");
handleError("Connection Error");
}
}
private void showSignedInUI() {
updateUI(true);
}
@Override
protected void onStop() {
super.onStop();
mGoogleApiClient.disconnect();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_IS_RESOLVING, mIsResolving);
outState.putBoolean(KEY_SHOULD_RESOLVE, mShouldResolve);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
if (resultCode != RESULT_OK) {
mShouldResolve = false;
}
mIsResolving = false;
mGoogleApiClient.connect();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
if (requestCode == RC_PERM_GET_ACCOUNTS) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showSignedInUI();
} else {
Log.d(TAG, "GET_ACCOUNTS Permission Denied.");
}
}
}
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "onConnected:" + bundle);
mShouldResolve = false;
showSignedInUI();
}
@Override
public void onConnectionSuspended(int i) {
Log.w(TAG, "onConnectionSuspended:" + i);
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
Log.d(TAG, "onConnectionFailed:" + connectionResult.getErrorCode());
if (!mIsResolving && mShouldResolve) {
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(this, RC_SIGN_IN);
mIsResolving = true;
Log.d(TAG, "Could not resolve ConnectionResult.");
} catch (IntentSender.SendIntentException e) {
Log.d(TAG, "Could not resolve ConnectionResult.", e);
handleError("Connection Error");
mIsResolving = false;
mGoogleApiClient.connect();
}
} else {
showErrorDialog(connectionResult);
}
} else {
handleError("Connection Error");
}
}
private void showErrorDialog(ConnectionResult connectionResult) {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, RC_SIGN_IN,
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mShouldResolve = false;
}
}).show();
Log.d(TAG, "In ShowError");
} else {
Log.d(TAG, "Google Play Services Error:" + connectionResult);
Log.d(TAG, "In ShowError: " + apiAvailability.getErrorString(resultCode));
handleError("Play Services not supported");
mShouldResolve = false;
}
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
if (!serviceUtils.checkInternet()) {
progressBar.setVisibility(View.INVISIBLE);
handleError("Connection Error");
} else {
mShouldResolve = true;
mGoogleApiClient.connect();
}
break;
}
}
private void registerUser() {
Log.d(TAG, "LoginActivity:RegisterUser:Url: " + Config.user_login_url);
StringRequest request = new StringRequest(Request.Method.POST,
Config.user_login_url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
SharedPreferences.Editor editor = sharedPreferences.edit();
try {
progressBar.setVisibility(View.INVISIBLE);
JSONObject json_response = new JSONObject(response);
Log.d(TAG, response.toString());
message = json_response.getString("message");
if (message.equals("Inserted successfully") || message.equals("ReLogin"))
editor.putString("userID", json_response.getString("UserID"));
editor.commit();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra("page", 0);
if (message.equals("ReLogin"))
intent.putExtra("newUser", 1);
if (message.equals("Inserted successfully"))
intent.putExtra("newUser", 0);
startActivity(intent);
GCMRegister();
} catch (JSONException e) {
e.printStackTrace();
Log.d(TAG, "LoginActivity:RegisterUser:JSONException:: " + e.getMessage());
handleError("Connection Error");
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "LoginActivity:RegisterUser:VolleyError: " + error.getMessage());
handleError("Connection Error");
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
Log.d(TAG, "LoginActivity:RegisterUser:Post:" + profileData.getEmail() + ", " + profileData.getPlatform() + "," + profileData.getFullName() + "," + profileData.getGender() + "," + profileData.getMaxAge()+","+profileData.getEmail()+","+profileData.getBirthday()+","+profileData.getProfileCoverUrl());
params.put("Email", profileData.getEmail());
params.put("LoginPlatform", profileData.getPlatform());
params.put("FullName", profileData.getFullName());
params.put("ProfilePic", profileData.getProfileImgUrl());
params.put("ProfileUrl", profileData.getPlatformProfileId());
params.put("ProfileCoverUrl",profileData.getProfileCoverUrl());
params.put("DOB", profileData.getBirthday());
params.put("Gender",profileData.getGender());
params.put("RelationshipStatus",profileData.getRelationshipStatus());
params.put("MaxAge",profileData.getMaxAge());
params.put("MinAge",profileData.getMinAge());
params.put("UserIsActive", String.valueOf(1));
params.put("UserDevice", "Android" + android.os.Build.VERSION.SDK_INT);
return params;
}
};
AppController.getInstance().addToRequestQueue(request);
}
private void GCMRegister() {
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences.getBoolean(Config.SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
Log.d(TAG, "register");
} else {
Log.d(TAG, "token error");
}
}
};
if (checkPlayServices()) {
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
}
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
handleError("Play Services not supported");
}
return false;
}
return true;
}
@Override
public void onResume() {
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
mViewPager.setAdapter(new ImageSlideAdapter(this, "SignIn"));
mIndicator.setViewPager(mViewPager);
super.onResume();
}
private void handleError(String msg) {
progressBar.setVisibility(View.INVISIBLE);
if(msg.equals("Play Services not supported"))
{
Toast.makeText(this,"Play Services not supported",Toast.LENGTH_LONG).show();
}
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
}
最佳答案
检查您的 kitkat 设备的播放服务应用程序版本。
也许您应该使用旧版本的播放服务库。
在您的顶级 build.gradle 文件中:
classpath 'com.google.gms:google-services:1.3.0-beta1'
compile 'com.google.android.gms:play-services-plus:7.5.0'
compile "com.google.android.gms:play-services-gcm:7.5.0"
关于android - ConnectionResult=SERVICE_MISSING 用于 android Kitkat 真实设备中的 google play 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33968682/
这里的这个问题对 updating Google Sheets charts linked to Google slides 有一个简洁的解决方案. function onOpen() { var
我正在尝试将 Google 表单添加到 Google 类作业中,但似乎不可能。 首先,它在这里 ( https://developers.google.com/classroom/reference/
出于某种原因,无论我做什么以及我如何尝试,这个日期格式化程序都不起作用。工具提示仍然显示错误的格式。你可以试试代码here . 在代码中我必须注释掉 formatter.format(dataTabl
我目前正在使用访问 token 和刷新 token 从 Google Analytics Reporting API (v4) 中提取数据。当我致力于自动从 Google Analytics 中提取数
我已在 Google 云端硬盘中创建了一个文件夹,例如测试一下,放入3个文件 a.jpg, b.jpg, c.jpg 我希望在同一帐户下的 Google 电子表格中访问文件,例如生成图像文件的链接,可
电子表格 A 是欢迎新移民来到我们小镇的团队的主数据源。它里面有大量非常敏感的数据,不能公开,哪怕是一点点。 (我们谈论的是 child 的姓名和出生日期以及他们在哪里上学……保证电子表格 A 的安全
有没有办法在 Google 文档中编写 Google Apps 脚本以从 Google 表格中检索仅限于非空白行的范围并将这些行显示为表格? 我正在寻找一个脚本,用于使用 Google Apps 脚本
有没有办法在 Google 文档中编写 Google Apps 脚本以从 Google 表格中检索仅限于非空白行的范围并将这些行显示为表格? 我正在寻找一个脚本,用于使用 Google Apps 脚本
尝试检索存储在 google firebase 中名为条目的节点下的表单条目,并使用谷歌工作表中的脚本编辑器附加到谷歌工作表。 我已将 FirebaseApp 库添加到谷歌表脚本编辑器。然后我的代码看
是否可以将我的 Web 应用程序的登录限制为仅限 google 组中的帐户? 我不希望每个人都可以使用他们的私有(private) gmail 登录,而只能使用我的 google 组中的用户。 最佳答
我们想使用 Google 自定义搜索实现 Google 附加链接搜索框。在谷歌 documentation , 我发现我们需要包含以下代码来启用附加链接搜索框 { "@context"
我想将特定搜索词的 Google 趋势图表添加到我的 Google Data Studio 报告中,但趋势不是数据源列表中的选项。我也找不到嵌入 JavaScript 的选项。是否可以将趋势图表添加到
是否可以将文件从 Google Drive 复制到 Google Cloud Storage?我想它会非常快,因为两者都在类似的存储系统上。 我还没有看到有关无缝执行此操作的任何方法的任何信息,而无需
之间有什么区别 ga('send', 'pageview', { 'dimension1': 'data goes here' }); 和 ga('set', 'dimension1', 'da
我正在尝试记录每个博客站点作者的点击率。 ga('send', 'pageview'); (in the header with the ga code to track each page) ga(
我设置了 Google Tag Manager 和 2 个数据层变量:一个用于跟踪用户 ID,传递给 Google Analytics 以同步用户 session ,另一个用于跟踪访问者类型。 在使用
我在我们的网站上遇到多个职位发布的问题。 我们在加拿大多个地点提供工作机会。所有职位页面都包含一个“LD+JSON ”职位发布的结构化数据,基于 Google 的职位发布文档: https://dev
公司未使用 Google 套件,使用个人(消费者)帐户(甚至是 Google 帐户)违反公司政策。 需要访问 Google Analytics - 没有 Google 帐户是否可能? 谢谢 最佳答案
我想分析人们使用哪些搜索关键字在 Play 商店中找到我的应用。 那可能吗?我怎么能这样做? 最佳答案 自 2013 年 10 月起,您可以关联您的 Google Analytics(分析)和 Goo
Google Now 和 Google Keep 中基于时间和位置的提醒与 Google Calendar 事件提醒不同。是否有公共(public) API 可以访问 Now 和 Keep 中的这些事
我是一名优秀的程序员,十分优秀!