2016-11-09 2 views

답변

2

this가 작업중인 개체를 참조합니다 : 그것은 나에게 오류를 보여줍니다

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_vertretungsplan); 
    Button dlbutton = (Button) findViewById(R.id.buttondownload); 
    dlbutton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(myurl)); 
      request.setTitle("Vertretungsplan"); 
      request.setDescription("wird heruntergeladen"); 
      request.allowScanningByMediaScanner(); 
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
      String filename = URLUtil.guessFileName(myurl,null, MimeTypeMap.getFileExtensionFromUrl(myurl)); 
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "Schul-App",filename); 
      DownloadManager manager =(DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE); 
      manager.enqueue(request); 
     } 
    }); 

: 여기

코드입니다 당신의 Activity 클래스. 이 같은

뭔가

final Context c = this; 
dlbutton.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     //... 
     DownloadManager manager =(DownloadManager) c.getSystemService(Context.DOWNLOAD_SERVICE); 
     manager.enqueue(request); 
    } 
});