Android 应用编码错误
Android app coding error
我下载了一个源代码,我看到了一些我无法修复的错误,如下所列
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();
}
}
values/styles.xml
@color/colorPrimary
@color/colorPrimary黑暗
</style>
<item name="windowNoTitle">true</item>
</style>
据我所知和这里 Android version check
** 我改了**
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代表23而N代表24
其他人位于此处Get Android API level of phone currently running my application
而对于
values/styles.xml
@color/colorPrimary@color/colorPrimary暗
<item name="windowNoTitle">true</item>
我添加了 android: 看起来像
values/styles.xml
@color/colorPrimary@color/colorPrimary暗
<item name="android:windowNoTitle">true</item>
了解不多但希望能得到帮助
我下载了一个源代码,我看到了一些我无法修复的错误,如下所列
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();
}
}
values/styles.xml
@color/colorPrimary @color/colorPrimary黑暗
</style>
<item name="windowNoTitle">true</item>
</style>
据我所知和这里 Android version check
** 我改了**
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代表23而N代表24
其他人位于此处Get Android API level of phone currently running my application
而对于
values/styles.xml
@color/colorPrimary@color/colorPrimary暗
<item name="windowNoTitle">true</item>
我添加了 android: 看起来像
values/styles.xml
@color/colorPrimary@color/colorPrimary暗
<item name="android:windowNoTitle">true</item>
了解不多但希望能得到帮助