如何保存mediaprojection android studio的权限,即使关闭应用程序也只要求一次?

时间:2020-10-02 18:12:37

标签: java android performance android-studio android-permissions

1。我有这段代码向我询问权限,但是当我关闭应用程序时,我忘记了它们,然后像​​我一样再次询问它们,这样我就不再从版本6.0到顶部再次询问该权限。 Android。

2。因此,您只需要一次许可即可,就像大型应用程序一样。

@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    if (datos==null && code==0){
        start();
    }else{


        startService(Conector.newIntent(TakeScreen.this, code, datos));
        finish();


        Toast.makeText(TakeScreen.this,"has data",Toast.LENGTH_SHORT).show();

    }

}

public void start(){
    MediaProjectionManager mgr = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
    startActivityForResult(mgr.createScreenCaptureIntent(), REQUEST_CODE_MEDIA_PROJECTION);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case REQUEST_CODE_MEDIA_PROJECTION: {
            if (resultCode == RESULT_OK) {
                if(data!=null){
                    code=resultCode;
                    datos=data;
                    startService(Conector.newIntent(TakeScreen.this, code, datos));

                }else{
                    Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
                }

            } else {
                variableVN();
                Toast.makeText(getApplicationContext(),"Permiso denegado",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(this, FloatinBoton.class);
                stopService(intent);

            }
            finishAndRemoveTask();
            break;
        }

    }
}

0 个答案:

没有答案
相关问题