添加下载管理器后无法下载视频

时间:2018-10-20 21:21:36

标签: android android-studio

public class MainActivity extends AppCompatActivity {
private Button btn1;
private EditText tf1;

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == 1){
        if (grantResults.length > 0  && grantResults[0] == PackageManager.PERMISSION_GRANTED){
            btn1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
                    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(tf1.getText().toString()));
                    dm.enqueue(request);

                }
            });
        }
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn1 = (Button)findViewById(R.id.btn1);
    tf1 =(EditText)findViewById(R.id.tf1);

    if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(tf1.getText().toString()));
                dm.enqueue(request);
            }
        });
    }else{
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
    }






    }

}

添加下载管理器后,视频未在我的手机中下载,我想从用户那里获取视频链接的输入,但是当我按下按钮时,通知栏上出现下载管理器,突然播放并且视频未下载,您可以点击我的上方代码

0 个答案:

没有答案