2013-08-04 4 views
0

안드로이드 앱 안의 웹 사이트를 열 때 webview를 사용하고 있지만 다운로드 파일 링크를 클릭하면 다운로드가 시작되지 않습니다. 내가 어떻게?Android : Webview를 사용하고 있지만 다운로드하지 않습니다.

사이트는 음악 다운로드이지만 mp3 파일 링크를 클릭하면 아무 일도 일어나지 않습니다.

코드 :

public class MainActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.main); 

    // Let's display the progress in the activity title bar, like the 
    // browser app does. 
    getWindow().requestFeature(Window.FEATURE_PROGRESS); 

    WebView webview = new WebView(this); 
    setContentView(webview); 
    webview.getSettings().setJavaScriptEnabled(true); 

    final Activity activity = this; 
    webview.setWebChromeClient(new WebChromeClient() { 
     public void onProgressChanged(WebView view, int progress) { 
      // Activities and WebViews measure progress with different scales. 
      // The progress meter will automatically disappear when we reach 100% 
      activity.setProgress(progress * 1000); 
     } 
    }); 

    webview.setWebViewClient(new WebViewClient() { 

     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
      //Users will be notified in case there's an error (i.e. no internet connection) 
      Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    //This will load the webpage that we want to see 
    webview.loadUrl("http://www.xtramasti.com/"); 



} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

} 

답변

1

시도 documentation에서 webview.setDownloadListener(new DownloadListener() { ... });

Source

사용 :

레지스터 내용이 렌더링에 의해 처리 할 수없는 경우에 사용되는 인터페이스 엔진 및 대신 다운로드 할 수 있습니다. 이것은 현재 처리기를 바꿉니다.

DownloadListener interfaceonDownloadStart 방법 :

파일을 다운로드해야 호스트 응용 프로그램을 통지

관련 문제