0
나는 안드로이드 다운로드 관리자에 for 루프 내부의 ArrayList (VideoUrlArrayList) 값을 보내려고하고 있어요 그러나 나는 다음과 같은 오류가 계속
:ArrayList를 반복하여 각 값을 Download Manager에 보내는 방법은 무엇입니까?
error: incompatible types: String cannot be converted to Uri
을이 라인을 가리키는 :
DownloadManager.Request request = new DownloadManager.Request(VideoUrlArrayList.get(i));
fileName = VideoUrlArrayList.get(i).substring(VideoUrlArrayList.get(i).lastIndexOf("/"));
내가 제거하는 경우 다운로드 관리자에게 url을 보내는 코드 부분은 arrayList (VideoUrlArrayList) 값을 올바르게 표시합니다!
너희들은 내가이 문제를 해결하고 성공적으로 다운로드 관리자 내 ArrayList에 값을 보내 도움이 될 수 (또한, 내가 VideoUrlArrayList에 저장된 URL의 원본 파일 이름을 사용하려면)
MainAcitivty.java을 .Thanks?
public class MainActivity extends AppCompatActivity {
private DownloadManager downloadManager;
private long refid;
private String fileName;
ArrayList<Long> list = new ArrayList<>();
ArrayList<String> VideoUrlArrayList =new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
registerReceiver(onComplete,
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
TextView btnMultiple = (TextView) findViewById(R.id.multiple);
if(!isStoragePermissionGranted())
{
}
btnMultiple.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
list.clear();
EditText editText1 = (EditText) findViewById(R.id.editText);
String linesArray[] = editText1.getText().toString().split("\n");
for (int i = 0; i < linesArray.length; i++) {
String currLine = linesArray[i];
VideoUrlArrayList.add(currLine);
}
for (int i = 0; i < VideoUrlArrayList.size(); i++) {
//Toast.makeText(getApplicationContext(), "Array Text: " + VideoUrlArrayList.get(i), Toast.LENGTH_LONG).show();
DownloadManager.Request request = new DownloadManager.Request(VideoUrlArrayList.get(i));
fileName = VideoUrlArrayList.get(i).substring(VideoUrlArrayList.get(i).lastIndexOf("/"));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
//Set the title of this download, to be displayed in notifications (if enabled).
request.setTitle("Demo Downloading " + fileName);
//Set a description of this download, to be displayed in notifications (if enabled)
request.setDescription("Downloading " + fileName);
//Set whether this download should be displayed in the system's Downloads UI. True by default.
request.setVisibleInDownloadsUi(true);
//Set the local destination for the downloaded file to a path within the public external storage directory (as returned by getExternalStoragePublicDirectory(String)).
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
refid = downloadManager.enqueue(request);
Log.e("OUTNM", "" + refid);
list.add(refid);
}
}
});
//the rest of code after this
}
답장을 보내 주셔서 감사합니다. 나는 그것을 시도하고이 오류가 발생합니다 : 오류 : Uri 추상입니다; 인스턴스화 할 수 없습니다 – user1788736
죄송합니다, 내 대답을 업데이 트되었습니다. –
컴파일하는 동안 오류가 발생하지 않지만 프로그램을 실행하고 텍스트 상자에 일부 URL을 입력하고 프로그램이 닫히는 버튼을 누르면! (불행히도 demoApp가 중지되었습니다.) 축배가 배열 목록 데이터를 표시하지 않습니다. – user1788736