我在我的项目中使用Cordova启动画面插件 当我使用以下代码获取请求存储权限时,启动屏幕不起作用:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
当我删除此代码启动屏幕后,它又可以工作了!
这是我的MainActivity:
public class MainActivity extends CordovaActivity
{
boolean doubleBackToExitPressedOnce = false;
int res = 404;
int code;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
....
....
....
UiChangeListener();
requestPermission();
}
public void UiChangeListener()
{
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
}
});
}
private void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
} }
}
}
怎么了?
答案 0 :(得分:0)
代替此:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
这样写:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
对于2种不同的权限,您不必两次请求权限。您可以将多个权限组合成一个请求。
希望有帮助。
答案 1 :(得分:0)
您可以在AndroidManifest File中添加以上权限,并且要创建启动画面,只需编写如下所示的类并使用intent
public class entercsreen extends Activity {
private final int SPLASH_DISPLAY_LENGTH = 1500;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entercsreen);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(entercsreen.this,MainActivity.class);
entercsreen.this.startActivity(mainIntent);
entercsreen.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}