我正在尝试使用Google Play服务。为了尝试该服务,我创建了一个只有一个具有登录代码的活动的应用程序。我添加了库并在Google Play控制台上创建了我的应用。获取我的ID并将其添加到我的清单中。
但是当我尝试测试我的应用时,我在logcat上得到了这个:
09-11 16:55:30.500 2387-5329/? E/DatabaseUtils﹕ Writing exception to parcel
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
我做过的事情:
清单:
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
互联网许可:
<uses-permission android:name="android.permission.INTERNET"/>
grandle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.google.android.gms:play-services:4.4.52'
compile project(':libraries:BaseGameUtils')
}
注意:我使用的是版本4.4.52,因为我的设备上没有更新最新版本,并且它提供“此应用程序无法正常工作,除非更新Google Play服务”之类的东西。所以我在sdk中降级了我的lib。
类别:
public class MyActivity extends BaseGameActivity implements View.OnClickListener {
Button signOutBut;
View signInBut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_my);
signOutBut = (Button) findViewById(R.id.sign_out_button);
setContentView(R.layout.activity_my);
signOutBut.setOnClickListener(this);
findViewById(R.id.sign_in_button).setOnClickListener(this);
checkIfOk();
}
private boolean checkIfOk() {
int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, this, 1122).show();
return false;
} else {
return true;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.sign_in_button){
beginUserInitiatedSignIn();
}else {
signOut();
signOutBut.setVisibility(View.GONE);
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
}
}
@Override
public void onSignInFailed() {
Toast.makeText(getApplicationContext(), "ss", Toast.LENGTH_SHORT).show();
}
@Override
public void onSignInSucceeded() {
signOutBut.setVisibility(View.VISIBLE);
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
}
}
出现此错误的原因是什么?