다운로드도 안되고 그리고 특정폴더에 넣고 싶은데요 


java 코드


package com.ggomsu;



import java.io.BufferedInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

import java.net.URL;

import java.net.URLConnection;


import android.app.Activity;

import android.app.Dialog;

import android.app.ProgressDialog;

import android.os.AsyncTask;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.LinearLayout;


import com.google.ads.AdRequest;

import com.google.ads.AdSize;

import com.google.ads.AdView;


public class ggomsu extends Activity {

public static final int DIALOG_DOWNLOAD_PROGRESS = 0;

private Button ggomsu01;

private ProgressDialog ProgressDialog ;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

AdView adView = new AdView(this, AdSize.BANNER, "광고 코드");

LinearLayout layout = (LinearLayout)findViewById(R.id.advertisement2);

layout.addView(adView);

adView.loadAd(new AdRequest());

ggomsu01 = (Button)findViewById(R.id.ggomsu01);

ggomsu01.setOnClickListener(new OnClickListener(){

public void onClick(View v) {

startDownload();

}

});

}

private void startDownload() {

String url = "http://d9a9b351d36a4b0722064647cfb822f6.zoi.kr:2201/dl/fid/752474.121.14420.1000.70031.1/%25EB%2582%2598%25EB%258A%2594%2B%25EA%25BC%25BC%25EC%2588%2598%25EB%258B%25A4.E01.20110428.mp3";

new DownloadFileAsync().execute(url);

}

@Override

protected Dialog onCreateDialog(int id) {

switch (id) {

case DIALOG_DOWNLOAD_PROGRESS:

ProgressDialog  = new ProgressDialog(this);

ProgressDialog.setMessage("Downloading file..");

ProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

ProgressDialog.setCancelable(false);

ProgressDialog.show();

return ProgressDialog;

default:

return null;

}

}

class DownloadFileAsync extends AsyncTask<String, String, String> {

@Override

protected void onPreExecute() {

super.onPreExecute();

showDialog(DIALOG_DOWNLOAD_PROGRESS);

}

@Override

protected String doInBackground(String... aurl) {

int count;

try {

URL url = new URL("aurl[0]);

URLConnection conexion = url.openConnection();

conexion.connect();

int lenghtOfFile = conexion.getContentLength();

Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

InputStream input = new BufferedInputStream(url.openStream());

OutputStream output = new FileOutputStream("/sdcard/Downloads/");

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {

total += count;

publishProgress(""+(int)((total*100)/lenghtOfFile));

output.write(data, 0, count);

}

output.flush();

output.close();

input.close();

}

catch (Exception e){

}

return null;

}

protected void onProgressUpdate(String... progress) {

Log.d("ANDRO_ASYNC",progress[0]);

ProgressDialog.setProgress(Integer.parseInt(progress[0]));

}

@Override

protected void onPostExecute(String unused) {

dismissDialog(DIALOG_DOWNLOAD_PROGRESS);

}

}

}


xml 코드


<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >

    <LinearLayout

        xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:myapp="http://schemas.android.com/apk/res/com.korea_music_list"

        android:id="@+id/advertisement2"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"/>

    <Button

android:id="@+id/ggomsu01"  

android:layout_width="fill_parent" 

android:layout_height="wrap_content"

android:text="나는 꼼수다 1회"

android:layout_below="@+id/advertisement2"/>

</RelativeLayout>