在Android版本6

时间:2017-05-04 17:00:30

标签: android splash

我不是Android编码的专家,但我知道一点点,这就是我从一个人那里购买这个应用程序的原因。不幸的是,应用程序作者没有给予支持,这就是我在这里发布此问题的原因。所以请帮助我,我的新应用程序在旧版本中运行良好,但在Android 6和最新版本中它被卡在启动画面中。在旧版本中,此启动画面无法正常显示。 我在android 6中启用了权限,但在启用权限后,它被卡在同一个屏幕上。我已经重新启动了应用程序很多次,但相同的错误和相同的问题,它没有去Android 6版本的第二个屏幕,并没有在其他版本中显示启动画面所以任何人都可以帮助我,请帮助我。如果您需要任何其他代码,请在回复中提及我将在此处更新..

public class Splash extends AppCompatActivity {
public static final int MY_PERMISSIONS_REQUEST_WRITE_FIELS = 102;
AlertDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    getSupportActionBar().hide();


    if (ContextCompat.checkSelfPermission(this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED ||
            ContextCompat.checkSelfPermission(this,
                    android.Manifest.permission.INTERNET)
                    != PackageManager.PERMISSION_GRANTED||
            ContextCompat.checkSelfPermission(this,
                    android.Manifest.permission.READ_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED||
            ContextCompat.checkSelfPermission(this,
                    android.Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED||
            ContextCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_NETWORK_STATE)
                    != PackageManager.PERMISSION_GRANTED||
            ContextCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED||
            ContextCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_FINE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED
            ) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) && ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.CAMERA) && ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE) && ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.INTERNET) && ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_NETWORK_STATE) && ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_COARSE_LOCATION) && ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            go_next();
        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{
                            Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
                            Manifest.permission.INTERNET,
                            Manifest.permission.ACCESS_NETWORK_STATE,
                            Manifest.permission.ACCESS_COARSE_LOCATION,
                            Manifest.permission.ACCESS_FINE_LOCATION
                    },
                    MY_PERMISSIONS_REQUEST_WRITE_FIELS);
        }
    }else{
        go_next();
    }
}
@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    if(requestCode == MY_PERMISSIONS_REQUEST_WRITE_FIELS) {
        if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            go_next();
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(Splash.this);
            builder.setMessage(R.string.permission_required)
                    .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // FIRE ZE MISSILES!
                            openPermissionScreen();
                        }
                    })
                    .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // User cancelled the dialog
                            dialog.dismiss();
                        }
                    });
            dialog = builder.show();
        }
        return;
    }
}
public  void go_next(){
    Intent intent = new Intent(Splash.this, MainActivity.class);
    startActivity(intent);
    finish();
}
public void openPermissionScreen(){
    // startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
            Uri.fromParts("package", Splash.this.getPackageName(), null));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

@Override
protected void onDestroy() {
    if(dialog!=null){
        dialog.dismiss();
        dialog = null;
    }
    super.onDestroy();
}

}

0 个答案:

没有答案