Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.damagedapps.dcedge.ui;
- import android.app.Activity;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.os.Bundle;
- import android.os.IBinder;
- import android.os.RemoteException;
- import android.util.Log;
- import android.widget.Toast;
- import com.damagedapps.dcedge.custom.DownloadDetails;
- import com.damagedapps.dcedge.interfaces.IDownloadService;
- import com.damagedapps.dcedge.services.DownloadService;
- import java.io.Serializable;
- /**
- * User: AdamGessel
- * Date: Oct 20, 2010
- * Time: 3:25:42 PM
- */
- public class DownloadActivity extends Activity {
- private static final String TAG = "DownloadActivity";
- private DownloadDetails dd = new DownloadDetails();
- private boolean mbound = false;
- private Intent serviceIntent;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- try {
- Intent i = getIntent();
- Bundle b = i.getExtras();
- if (b != null) {
- dd = (DownloadDetails) b.get("DownloadActivity");
- }
- String fileName = dd.getUri();
- mbound = false;
- serviceIntent = new Intent(IDownloadService.class.getName());
- ComponentName comp = startService(serviceIntent);
- if (comp == null)
- Toast.makeText(this, "startService failed....", Toast.LENGTH_LONG).show();
- mbound = bindService(serviceIntent, mConnection, BIND_AUTO_CREATE);
- //Toast.makeText(this, "Downloading: " + dd.getUri(), Toast.LENGTH_LONG).show();
- }
- catch (Exception e) {
- Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
- }
- }
- public static IDownloadService myService;
- private final ServiceConnection mConnection = new ServiceConnection() {
- public void onServiceConnected(ComponentName name, IBinder service) {
- myService = IDownloadService.Stub.asInterface(service);
- Toast.makeText(DownloadActivity.this,"Testing!!!", Toast.LENGTH_LONG).show();
- //Start Downloading
- try {
- myService.download();
- }
- catch(RemoteException e)
- {
- Toast.makeText(DownloadActivity.this,e.getMessage().toString(), Toast.LENGTH_LONG).show();
- }
- }
- public void onServiceDisconnected(ComponentName name) {
- myService = null;
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement