Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. package com.damagedapps.dcedge.ui;
  2.  
  3. import android.app.Activity;
  4. import android.content.ComponentName;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.ServiceConnection;
  8. import android.os.Bundle;
  9. import android.os.IBinder;
  10. import android.os.RemoteException;
  11. import android.util.Log;
  12. import android.widget.Toast;
  13. import com.damagedapps.dcedge.custom.DownloadDetails;
  14. import com.damagedapps.dcedge.interfaces.IDownloadService;
  15. import com.damagedapps.dcedge.services.DownloadService;
  16.  
  17. import java.io.Serializable;
  18.  
  19. /**
  20.  * User: AdamGessel
  21.  * Date: Oct 20, 2010
  22.  * Time: 3:25:42 PM
  23.  */
  24. public class DownloadActivity extends Activity {
  25.  
  26.     private static final String TAG = "DownloadActivity";
  27.     private DownloadDetails dd = new DownloadDetails();
  28.     private boolean mbound = false;
  29.     private Intent serviceIntent;
  30.  
  31.  
  32.     @Override
  33.     public void onCreate(Bundle savedInstanceState) {
  34.         super.onCreate(savedInstanceState);
  35.         try {
  36.             Intent i = getIntent();
  37.             Bundle b = i.getExtras();
  38.             if (b != null) {
  39.                 dd = (DownloadDetails) b.get("DownloadActivity");
  40.             }
  41.             String fileName = dd.getUri();
  42.  
  43.             mbound = false;
  44.             serviceIntent = new Intent(IDownloadService.class.getName());
  45.             ComponentName comp = startService(serviceIntent);
  46.             if (comp == null)
  47.                 Toast.makeText(this, "startService failed....", Toast.LENGTH_LONG).show();
  48.             mbound = bindService(serviceIntent, mConnection, BIND_AUTO_CREATE);
  49.             //Toast.makeText(this, "Downloading: " + dd.getUri(), Toast.LENGTH_LONG).show();
  50.  
  51.         }
  52.         catch (Exception e) {
  53.             Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
  54.         }
  55.  
  56.  
  57.     }
  58.  
  59.  
  60.     public static IDownloadService myService;
  61.  
  62.    
  63.     private final ServiceConnection mConnection = new ServiceConnection() {
  64.         public void onServiceConnected(ComponentName name, IBinder service) {
  65.             myService = IDownloadService.Stub.asInterface(service);
  66.             Toast.makeText(DownloadActivity.this,"Testing!!!", Toast.LENGTH_LONG).show();
  67.  
  68.             //Start Downloading
  69.             try {
  70.                myService.download();
  71.             }
  72.             catch(RemoteException e)
  73.             {
  74.                 Toast.makeText(DownloadActivity.this,e.getMessage().toString(), Toast.LENGTH_LONG).show();
  75.             }
  76.         }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.         public void onServiceDisconnected(ComponentName name) {
  83.             myService = null;
  84.         }
  85.     };
  86.  
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement