Example usage for android.provider BaseColumns _ID

List of usage examples for android.provider BaseColumns _ID

Introduction

In this page you can find the example usage for android.provider BaseColumns _ID.

Prototype

String _ID

To view the source code for android.provider BaseColumns _ID.

Click Source Link

Document

The unique ID for a row.

Usage

From source file:org.andstatus.app.account.AccountSelector.java

private MySimpleAdapter newListAdapter(List<MyAccount> listData) {
    List<Map<String, String>> list = new ArrayList<>();
    final String syncText = getText(R.string.synced_abbreviated).toString();
    for (MyAccount ma : listData) {
        Map<String, String> map = new HashMap<>();
        String visibleName = ma.getAccountName();
        if (!ma.isValidAndSucceeded()) {
            visibleName = "(" + visibleName + ")";
        }//from w ww. j  av  a2s.  co m
        map.put(KEY_VISIBLE_NAME, visibleName);
        map.put(KEY_SYNC_AUTO, ma.isSyncedAutomatically() && ma.isValidAndSucceeded() ? syncText : "");
        map.put(BaseColumns._ID, Long.toString(ma.getUserId()));
        list.add(map);
    }

    return new MySimpleAdapter(getActivity(), list, R.layout.accountlist_item,
            new String[] { KEY_VISIBLE_NAME, KEY_SYNC_AUTO, BaseColumns._ID },
            new int[] { R.id.visible_name, R.id.sync_auto, R.id.id }, true);
}

From source file:org.cnx.quizcards.activities.CardListActivity.java

private void getCards() {
    String[] projection = { BaseColumns._ID, DECK_ID, TERM, MEANING };
    String selection = DECK_ID + " = '" + id + "'";
    String order = "LOWER(" + TERM + ")"; //SQLite normally orders any upper case before all lower case
    cardsCursor = getContentResolver().query(CardProvider.CONTENT_URI, projection, selection, null, order);
    cardsCursor.moveToFirst();/*  w w w . j a va 2  s.  com*/

    int[] to = { R.id.term, R.id.meaning };
    String[] from = { TERM, MEANING };
    cursorAdapter = new SimpleCursorAdapter(this, R.layout.card_list_row, cardsCursor, from, to,
            CursorAdapter.NO_SELECTION);

    cardListView.setAdapter(cursorAdapter);
}

From source file:de.schildbach.wallet.litecoin.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) {
        LycBtcRate = getLycBtcRate();/*from  w ww .j a v  a 2 s .  co m*/
        if (LycBtcRate == null)
            return null;

        Map<String, ExchangeRate> newExchangeRates = getBlockchainInfo();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getLycancoinCharts();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(entry.getKey().hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String code = selectionArgs[0];
        final ExchangeRate rate = exchangeRates.get(code);
        try {
            cursor.newRow().add(code.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        } catch (NullPointerException e) {
            Log.e("Lycancoin", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:com.frostwire.android.gui.Librarian.java

/**
 * @param fileType the file type/* ww w. j a  v  a  2s . c o m*/
 * @return the number of files registered in the providers
 */
public int getNumFiles(Context context, byte fileType) {
    TableFetcher fetcher = TableFetchers.getFetcher(fileType);
    Cursor c = null;

    int numFiles = 0;

    try {
        ContentResolver cr = context.getContentResolver();
        c = cr.query(fetcher.getContentUri(), new String[] { "count(" + BaseColumns._ID + ")" },
                fetcher.where(), fetcher.whereArgs(), null);
        numFiles = c != null && c.moveToFirst() ? c.getInt(0) : 0;
    } catch (Throwable e) {
        Log.e(TAG, "Failed to get num of files", e);
    } finally {
        if (c != null) {
            c.close();
        }
    }

    return numFiles;
}

From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java

@Override
public void onCreate() {
    super.onCreate();
    mGeocoder = new Geocoder(this);
    mContentObserver = new ContentObserver(new Handler()) {
        @Override/*from   ww  w  . j  a  v a  2 s  .com*/
        public void onChange(boolean selfChange, Uri uri) {
            // Update the metadata
            updateMeta();

            // See if we've just added the very first image
            Artwork currentArtwork = getCurrentArtwork();
            if (currentArtwork == null) {
                publishNextArtwork(null);
                return;
            }

            // See if the current artwork was removed
            Cursor data = getContentResolver().query(GalleryContract.ChosenPhotos.CONTENT_URI,
                    new String[] { BaseColumns._ID }, GalleryContract.ChosenPhotos.COLUMN_NAME_URI + "=?",
                    new String[] { currentArtwork.getToken() }, null);
            if (data == null || !data.moveToFirst()) {
                // We're showing a removed URI
                publishNextArtwork(null);
            }
            if (data != null) {
                data.close();
            }
        }
    };
    // Make any changes since the last time the GalleryArtSource was created
    mContentObserver.onChange(false, GalleryContract.ChosenPhotos.CONTENT_URI);
    getContentResolver().registerContentObserver(GalleryContract.ChosenPhotos.CONTENT_URI, true,
            mContentObserver);
}

From source file:com.nadmm.airports.e6b.E6bMenuFragment.java

@Override
protected void onListItemClick(ListView l, View v, int position) {
    Cursor c = (Cursor) getListAdapter().getItem(position);
    long id = c.getLong(c.getColumnIndex(BaseColumns._ID));
    Class<?> clss = getItemFragmentClass(id);
    if (clss == E6bMenuFragment.class || Application.sDonationDone) {
        super.onListItemClick(l, v, position);
    } else {//  ww w  .j av a2  s.  c  o m
        UiUtils.showToast(getActivity(), "This function is only available after a donation");
    }
}

From source file:com.example.android.dragonTV.data.VideoDatabase.java

/**
 * Builds a map for all columns that may be requested, which will be given to the
 * SQLiteQueryBuilder. This is a good way to define aliases for column names, but must include
 * all columns, even if the value is the key. This allows the ContentProvider to request
 * columns w/o the need to know real column names and create the alias itself.
 *///from w w w  .j ava2s.  c o  m
private static HashMap<String, String> buildColumnMap() {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put(KEY_NAME, KEY_NAME);
    map.put(KEY_DESCRIPTION, KEY_DESCRIPTION);
    map.put(KEY_ICON, KEY_ICON);
    map.put(KEY_DATA_TYPE, KEY_DATA_TYPE);
    map.put(KEY_IS_LIVE, KEY_IS_LIVE);
    map.put(KEY_VIDEO_WIDTH, KEY_VIDEO_WIDTH);
    map.put(KEY_VIDEO_HEIGHT, KEY_VIDEO_HEIGHT);
    map.put(KEY_AUDIO_CHANNEL_CONFIG, KEY_AUDIO_CHANNEL_CONFIG);
    map.put(KEY_PURCHASE_PRICE, KEY_PURCHASE_PRICE);
    map.put(KEY_RENTAL_PRICE, KEY_RENTAL_PRICE);
    map.put(KEY_RATING_STYLE, KEY_RATING_STYLE);
    map.put(KEY_RATING_SCORE, KEY_RATING_SCORE);
    map.put(KEY_PRODUCTION_YEAR, KEY_PRODUCTION_YEAR);
    map.put(KEY_COLUMN_DURATION, KEY_COLUMN_DURATION);
    map.put(KEY_ACTION, KEY_ACTION);
    map.put(BaseColumns._ID, "rowid AS " + BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID,
            "rowid AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

From source file:com.mpower.daktar.android.tasks.DownloadFormsTask.java

@Override
protected HashMap<String, String> doInBackground(final ArrayList<FormDetails>... values) {
    final ArrayList<FormDetails> toDownload = values[0];

    final int total = toDownload.size();
    int count = 1;

    final HashMap<String, String> result = new HashMap<String, String>();

    for (int i = 0; i < total; i++) {
        final FormDetails fd = toDownload.get(i);
        publishProgress(fd.formName, Integer.valueOf(count).toString(), Integer.valueOf(total).toString());

        String message = "";

        try {//from   w  w  w. j a va2  s  . c o  m
            // get the xml file
            // if we've downloaded a duplicate, this gives us the file
            final File dl = downloadXform(fd.formName, fd.downloadUrl);

            final String[] projection = { BaseColumns._ID, FormsColumns.FORM_FILE_PATH };
            final String[] selectionArgs = { dl.getAbsolutePath() };
            final String selection = FormsColumns.FORM_FILE_PATH + "=?";
            final Cursor alreadyExists = MIntel.getInstance().getContentResolver()
                    .query(FormsColumns.CONTENT_URI, projection, selection, selectionArgs, null);

            Uri uri = null;
            if (alreadyExists.getCount() <= 0) {
                // doesn't exist, so insert it
                final ContentValues v = new ContentValues();
                v.put(FormsColumns.FORM_FILE_PATH, dl.getAbsolutePath());

                final HashMap<String, String> formInfo = FileUtils.parseXML(dl);
                v.put(FormsColumns.DISPLAY_NAME, formInfo.get(FileUtils.TITLE));
                v.put(FormsColumns.MODEL_VERSION, formInfo.get(FileUtils.MODEL));
                v.put(FormsColumns.UI_VERSION, formInfo.get(FileUtils.UI));
                v.put(FormsColumns.JR_FORM_ID, formInfo.get(FileUtils.FORMID));
                v.put(FormsColumns.SUBMISSION_URI, formInfo.get(FileUtils.SUBMISSIONURI));
                uri = MIntel.getInstance().getContentResolver().insert(FormsColumns.CONTENT_URI, v);
            } else {
                alreadyExists.moveToFirst();
                uri = Uri.withAppendedPath(FormsColumns.CONTENT_URI,
                        alreadyExists.getString(alreadyExists.getColumnIndex(BaseColumns._ID)));
            }

            if (fd.manifestUrl != null) {
                final Cursor c = MIntel.getInstance().getContentResolver().query(uri, null, null, null, null);
                if (c.getCount() > 0) {
                    // should be exactly 1
                    c.moveToFirst();

                    final String error = downloadManifestAndMediaFiles(
                            c.getString(c.getColumnIndex(FormsColumns.FORM_MEDIA_PATH)), fd, count, total);
                    if (error != null) {
                        message += error;
                    }
                }
            } else {
                // TODO: manifest was null?
                Log.e(t, "Manifest was null.  PANIC");
            }
        } catch (final SocketTimeoutException se) {
            se.printStackTrace();
            message += se.getMessage();
        } catch (final Exception e) {
            e.printStackTrace();
            if (e.getCause() != null) {
                message += e.getCause().getMessage();
            } else {
                message += e.getMessage();
            }
        }
        count++;
        if (message.equalsIgnoreCase("")) {
            message = MIntel.getInstance().getString(R.string.success);
        }
        result.put(fd.formName, message);
    }

    return result;
}

From source file:com.example.android.tvleanback2.data.VideoDatabase.java

/**
 * Builds a map for all columns that may be requested, which will be given to the
 * SQLiteQueryBuilder. This is a good way to define aliases for column names, but must include
 * all columns, even if the value is the key. This allows the ContentProvider to request
 * columns w/o the need to know real column names and create the alias itself.
 *///from   www  .  j  av  a 2  s. c  o m
private static HashMap<String, String> buildColumnMap() {
    HashMap<String, String> map = new HashMap<>();
    map.put(KEY_NAME, KEY_NAME);
    map.put(KEY_DESCRIPTION, KEY_DESCRIPTION);
    map.put(KEY_ICON, KEY_ICON);
    map.put(KEY_DATA_TYPE, KEY_DATA_TYPE);
    map.put(KEY_IS_LIVE, KEY_IS_LIVE);
    map.put(KEY_VIDEO_WIDTH, KEY_VIDEO_WIDTH);
    map.put(KEY_VIDEO_HEIGHT, KEY_VIDEO_HEIGHT);
    map.put(KEY_AUDIO_CHANNEL_CONFIG, KEY_AUDIO_CHANNEL_CONFIG);
    map.put(KEY_PURCHASE_PRICE, KEY_PURCHASE_PRICE);
    map.put(KEY_RENTAL_PRICE, KEY_RENTAL_PRICE);
    map.put(KEY_RATING_STYLE, KEY_RATING_STYLE);
    map.put(KEY_RATING_SCORE, KEY_RATING_SCORE);
    map.put(KEY_PRODUCTION_YEAR, KEY_PRODUCTION_YEAR);
    map.put(KEY_COLUMN_DURATION, KEY_COLUMN_DURATION);
    map.put(KEY_ACTION, KEY_ACTION);
    map.put(BaseColumns._ID, "rowid AS " + BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID,
            "rowid AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

From source file:com.mpower.daktar.android.tasks.InstanceUploaderTask.java

@Override
protected HashMap<String, String> doInBackground(final Long... values) {
    mResults = new HashMap<String, String>();

    String postResponse;//from   w  w w.  j  a  va 2  s.  co m
    String selection = BaseColumns._ID + "=?";
    final String[] selectionArgs = new String[values.length];
    for (int i = 0; i < values.length; i++) {
        if (i != values.length - 1) {
            selection += " or " + BaseColumns._ID + "=?";
        }
        selectionArgs[i] = values[i].toString();
    }

    // get shared HttpContext so that authentication and cookies are
    // retained.
    final HttpContext localContext = MIntel.getInstance().getHttpContext();
    final HttpClient httpclient = WebUtils.createHttpClient(CONNECTION_TIMEOUT);

    final Map<URI, URI> uriRemap = new HashMap<URI, URI>();

    final Cursor c = MIntel.getInstance().getContentResolver().query(InstanceColumns.CONTENT_URI, null,
            selection, selectionArgs, null);

    if (c.getCount() > 0) {
        c.moveToPosition(-1);
        next_submission: while (c.moveToNext()) {
            if (isCancelled())
                return mResults;
            publishProgress(c.getPosition() + 1, c.getCount());
            final String instance = c.getString(c.getColumnIndex(InstanceColumns.INSTANCE_FILE_PATH));
            final String id = c.getString(c.getColumnIndex(BaseColumns._ID));
            final Uri toUpdate = Uri.withAppendedPath(InstanceColumns.CONTENT_URI, id);

            String urlString = c.getString(c.getColumnIndex(InstanceColumns.SUBMISSION_URI));
            if (urlString == null) {
                final SharedPreferences settings = PreferenceManager
                        .getDefaultSharedPreferences(MIntel.getInstance());
                urlString = settings.getString(PreferencesActivity.KEY_SERVER_URL, null);
                urlString = urlString + WebUtils.URL_PART_SUBMISSION;
            }

            final ContentValues cv = new ContentValues();
            URI u = null;
            try {
                final URL url = new URL(URLDecoder.decode(urlString, "utf-8"));
                u = url.toURI();
            } catch (final MalformedURLException e) {
                e.printStackTrace();
                mResults.put(id, fail + "invalid url: " + urlString + " :: details: " + e.getMessage());
                cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                continue;
            } catch (final URISyntaxException e) {
                e.printStackTrace();
                mResults.put(id, fail + "invalid uri: " + urlString + " :: details: " + e.getMessage());
                cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                continue;
            } catch (final UnsupportedEncodingException e) {
                e.printStackTrace();
                mResults.put(id, fail + "invalid url: " + urlString + " :: details: " + e.getMessage());
                cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                continue;
            }

            boolean openRosaServer = false;
            if (uriRemap.containsKey(u)) {
                // we already issued a head request and got a response,
                // so we know the proper URL to send the submission to
                // and the proper scheme. We also know that it was an
                // OpenRosa compliant server.
                openRosaServer = true;
                u = uriRemap.get(u);
            } else {
                // we need to issue a head request
                final HttpHead httpHead = WebUtils.createOpenRosaHttpHead(u);

                // prepare response
                HttpResponse response = null;
                try {
                    response = httpclient.execute(httpHead, localContext);
                    final int statusCode = response.getStatusLine().getStatusCode();
                    if (statusCode == 401) {
                        // we need authentication, so stop and return what
                        // we've
                        // done so far.
                        mAuthRequestingServer = u;
                        return null;
                    } else if (statusCode == 204) {
                        final Header[] locations = response.getHeaders("Location");
                        if (locations != null && locations.length == 1) {
                            try {
                                final URL url = new URL(URLDecoder.decode(locations[0].getValue(), "utf-8"));
                                final URI uNew = url.toURI();
                                if (u.getHost().equalsIgnoreCase(uNew.getHost())) {
                                    openRosaServer = true;
                                    // trust the server to tell us a new
                                    // location
                                    // ... and possibly to use https
                                    // instead.
                                    uriRemap.put(u, uNew);
                                    u = uNew;
                                } else {
                                    // Don't follow a redirection attempt to
                                    // a different host.
                                    // We can't tell if this is a spoof or
                                    // not.
                                    mResults.put(id,
                                            fail + "Unexpected redirection attempt to a different host: "
                                                    + uNew.toString());
                                    cv.put(InstanceColumns.STATUS,
                                            InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                                    MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                                    continue;
                                }
                            } catch (final Exception e) {
                                e.printStackTrace();
                                mResults.put(id, fail + urlString + " " + e.getMessage());
                                cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                                MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                                continue;
                            }
                        }
                    } else {
                        // may be a server that does not handle
                        try {
                            // have to read the stream in order to reuse the
                            // connection
                            final InputStream is = response.getEntity().getContent();
                            // read to end of stream...
                            final long count = 1024L;
                            while (is.skip(count) == count) {
                                ;
                            }
                            is.close();
                        } catch (final IOException e) {
                            e.printStackTrace();
                        } catch (final Exception e) {
                            e.printStackTrace();
                        }

                        Log.w(t, "Status code on Head request: " + statusCode);
                        if (statusCode >= 200 && statusCode <= 299) {
                            mResults.put(id, fail
                                    + "Invalid status code on Head request.  If you have a web proxy, you may need to login to your network. ");
                            cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                            MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                            continue;
                        }
                    }
                } catch (final ClientProtocolException e) {
                    e.printStackTrace();
                    Log.e(t, e.getMessage());
                    mResults.put(id, fail + "Client Protocol Exception");
                    cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                    MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                    continue;
                } catch (final ConnectTimeoutException e) {
                    e.printStackTrace();
                    Log.e(t, e.getMessage());
                    mResults.put(id, fail + "Connection Timeout");
                    cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                    MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                    continue;
                } catch (final UnknownHostException e) {
                    e.printStackTrace();
                    mResults.put(id, fail + e.getMessage() + " :: Network Connection Failed");
                    Log.e(t, e.getMessage());
                    cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                    MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                    continue;
                } catch (final Exception e) {
                    e.printStackTrace();
                    mResults.put(id, fail + "Generic Exception");
                    Log.e(t, e.getMessage());
                    cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                    MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                    continue;
                }
            }

            // At this point, we may have updated the uri to use https.
            // This occurs only if the Location header keeps the host name
            // the same. If it specifies a different host name, we error
            // out.
            //
            // And we may have set authentication cookies in our
            // cookiestore (referenced by localContext) that will enable
            // authenticated publication to the server.
            //
            // get instance file
            final File instanceFile = new File(instance);

            if (!instanceFile.exists()) {
                mResults.put(id, fail + "instance XML file does not exist!");
                cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                continue;
            }

            // find all files in parent directory
            final File[] allFiles = instanceFile.getParentFile().listFiles();

            // add media files
            final List<File> files = new ArrayList<File>();
            for (final File f : allFiles) {
                final String fileName = f.getName();

                final int dotIndex = fileName.lastIndexOf(".");
                String extension = "";
                if (dotIndex != -1) {
                    extension = fileName.substring(dotIndex + 1);
                }

                if (fileName.startsWith(".")) {
                    // ignore invisible files
                    continue;
                }
                if (fileName.equals(instanceFile.getName())) {
                    continue; // the xml file has already been added
                } else if (openRosaServer) {
                    files.add(f);
                } else if (extension.equals("jpg")) { // legacy 0.9x
                    files.add(f);
                } else if (extension.equals("3gpp")) { // legacy 0.9x
                    files.add(f);
                } else if (extension.equals("3gp")) { // legacy 0.9x
                    files.add(f);
                } else if (extension.equals("mp4")) { // legacy 0.9x
                    files.add(f);
                } else if (extension.equals("amr")) { // legacy 0.9x
                    files.add(f);
                } else {
                    Log.w(t, "unrecognized file type " + f.getName());
                }
            }

            postResponse = "";
            boolean first = true;
            int j = 0;
            while (j < files.size() || first) {
                first = false;

                final HttpPost httppost = WebUtils.createOpenRosaHttpPost(u, mAuth);

                final MimeTypeMap m = MimeTypeMap.getSingleton();

                long byteCount = 0L;

                // mime post
                final MultipartEntity entity = new MultipartEntity();

                // add the submission file first...
                FileBody fb = new FileBody(instanceFile, "text/xml");
                entity.addPart("xml_submission_file", fb);
                Log.i(t, "added xml_submission_file: " + instanceFile.getName());
                byteCount += instanceFile.length();

                for (; j < files.size(); j++) {
                    final File f = files.get(j);
                    final String fileName = f.getName();
                    final int idx = fileName.lastIndexOf(".");
                    String extension = "";
                    if (idx != -1) {
                        extension = fileName.substring(idx + 1);
                    }
                    String contentType = m.getMimeTypeFromExtension(extension);

                    // we will be processing every one of these, so
                    // we only need to deal with the content type
                    // determination...
                    if (extension.equals("xml")) {
                        fb = new FileBody(f, "text/xml");
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added xml file " + f.getName());
                    } else if (extension.equals("jpg")) {
                        fb = new FileBody(f, "image/jpeg");
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added image file " + f.getName());
                    } else if (extension.equals("3gpp")) {
                        fb = new FileBody(f, "audio/3gpp");
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added audio file " + f.getName());
                    } else if (extension.equals("3gp")) {
                        fb = new FileBody(f, "video/3gpp");
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added video file " + f.getName());
                    } else if (extension.equals("mp4")) {
                        fb = new FileBody(f, "video/mp4");
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added video file " + f.getName());
                    } else if (extension.equals("csv")) {
                        fb = new FileBody(f, "text/csv");
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added csv file " + f.getName());
                    } else if (f.getName().endsWith(".amr")) {
                        fb = new FileBody(f, "audio/amr");
                        entity.addPart(f.getName(), fb);
                        Log.i(t, "added audio file " + f.getName());
                    } else if (extension.equals("xls")) {
                        fb = new FileBody(f, "application/vnd.ms-excel");
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added xls file " + f.getName());
                    } else if (contentType != null) {
                        fb = new FileBody(f, contentType);
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.i(t, "added recognized filetype (" + contentType + ") " + f.getName());
                    } else {
                        contentType = "application/octet-stream";
                        fb = new FileBody(f, contentType);
                        entity.addPart(f.getName(), fb);
                        byteCount += f.length();
                        Log.w(t, "added unrecognized file (" + contentType + ") " + f.getName());
                    }

                    // we've added at least one attachment to the request...
                    if (j + 1 < files.size()) {
                        if (byteCount + files.get(j + 1).length() > 10000000L) {
                            // the next file would exceed the 10MB
                            // threshold...
                            Log.i(t, "Extremely long post is being split into multiple posts");
                            try {
                                final StringBody sb = new StringBody("yes", Charset.forName("UTF-8"));
                                entity.addPart("*isIncomplete*", sb);
                            } catch (final Exception e) {
                                e.printStackTrace(); // never happens...
                            }
                            ++j; // advance over the last attachment
                            // added...
                            break;
                        }
                    }
                }

                httppost.setEntity(entity);

                // prepare response and return uploaded
                HttpResponse response = null;
                try {
                    response = httpclient.execute(httppost, localContext);
                    final int responseCode = response.getStatusLine().getStatusCode();

                    // try {
                    // // have to read the stream in order to reuse the
                    // connection
                    // InputStream is = response.getEntity().getContent();
                    // // read to end of stream...
                    // final long count = 1024L;
                    // while (is.skip(count) == count)
                    // ;
                    // is.close();
                    // } catch (IOException e) {
                    // e.printStackTrace();
                    // } catch (Exception e) {
                    // e.printStackTrace();
                    // }

                    final HttpEntity httpEntity = response.getEntity();
                    try {
                        postResponse = EntityUtils.toString(httpEntity, HTTP.UTF_8).trim();
                    } catch (final IOException e) {
                        e.printStackTrace();
                    }

                    Log.i(t, "Response code:" + responseCode);
                    // verify that the response was a 201 or 202.
                    // If it wasn't, the submission has failed.
                    if (responseCode != 201 && responseCode != 202) {
                        if (responseCode == 200) {
                            mResults.put(id, fail + "Network login failure? Again?");
                        } else {
                            if (postResponse.length() > 0) {
                                mResults.put(id, postResponse);
                            } else {
                                mResults.put(id, fail + response.getStatusLine().getReasonPhrase() + " ("
                                        + responseCode + ") at " + urlString);
                            }
                        }
                        cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                        MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                        continue next_submission;
                    }
                } catch (final Exception e) {
                    e.printStackTrace();
                    mResults.put(id, fail + " " + e.getMessage());
                    cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED);
                    MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);
                    continue next_submission;
                }
            }

            // if it got here, it must have worked
            if (postResponse.length() > 0) {
                // Custom msg from server
                mResults.put(id, postResponse);
            } else {
                // There is no response from server, use default string
                mResults.put(id, MIntel.getInstance().getString(R.string.success));
            }
            // mResults.put(id,
            // MIntel.getInstance().getString(R.string.success));
            cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMITTED);
            MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null);

        }
        if (c != null) {
            c.close();
        }

    } // end while

    return mResults;
}