Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

In this page you can find the example usage for android.content Intent hasExtra.

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:android_network.hetnet.vpn_service.ActivityLog.java

private void handleExportPCAP(final Intent data) {
    new AsyncTask<Object, Object, Throwable>() {
        @Override//from w  w  w.j a v  a2s .  c  om
        protected Throwable doInBackground(Object... objects) {
            OutputStream out = null;
            FileInputStream in = null;
            try {
                // Stop capture
                ServiceSinkhole.setPcap(false, ActivityLog.this);

                Uri target = data.getData();
                if (data.hasExtra("org.openintents.extra.DIR_PATH"))
                    target = Uri.parse(target + "/netguard.pcap");
                Log.i(TAG, "Export PCAP URI=" + target);
                out = getContentResolver().openOutputStream(target);

                File pcap = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");
                in = new FileInputStream(pcap);

                int len;
                long total = 0;
                byte[] buf = new byte[4096];
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                    total += len;
                }
                Log.i(TAG, "Copied bytes=" + total);

                return null;
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                return ex;
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }
                if (in != null)
                    try {
                        in.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }

                // Resume capture
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityLog.this);
                if (prefs.getBoolean("pcap", false))
                    ServiceSinkhole.setPcap(true, ActivityLog.this);
            }
        }

        @Override
        protected void onPostExecute(Throwable ex) {
            if (ex == null)
                Toast.makeText(ActivityLog.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
            else
                Toast.makeText(ActivityLog.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
    }.execute();
}

From source file:cc.mintcoin.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    log.info("service start command: " + intent
            + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                    ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                    : ""));

    //log.info("org.bitcoin.NativeSecp256k1.enabled=" + org.bitcoin.NativeSecp256k1.enabled);

    if (blockChain == null) {
        boolean blockChainFileExists = blockChainFile.exists();
        boolean tryStarting = true;

        if (DownloadCompleteReceiver.isDownloading(application)) {
            log.info("isDownloading");
            DownloadCompleteReceiver.updateDownloadState(application); // it can fix itself this way

            tryStarting = false;/*w  ww .ja va 2 s .  c  om*/
        } else if (!blockChainFileExists) {
            if (DownloadCompleteReceiver.isObbAvailable(application)) {
                initializeBlockchainFast();
                tryStarting = true;
            } else if (intent.getBooleanExtra(DownloadCompleteReceiver.INTENT_EXTRA_SKIP_OBB_INIT, false)) {
                tryStarting = true;
            } else {
                // open dialog box to ask user what to do for download
                Intent intent2 = new Intent(this, InitialBlockchainActivity.class);
                intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent2);
                tryStarting = false;
            }
        }

        if (tryStarting) {
            try {
                startBlockChain();
            } catch (Error e) {
                stopSelf();
                throw e;
            }
        } else {
            stopSelf();
        }
    }

    String action = intent.getAction();

    if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
        notificationCount = 0;
        notificationAccumulatedAmount = BigInteger.ZERO;
        notificationAddresses.clear();

        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
        log.info("will remove blockchain on service shutdown");

        resetBlockchainOnShutdown = true;
        stopSelf();
    } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
        final Sha256Hash hash = new Sha256Hash(
                intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
        final Transaction tx = application.getWallet().getTransaction(hash);

        if (peerGroup != null) {
            log.info("broadcasting transaction " + tx.getHashAsString());
            peerGroup.broadcastTransaction(tx);
        } else {
            log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
        }
    }

    return START_NOT_STICKY;
}

From source file:com.google.android.gms.samples.wallet.FullWalletConfirmationButtonFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    mProgressDialog.hide();/*  w  ww. j av  a  2 s  .c  o m*/

    // retrieve the error code, if available
    int errorCode = -1;
    if (data != null) {
        errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, -1);
    }

    switch (requestCode) {
    case REQUEST_CODE_RESOLVE_ERR:
        if (resultCode == Activity.RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            handleUnrecoverableGoogleWalletError(errorCode);
        }
        break;
    case REQUEST_CODE_RESOLVE_LOAD_FULL_WALLET:
        switch (resultCode) {
        case Activity.RESULT_OK:
            if (data.hasExtra(WalletConstants.EXTRA_FULL_WALLET)) {
                FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
                // the full wallet can now be used to process the customer's payment
                // send the wallet info up to server to process, and to get the result
                // for sending a transaction status
                fetchTransactionStatus(fullWallet);
            } else if (data.hasExtra(WalletConstants.EXTRA_MASKED_WALLET)) {
                // re-launch the activity with new masked wallet information
                mMaskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
                mActivityLaunchIntent.putExtra(Constants.EXTRA_MASKED_WALLET, mMaskedWallet);
                startActivity(mActivityLaunchIntent);
            }
            break;
        case Activity.RESULT_CANCELED:
            // nothing to do here
            break;
        default:
            handleError(errorCode);
            break;
        }
        break;
    }
}

From source file:com.moxtra.moxiechat.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from w w w.  j  a  v  a 2  s.co m*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // Post notification of received message.
            boolean handled = MXNotificationManager.preProcessMXNotification(getApplicationContext(), intent);
            if (handled) {
                // This is a moxtra message and it will be handled by moxtra
                if (intent.getBooleanExtra(MXNotificationManager.MOXTRA_MESSAGE_SHOW_NOTIFICATION, false)) {
                    String title = intent.getStringExtra(MXNotificationManager.MOXTRA_MESSAGE_TITLE_TEXT);
                    if (intent.hasExtra(MXNotificationManager.MOXTRA_MESSAGE_ALERT_SOUND)) {
                        String soundUrl = intent
                                .getStringExtra(MXNotificationManager.MOXTRA_MESSAGE_ALERT_SOUND);
                        Log.d(TAG, "soundUrl = " + soundUrl);
                        Uri uri = Uri.parse(soundUrl);
                        sendMoxtraNotification(title, uri, intent);
                    } else {
                        sendMoxtraNotification(title, intent);
                    }
                }
            } else {
                // Not a moxtra message and app should handle it.
                Log.i(TAG, "App should handle it.");
            }
            Log.i(TAG, "Received: " + extras.toString());
        }
    }

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:org.klnusbaum.udj.network.PlayerCommService.java

private void joinPlayer(Intent intent, AccountManager am, Account account, boolean attemptReauth) {
    if (!Utils.isNetworkAvailable(this)) {
        doLoginFail(am, account, PlayerJoinError.NO_NETWORK_ERROR);
        return;//from w ww  .  j  a va 2s . co  m
    }

    String userId = am.getUserData(account, Constants.USER_ID_DATA);
    String playerId = intent.getStringExtra(Constants.PLAYER_ID_EXTRA);
    String ownerId = intent.getStringExtra(Constants.PLAYER_OWNER_ID_EXTRA);
    if (userId.equals(ownerId)) {
        setLoggedInToPlayer(intent, am, account, playerId);
        return;
    }

    String authToken;
    String password = "";
    boolean hasPassword = false;
    //TODO hanle error if account isn't provided
    try {
        //TODO handle if player id isn't provided
        authToken = am.blockingGetAuthToken(account, "", true);
        if (intent.hasExtra(Constants.PLAYER_PASSWORD_EXTRA)) {
            Log.d(TAG, "password given for player");
            hasPassword = true;
            password = intent.getStringExtra(Constants.PLAYER_PASSWORD_EXTRA);
        } else {
            Log.d(TAG, "No password given for player");
        }
    } catch (OperationCanceledException e) {
        Log.e(TAG, "Operation canceled exception");
        doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR);
        return;
    } catch (AuthenticatorException e) {
        Log.e(TAG, "Authenticator exception");
        doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR);
        return;
    } catch (IOException e) {
        Log.e(TAG, "IO exception");
        doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR);
        return;
    }

    try {
        if (!hasPassword) {
            ServerConnection.joinPlayer(playerId, authToken);
        } else {
            ServerConnection.joinPlayer(playerId, password, authToken);
        }
        setLoggedInToPlayer(intent, am, account, playerId);
    } catch (IOException e) {
        Log.e(TAG, "IO exception when joining player");
        Log.e(TAG, e.getMessage());
        doLoginFail(am, account, PlayerJoinError.SERVER_ERROR);
    } catch (JSONException e) {
        Log.e(TAG, "JSON exception when joining player");
        Log.e(TAG, e.getMessage());
        doLoginFail(am, account, PlayerJoinError.SERVER_ERROR);
    } catch (AuthenticationException e) {
        handleLoginAuthException(intent, am, account, authToken, attemptReauth);
    } catch (PlayerInactiveException e) {
        Log.e(TAG, "Player inactive Exception when joining player");
        doLoginFail(am, account, PlayerJoinError.PLAYER_INACTIVE_ERROR);
    } catch (ParseException e) {
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.SERVER_ERROR);
    } catch (PlayerPasswordException e) {
        Log.e(TAG, "Player Password Exception");
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.PLAYER_PASSWORD_ERROR);
    } catch (PlayerFullException e) {
        Log.e(TAG, "Player Password Exception");
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.PLAYER_FULL_ERROR);
    } catch (BannedException e) {
        Log.e(TAG, "Player Password Exception");
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.BANNED_ERROR);
    }
}

From source file:com.owncloud.android.files.services.FileUploader.java

/**
 * Entry point to add one or several files to the queue of uploads.
 *
 * New uploads are added calling to startService(), resulting in a call to
 * this method. This ensures the service will keep on working although the
 * caller activity goes away./*from w  ww. j  a  v a  2s. co  m*/
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
            || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return Service.START_NOT_STICKY;
    }
    int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
    if (uploadType == -1) {
        Log_OC.e(TAG, "Incorrect upload type provided");
        return Service.START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    if (!AccountUtils.exists(account, getApplicationContext())) {
        return Service.START_NOT_STICKY;
    }

    String[] localPaths = null, remotePaths = null, mimeTypes = null;
    OCFile[] files = null;
    if (uploadType == UPLOAD_SINGLE_FILE) {

        if (intent.hasExtra(KEY_FILE)) {
            files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };

        } else {
            localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
            remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
            mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
        }

    } else { // mUploadType == UPLOAD_MULTIPLE_FILES

        if (intent.hasExtra(KEY_FILE)) {
            files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO
                                                                         // will
                                                                         // this
                                                                         // casting
                                                                         // work
                                                                         // fine?

        } else {
            localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
            remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
            mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
        }
    }

    FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());

    boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
    boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
    int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_COPY);

    if (intent.hasExtra(KEY_FILE) && files == null) {
        Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
        return Service.START_NOT_STICKY;

    } else if (!intent.hasExtra(KEY_FILE)) {
        if (localPaths == null) {
            Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (remotePaths == null) {
            Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (localPaths.length != remotePaths.length) {
            Log_OC.e(TAG, "Different number of remote paths and local paths!");
            return Service.START_NOT_STICKY;
        }

        files = new OCFile[localPaths.length];
        for (int i = 0; i < localPaths.length; i++) {
            files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i],
                    ((mimeTypes != null) ? mimeTypes[i] : null));
            if (files[i] == null) {
                // TODO @andomaex add failure Notification
                return Service.START_NOT_STICKY;
            }
        }
    }

    OwnCloudVersion ocv = AccountUtils.getServerVersion(account);

    boolean chunked = FileUploader.chunkedUploadIsSupported(ocv);
    AbstractList<String> requestedUploads = new Vector<String>();
    String uploadKey = null;
    UploadFileOperation newUpload = null;
    try {
        for (int i = 0; i < files.length; i++) {
            newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite,
                    localAction, getApplicationContext());
            if (isInstant) {
                newUpload.setRemoteFolderToBeCreated();
            }
            newUpload.addDatatransferProgressListener(this);
            newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
            Pair<String, String> putResult = mPendingUploads.putIfAbsent(account, files[i].getRemotePath(),
                    newUpload);
            uploadKey = putResult.first;
            requestedUploads.add(uploadKey);
        }

    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (IllegalStateException e) {
        Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (Exception e) {
        Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
        return START_NOT_STICKY;

    }

    if (requestedUploads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedUploads;
        mServiceHandler.sendMessage(msg);
    }
    return Service.START_NOT_STICKY;
}

From source file:com.facebook.widget.FacebookDialog.java

static private String getEventName(Intent intent) {
    String action = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_ACTION);
    boolean hasPhotos = intent.hasExtra(NativeProtocol.EXTRA_PHOTOS);
    boolean hasVideo = false;

    Bundle extras = intent.getBundleExtra(NativeProtocol.EXTRA_PROTOCOL_METHOD_ARGS);
    if (extras != null) {
        ArrayList<String> photo = extras.getStringArrayList(NativeProtocol.METHOD_ARGS_PHOTOS);
        String video = extras.getString(NativeProtocol.METHOD_ARGS_VIDEO);
        if (photo != null && !photo.isEmpty()) {
            hasPhotos = true;//from   ww  w .j a v a  2 s.c om
        }
        if (video != null && !video.isEmpty()) {
            hasVideo = true;
        }
    }
    return getEventName(action, hasPhotos, hasVideo);
}

From source file:com.kncwallet.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    String action = null;/*from  w  w  w.  ja va  2s  .co  m*/

    if (intent == null) {
        log.info("Blockchain service started with null intent");
    } else {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        action = intent.getAction();
    }

    if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
        notificationCount = 0;
        notificationAccumulatedAmount = BigInteger.ZERO;
        notificationAddresses.clear();

        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
        log.info("will remove blockchain on service shutdown");

        resetBlockchainOnShutdown = true;
        stopSelf();
    } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
        final Sha256Hash hash = new Sha256Hash(
                intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
        final Transaction tx = application.getWallet().getTransaction(hash);

        if (peerGroup != null) {
            log.info("broadcasting transaction " + tx.getHashAsString());
            peerGroup.broadcastTransaction(tx);
        } else {
            log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
        }
    }

    return START_NOT_STICKY;
}

From source file:com.synox.android.files.services.FileUploader.java

/**
 * Entry point to add one or several files to the queue of uploads.
 *
 * New uploads are added calling to startService(), resulting in a call to
 * this method. This ensures the service will keep on working although the
 * caller activity goes away./* w w w.  j a  v a2  s . c o  m*/
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
            || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return Service.START_NOT_STICKY;
    }
    int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
    if (uploadType == -1) {
        Log_OC.e(TAG, "Incorrect upload type provided");
        return Service.START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    if (!AccountUtils.exists(account, getApplicationContext())) {
        return Service.START_NOT_STICKY;
    }

    String[] localPaths = null, remotePaths = null, mimeTypes = null;
    OCFile[] files = null;
    if (uploadType == UPLOAD_SINGLE_FILE) {

        if (intent.hasExtra(KEY_FILE)) {
            files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };

        } else {
            localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
            remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
            mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
        }

    } else { // mUploadType == UPLOAD_MULTIPLE_FILES

        if (intent.hasExtra(KEY_FILE)) {
            files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO
                                                                         // will
                                                                         // this
                                                                         // casting
                                                                         // work
                                                                         // fine?

        } else {
            localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
            remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
            mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
        }
    }

    FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());

    boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
    boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
    int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_COPY);

    if (intent.hasExtra(KEY_FILE) && files == null) {
        Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
        return Service.START_NOT_STICKY;

    } else if (!intent.hasExtra(KEY_FILE)) {
        if (localPaths == null) {
            Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (remotePaths == null) {
            Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (localPaths.length != remotePaths.length) {
            Log_OC.e(TAG, "Different number of remote paths and local paths!");
            return Service.START_NOT_STICKY;
        }

        files = new OCFile[localPaths.length];
        for (int i = 0; i < localPaths.length; i++) {
            files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i],
                    ((mimeTypes != null) ? mimeTypes[i] : null), storageManager);
            if (files[i] == null) {
                // TODO @andomaex add failure Notification
                return Service.START_NOT_STICKY;
            }
        }
    }

    OwnCloudVersion ocv = AccountUtils.getServerVersion(account);

    boolean chunked = FileUploader.chunkedUploadIsSupported(ocv);
    AbstractList<String> requestedUploads = new Vector<>();
    String uploadKey = null;
    UploadFileOperation newUpload = null;
    try {
        for (OCFile file : files) {
            uploadKey = buildRemoteName(account, file.getRemotePath());
            newUpload = new UploadFileOperation(account, file, chunked, isInstant, forceOverwrite, localAction,
                    getApplicationContext());
            if (isInstant) {
                newUpload.setRemoteFolderToBeCreated();
            }
            // Grants that the file only upload once time
            mPendingUploads.putIfAbsent(uploadKey, newUpload);

            newUpload.addDatatransferProgressListener(this);
            newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
            requestedUploads.add(uploadKey);
        }

    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (IllegalStateException e) {
        Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (Exception e) {
        Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
        return START_NOT_STICKY;

    }

    if (requestedUploads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedUploads;
        mServiceHandler.sendMessage(msg);
    }
    Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size());
    return Service.START_NOT_STICKY;
}

From source file:com.cerema.cloud2.files.services.FileUploader.java

/**
 * Entry point to add one or several files to the queue of uploads.
 *
 * New uploads are added calling to startService(), resulting in a call to
 * this method. This ensures the service will keep on working although the
 * caller activity goes away.//from   w  w  w.  j  av a  2 s .  co  m
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (intent.hasExtra(KEY_CANCEL_ALL) && intent.hasExtra(KEY_ACCOUNT)) {
        Account account = intent.getParcelableExtra(KEY_ACCOUNT);

        if (mCurrentUpload != null) {
            FileUploaderBinder fub = (FileUploaderBinder) mBinder;
            fub.cancel(account);
            return Service.START_NOT_STICKY;
        }
    }

    if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
            || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return Service.START_NOT_STICKY;
    }
    int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
    if (uploadType == -1) {
        Log_OC.e(TAG, "Incorrect upload type provided");
        return Service.START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    if (!AccountUtils.exists(account, getApplicationContext())) {
        return Service.START_NOT_STICKY;
    }

    String[] localPaths = null, remotePaths = null, mimeTypes = null;
    OCFile[] files = null;
    if (uploadType == UPLOAD_SINGLE_FILE) {

        if (intent.hasExtra(KEY_FILE)) {
            files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };

        } else {
            localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
            remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
            mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
        }

    } else { // mUploadType == UPLOAD_MULTIPLE_FILES

        if (intent.hasExtra(KEY_FILE)) {
            files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO
                                                                         // will
                                                                         // this
                                                                         // casting
                                                                         // work
                                                                         // fine?

        } else {
            localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
            remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
            mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
        }
    }

    FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());

    boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
    boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
    int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);

    if (intent.hasExtra(KEY_FILE) && files == null) {
        Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
        return Service.START_NOT_STICKY;

    } else if (!intent.hasExtra(KEY_FILE)) {
        if (localPaths == null) {
            Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (remotePaths == null) {
            Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (localPaths.length != remotePaths.length) {
            Log_OC.e(TAG, "Different number of remote paths and local paths!");
            return Service.START_NOT_STICKY;
        }

        files = new OCFile[localPaths.length];
        for (int i = 0; i < localPaths.length; i++) {
            files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i],
                    ((mimeTypes != null) ? mimeTypes[i] : null));
            if (files[i] == null) {
                // TODO @andomaex add failure Notification
                return Service.START_NOT_STICKY;
            }
        }
    }

    OwnCloudVersion ocv = AccountUtils.getServerVersion(account);

    boolean chunked = FileUploader.chunkedUploadIsSupported(ocv);
    AbstractList<String> requestedUploads = new Vector<String>();
    String uploadKey = null;
    UploadFileOperation newUpload = null;
    try {
        for (int i = 0; i < files.length; i++) {
            newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite,
                    localAction, getApplicationContext());
            if (isInstant) {
                newUpload.setRemoteFolderToBeCreated();
            }
            newUpload.addDatatransferProgressListener(this);
            newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
            Pair<String, String> putResult = mPendingUploads.putIfAbsent(account, files[i].getRemotePath(),
                    newUpload);
            if (putResult != null) {
                uploadKey = putResult.first;
                requestedUploads.add(uploadKey);
            } // else, file already in the queue of uploads; don't repeat the request
        }

    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (IllegalStateException e) {
        Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (Exception e) {
        Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
        return START_NOT_STICKY;

    }

    if (requestedUploads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedUploads;
        mServiceHandler.sendMessage(msg);
    }
    return Service.START_NOT_STICKY;
}