A little coding help.....

Discussion in 'Android Hacks and Help' started by johnnyb15613, Aug 7, 2011.

  1. johnnyb15613
    Offline

    johnnyb15613 Theme Developer Theme Developer

    Joined:
    Apr 16, 2010
    Messages:
    259
    Likes Received:
    2
    Trophy Points:
    0
    So, I have an activity that has four buttons centered down a linear layout. Each button represents the file that i wish to download. Heres the java code:

    PHP:
    public class TwoActivity extends Activity {
        public 
    void onCreate(Bundle savedInstanceState) {
            
    super.onCreate(savedInstanceState);
            
    setContentView(R.layout.two);

            
    Button button1 = (ButtonfindViewById(R.id.button1);
            
    button1.setOnClickListener(new View.OnClickListener() {
                @
    Override
                
    public void onClick(View v) {
                    
    sendToUrl();
                }

                private 
    void sendToUrl() {
                    
    // TODO Auto-generated method stub
                    
    String url "downloadFileOne.com";
                    
    Intent i = new Intent(Intent.ACTION_VIEW);
                    
    i.setData(Uri.parse(url));
                    
    startActivity(i);
                }
            });

            
    Button button2 = (ButtonfindViewById(R.id.button2);
            
    button2.setOnClickListener(new View.OnClickListener() {
                @
    Override
                
    public void onClick(View v) {
                    
    sendToUrl();
                }

                private 
    void sendToUrl() {
                    
    // TODO Auto-generated method stub
                    
    String url "downloadFileTwo.com";
                    
    Intent i = new Intent(Intent.ACTION_VIEW);
                    
    i.setData(Uri.parse(url));
                    
    startActivity(i);
                }
            });

            
    Button button3 = (ButtonfindViewById(R.id.button3);
            
    button3.setOnClickListener(new View.OnClickListener() {
                @
    Override
                
    public void onClick(View v) {
                    
    sendToUrl();
                }

                private 
    void sendToUrl() {
                    
    // TODO Auto-generated method stub
                    
    String url "downloadFileThree.com";
                    
    Intent i = new Intent(Intent.ACTION_VIEW);
                    
    i.setData(Uri.parse(url));
                    
    startActivity(i);
                }
            });

            
    Button button4 = (ButtonfindViewById(R.id.button4);
            
    button4.setOnClickListener(new View.OnClickListener() {
                @
    Override
                
    public void onClick(View v) {
                    
    sendToUrl();
                }

                private 
    void sendToUrl() {
                    
    // TODO Auto-generated method stub
                    
    String url "downloadFileFour.com";
                    
    Intent i = new Intent(Intent.ACTION_VIEW);
                    
    i.setData(Uri.parse(url));
                    
    startActivity(i);
                }
            });
        }
    }

    The "String url =" has the web address of the download. However, this causes the browser to pop up and initiate the download, thus returning back to the activity. How do I go about downloading these files directly (maybe using downloadFromUrl as opposed to sendToUrl). I do not know how to implement downloadFrom.

    Any help is greatly appreciated!