1

我下载了一个源代码,我看到了一些我无法修复的错误,如下所示

MainActivity.java

包 com.droidoxy.pocket;

导入 android.transition.* 时也出错;

private void checkReadPhoneStatePermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!hasGetReadPhoneStatePermission()) {
            requestReadPhoneStatePermission();
        }
    }
}

private boolean hasGetReadPhoneStatePermission() {
    return ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
}

private void requestReadPhoneStatePermission() {
    //You can choose a more friendly notice text. And you can choose any view you like, such as dialog.
    Toast.makeText(this, "Only grant the permission, can you start the mission!", Toast.LENGTH_SHORT).show();
    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_PHONE_STATE}, REQUEST_READ_PHONE_STATE);
}

//Callback for requestPermission
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    try {
        switch (requestCode) {
            case REQUEST_READ_PHONE_STATE: {
                    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        Toast.makeText(this, "The Permission has granted,you can get your mission now", Toast.LENGTH_SHORT).show();
                    } else {
                        //had not get the permission
                        Toast.makeText(this, "Not get the permission,so you cannot get your mission", Toast.LENGTH_SHORT).show();
                    }
                    break;
                }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

值/样式.xml

@color/colorPrimary @color/colorPrimaryDark

</style>

    <item name="windowNoTitle">true</item>
</style>
4

1 回答 1

0

根据我的知识和这里的Android 版本检查

** 我变了 **

private void checkReadPhoneStatePermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!hasGetReadPhoneStatePermission()) {
            requestReadPhoneStatePermission();
        }
    }
}

private void checkReadPhoneStatePermission() {
    if (Build.VERSION.SDK_INT >= 23) {
        if (!hasGetReadPhoneStatePermission()) {
            requestReadPhoneStatePermission();
        }
    }
}

因为M 代表 23N 代表 24

其他人位于此处获取当前运行我的应用程序的手机的 Android API 级别

而对于

值/样式.xml

@color/colorPrimary @color/colorPrimaryDark

<item name="windowNoTitle">true</item>

我添加了android:让它看起来像

值/样式.xml

@color/colorPrimary @color/colorPrimaryDark

<item name="android:windowNoTitle">true</item>

不太了解,但希望我需要帮助

于 2016-11-23T02:19:30.537 回答