1. You want that $100.00 in your pocket or an Amazon Fire TV don't you? Well here's the deal. With our new updated look we are in desperate need of an updated logo. The 'old' one has certainly served us well, but it's time. Find all the details here: bit.ly/1q0k6Wa
  2. DroidForums.net is currently undergoing a major software upgrade. If you are experiencing any problems logging in please: Contact Us

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!