应用转到 "allow dropbox" 屏幕而不是 onCreate

App goes to "allow dropbox" screen instead of onCreate

已解决

完全重新安装应用程序显然是不够的。我重新启动了 phone 一次,应用程序回到了发生这种情况之前的状态。

原版post

我正在制作这个与 Dropbox 集成的应用程序,我最近 运行 遇到了一些问题。

在几个月的时间里,它发挥了应有的作用。首次安装应用程序时,它要求获得在 phone 上使用登录保管箱帐户的权限,之后所有与保管箱相关的内容都按预期在后台制作。

最近我对我的代码做了一个小改动,这使得该应用程序完全失控,它只是不断重新加载 "allow dropbox" 屏幕,您无法与该应用程序交互。所以很自然地我将更改恢复到以前的状态,但问题并没有消失。

问题

每当我启动应用程序时,它都会直接进入 "allow dropbox" 屏幕,当我按下允许或拒绝时,它会关闭应用程序并返回到我的主屏幕。

我注释掉了与 Dropbox 相关的每一行代码,在我的 phone 上完全删除并重新安装了该应用程序,并在 Android Studio 中做了很多清理和重建等等,但是问题依旧。

所以现在当我启动应用程序时,它会转到 "allow dropbox" 屏幕,但由于所有代码都被注释掉了,它只是说应用程序设置不正确,我所能做的就是再次关闭它.

清单:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/app_icon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.korpasjaervii.timereporter.MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </activity>
    <activity
        android:name="com.korpasjaervii.timereporter.CompilationActivity"
        android:parentActivityName="com.korpasjaervii.timereporter.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.korpasjaervii.timereporter.MainActivity"/>
    </activity>
    <activity
        android:name="com.korpasjaervii.timereporter.SettingsActivity"
        android:label="@string/title_activity_settings"
        android:parentActivityName="com.korpasjaervii.timereporter.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.korpasjaervii.timereporter.MainActivity" />
    </activity>
    <!--<activity
        android:name="com.dropbox.client2.android.AuthActivity"
        android:launchMode="singleTask"
        android:configChanges="orientation|keyboard">
        <intent-filter>
            <data android:scheme="db-rt97pzc7umt2krp" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>-->
    <receiver android:name=".AlarmReceiver"/>
</application>

MainActivity 的 onCreate:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

这显然不是实际的 onCreate 但我将其简化为这个问题仍然存在。

我还应该说 logcat 甚至没有注册我的应用程序已打开。

您没有提到您的应用程序的目标 SDK 版本,但是对于 Android 6.0(又名 23),权限模型已经更改,您的代码必须进行调整以在需要时请求权限如果用户没有给您请求的权限,则优雅地失败。

来自docs

// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.READ_CONTACTS)
        != PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
        Manifest.permission.READ_CONTACTS)) {

    // Show an expanation to the user *asynchronously* -- don't block
    // this thread waiting for the user's response! After the user
    // sees the explanation, try again to request the permission.

} else {

    // No explanation needed, we can request the permission.

    ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.READ_CONTACTS},
            MY_PERMISSIONS_REQUEST_READ_CONTACTS);

    // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
    // app-defined int constant. The callback method gets the
    // result of the request.
}

@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}

当您重新启动 phone 时,显然会发生一些事情,而当您完全重新安装应用程序时,这些事情不会发生。因为我已经重新安装了几次,没有任何变化,但是一旦解决了它就重新启动phone...