Example usage for android.content Context sendBroadcast

List of usage examples for android.content Context sendBroadcast

Introduction

In this page you can find the example usage for android.content Context sendBroadcast.

Prototype

public abstract void sendBroadcast(@RequiresPermission Intent intent);

Source Link

Document

Broadcast the given intent to all interested BroadcastReceivers.

Usage

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

public static void DownloadFromUrl(final String media, final String messageId, final Context ctx,
        final ImageView container, final Object object, final String timelineId, final String localId,
        final Long fileSize) {

    new AsyncTask<Void, Void, Boolean>() {
        private boolean retry = true;
        private Bitmap imageDownloaded;
        private BroadcastReceiver mDownloadCancelReceiver;
        private HttpGet job;
        private AccountManager am;
        private Account account;
        private String authToken;

        @Override/*from www. java  2 s  .  c om*/
        protected void onPreExecute() {
            IntentFilter downloadFilter = new IntentFilter(ConstantKeys.BROADCAST_CANCEL_PROCESS);
            mDownloadCancelReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String localIdToClose = (String) intent.getExtras().get(ConstantKeys.LOCALID);
                    if (localId.equals(localIdToClose)) {
                        try {
                            job.abort();
                        } catch (Exception e) {
                            log.debug("The process was canceled");
                        }
                        cancel(false);
                    }
                }
            };

            // registering our receiver
            ctx.getApplicationContext().registerReceiver(mDownloadCancelReceiver, downloadFilter);
        }

        @Override
        protected void onCancelled() {
            File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG);
            File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP);

            if (file1.exists()) {
                file1.delete();
            }
            if (file2.exists()) {
                file2.delete();
            }

            file1 = null;
            file2 = null;
            System.gc();
            try {
                ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver);
            } catch (Exception e) {
                log.debug("Receriver unregister from another code");
            }

            for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) {
                if (AppUtils.getlistOfDownload().get(i).equals(localId)) {
                    AppUtils.getlistOfDownload().remove(i);
                }
            }

            DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId, 100);

            Intent intent = new Intent();
            intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH);
            intent.putExtra(ConstantKeys.LOCALID, localId);
            ctx.sendBroadcast(intent);

            if (object != null) {
                ((ProgressDialog) object).dismiss();
            }
        }

        @Override
        protected Boolean doInBackground(Void... params) {
            try {
                File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG);
                File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP);
                // firt we are goint to search the local files
                if ((!file1.exists()) && (!file2.exists())) {
                    account = AccountUtils.getAccount(ctx.getApplicationContext(), false);
                    am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE);
                    authToken = ConstantKeys.STRING_DEFAULT;
                    authToken = am.blockingGetAuthToken(account, ctx.getString(R.string.account_type), true);

                    MessagingClientService messageService = new MessagingClientService(
                            ctx.getApplicationContext());

                    URL urlObj = new URL(Preferences.getServerProtocol(ctx), Preferences.getServerAddress(ctx),
                            Preferences.getServerPort(ctx), ctx.getString(R.string.url_get_content));

                    String url = ConstantKeys.STRING_DEFAULT;
                    url = Uri.parse(urlObj.toString()).buildUpon().build().toString() + timelineId + "/"
                            + messageId + "/" + "content";

                    job = new HttpGet(url);
                    // first, get free space
                    FreeUpSpace(ctx, fileSize);
                    messageService.getContent(authToken, media, messageId, timelineId, localId, false, false,
                            fileSize, job);
                }

                if (file1.exists()) {
                    imageDownloaded = decodeSampledBitmapFromPath(file1.getAbsolutePath(), 200, 200);
                } else if (file2.exists()) {
                    imageDownloaded = ThumbnailUtils.createVideoThumbnail(file2.getAbsolutePath(),
                            MediaStore.Images.Thumbnails.MINI_KIND);
                }

                if (imageDownloaded == null) {
                    return false;
                }
                return true;
            } catch (Exception e) {
                deleteFiles();
                return false;
            }
        }

        @Override
        protected void onPostExecute(Boolean result) {
            // We have the media
            try {
                ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver);
            } catch (Exception e) {
                log.debug("Receiver was closed on cancel");
            }

            if (!(localId.contains(ConstantKeys.AVATAR))) {
                for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) {
                    if (AppUtils.getlistOfDownload().get(i).equals(localId)) {
                        AppUtils.getlistOfDownload().remove(i);
                    }
                }

                DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId,
                        100);

                Intent intent = new Intent();
                intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH);
                intent.putExtra(ConstantKeys.LOCALID, localId);
                ctx.sendBroadcast(intent);
            }

            if (object != null) {
                ((ProgressDialog) object).dismiss();
            }

            // Now the only container could be the avatar in edit screen
            if (container != null) {
                if (imageDownloaded != null) {
                    container.setImageBitmap(imageDownloaded);
                } else {
                    deleteFiles();
                    imageDownloaded = decodeSampledBitmapFromResource(ctx.getResources(),
                            R.drawable.ic_error_loading, 200, 200);
                    container.setImageBitmap(imageDownloaded);
                    Toast.makeText(ctx.getApplicationContext(),
                            ctx.getApplicationContext().getText(R.string.donwload_fail), Toast.LENGTH_SHORT)
                            .show();
                }
            } else {
                showMedia(localId, ctx, (ProgressDialog) object);
            }

        }

        private void deleteFiles() {
            File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG);
            File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP);
            if (file1.exists()) {
                file1.delete();
            }
            if (file2.exists()) {
                file2.delete();
            }
        }

    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.kalianey.oxapp.service.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();//  w w  w.  j  a  va 2s.co m
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);
    Log.d("Notif received", messageType.toString());

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM
         * will be extended in the future with new message types, just ignore
         * any message types you're not interested in, or that you don't
         * recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // Is this our message?? Better be if you're going to act on it!
            if (MainActivity.PROJECT_NUMBER.equals(extras.getString(EXTRA_SENDER))) {
                // Process message and then post a notification of the received message.
                String type = extras.getString(EXTRA_TYPE);
                String message = extras.getString(EXTRA_MESSAGE);
                String dataString = extras.getString("extra");

                //Build a conv to send to MessageView
                ModelConversation conversation = new ModelConversation();
                try {
                    JSONObject dataObj = new JSONObject(dataString); //{"senderId":3,"conversationId":2,"displayName":"Veda","recipientId":"1","message":"test again"}
                    conversation.setId(dataObj.getString("conversationId"));
                    conversation.setName(dataObj.getString("displayName"));
                    conversation.setPreviewText(message);
                    conversation.setOpponentId(dataObj.getString("senderId"));
                    conversation.setInitiatorId(dataObj.getString("recipientId"));

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                //Send notification
                String alert = "New message: " + message;
                sendNotification(context, alert);

                //Send to MessageFragment
                Intent broadcastIntent = new Intent();
                Bundle mBundle = new Bundle();
                mBundle.putSerializable("convObj", conversation);
                broadcastIntent.setAction("GCM_RECEIVED_ACTION");
                broadcastIntent.putExtra("conversation", mBundle);
                broadcastIntent.putExtra("gcm", message);
                context.sendBroadcast(broadcastIntent);

            }

            Log.i(LOG_TAG, "Received: " + extras.toString());
        }
    }
}

From source file:org.vshgap.android.NotificationsController.java

private void setBadge(final Context context, final int count) {
    notificationsQueue.postRunnable(new Runnable() {
        @Override//from  ww w  .  ja  va 2s  .  com
        public void run() {
            if (lastBadgeCount == count) {
                return;
            }
            lastBadgeCount = count;
            try {
                ContentValues cv = new ContentValues();
                //cv.put("tag", "org.vshgap.messenger/org.vshgap.ui.LaunchActivity");
                cv.put("tag", context.getPackageName() + "/org.vshgap.ui.LaunchActivity"); //Plus
                cv.put("count", count);
                context.getContentResolver()
                        .insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);
            } catch (Throwable e) {
                //ignore
            }
            try {
                String launcherClassName = getLauncherClassName(context);
                if (launcherClassName == null) {
                    return;
                }
                Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
                intent.putExtra("badge_count", count);
                intent.putExtra("badge_count_package_name", context.getPackageName());
                intent.putExtra("badge_count_class_name", launcherClassName);
                context.sendBroadcast(intent);
            } catch (Throwable e) {
                FileLog.e("tmessages", e);
            }
        }
    });
}

From source file:com.daiv.android.twitter.services.WidgetRefreshService.java

@Override
public void onHandleIntent(Intent intent) {
    // it is refreshing elsewhere, so don't start
    if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning
            || !MainActivity.canSwitch) {
        return;//from w w  w. j a  va2  s  .  c  om
    }
    WidgetRefreshService.isRunning = true;
    sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setTicker(getResources().getString(R.string.refreshing) + "...")
            .setContentTitle(getResources().getString(R.string.app_name))
            .setContentText(getResources().getString(R.string.refreshing_widget) + "...")
            .setProgress(100, 100, true)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark));

    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(6, mBuilder.build());

    Context context = getApplicationContext();

    AppSettings settings = AppSettings.getInstance(context);

    // if they have mobile data on and don't want to sync over mobile data
    if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
        return;
    }

    Twitter twitter = Utils.getTwitter(context, settings);

    HomeDataSource dataSource = HomeDataSource.getInstance(context);

    int currentAccount = sharedPrefs.getInt("current_account", 1);

    List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>();

    boolean foundStatus = false;

    Paging paging = new Paging(1, 200);

    long[] lastId;
    long id;
    try {
        lastId = dataSource.getLastIds(currentAccount);
        id = lastId[0];
    } catch (Exception e) {
        WidgetRefreshService.isRunning = false;
        return;
    }

    paging.setSinceId(id);

    for (int i = 0; i < settings.maxTweetsRefresh; i++) {
        try {
            if (!foundStatus) {
                paging.setPage(i + 1);
                List<Status> list = twitter.getHomeTimeline(paging);
                statuses.addAll(list);

                if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) {
                    Log.v("Test_inserting", "found status");
                    foundStatus = true;
                } else {
                    Log.v("Test_inserting", "haven't found status");
                    foundStatus = false;
                }
            }
        } catch (Exception e) {
            // the page doesn't exist
            foundStatus = true;
        } catch (OutOfMemoryError o) {
            // don't know why...
        }
    }

    Log.v("Test_pull", "got statuses, new = " + statuses.size());

    // hash set to remove duplicates I guess
    HashSet hs = new HashSet();
    hs.addAll(statuses);
    statuses.clear();
    statuses.addAll(hs);

    Log.v("Test_inserting", "tweets after hashset: " + statuses.size());

    lastId = dataSource.getLastIds(currentAccount);

    int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId);

    if (inserted > 0 && statuses.size() > 0) {
        sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit();
    }

    if (settings.preCacheImages) {
        startService(new Intent(this, PreCacheService.class));
    }

    context.sendBroadcast(new Intent("com.daiv.android.Test.UPDATE_WIDGET"));
    getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null);
    sharedPrefs.edit().putBoolean("refresh_me", true).commit();

    mNotificationManager.cancel(6);

    WidgetRefreshService.isRunning = false;
}

From source file:com.klinker.android.twitter.services.WidgetRefreshService.java

@Override
public void onHandleIntent(Intent intent) {
    // it is refreshing elsewhere, so don't start
    if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning
            || !MainActivity.canSwitch) {
        return;//from  w  w w . ja  va2 s  . co  m
    }
    WidgetRefreshService.isRunning = true;
    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setTicker(getResources().getString(R.string.refreshing) + "...")
            .setContentTitle(getResources().getString(R.string.app_name))
            .setContentText(getResources().getString(R.string.refreshing_widget) + "...")
            .setProgress(100, 100, true)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark));

    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(6, mBuilder.build());

    Context context = getApplicationContext();

    AppSettings settings = AppSettings.getInstance(context);

    // if they have mobile data on and don't want to sync over mobile data
    if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
        return;
    }

    Twitter twitter = Utils.getTwitter(context, settings);

    HomeDataSource dataSource = HomeDataSource.getInstance(context);

    int currentAccount = sharedPrefs.getInt("current_account", 1);

    List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>();

    boolean foundStatus = false;

    Paging paging = new Paging(1, 200);

    long[] lastId;
    long id;
    try {
        lastId = dataSource.getLastIds(currentAccount);
        id = lastId[0];
    } catch (Exception e) {
        WidgetRefreshService.isRunning = false;
        return;
    }

    paging.setSinceId(id);

    for (int i = 0; i < settings.maxTweetsRefresh; i++) {
        try {
            if (!foundStatus) {
                paging.setPage(i + 1);
                List<Status> list = twitter.getHomeTimeline(paging);
                statuses.addAll(list);

                if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) {
                    Log.v("talon_inserting", "found status");
                    foundStatus = true;
                } else {
                    Log.v("talon_inserting", "haven't found status");
                    foundStatus = false;
                }
            }
        } catch (Exception e) {
            // the page doesn't exist
            foundStatus = true;
        } catch (OutOfMemoryError o) {
            // don't know why...
        }
    }

    Log.v("talon_pull", "got statuses, new = " + statuses.size());

    // hash set to remove duplicates I guess
    HashSet hs = new HashSet();
    hs.addAll(statuses);
    statuses.clear();
    statuses.addAll(hs);

    Log.v("talon_inserting", "tweets after hashset: " + statuses.size());

    lastId = dataSource.getLastIds(currentAccount);

    int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId);

    if (inserted > 0 && statuses.size() > 0) {
        sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit();
    }

    if (settings.preCacheImages) {
        startService(new Intent(this, PreCacheService.class));
    }

    context.sendBroadcast(new Intent("com.klinker.android.talon.UPDATE_WIDGET"));
    getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null);
    sharedPrefs.edit().putBoolean("refresh_me", true).commit();

    mNotificationManager.cancel(6);

    WidgetRefreshService.isRunning = false;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Deletes a application desktop shortcut icon.
 *
 * Note://  w w  w . j  av a2 s .  c  o  m
 *  Manual way.
 *
 *  This method need two additional permissions in the application:
 *
 * <code>
 *  <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
 * </code>
 *
 * @param context   The application context.
 * @param appClass  Shortcut's  activity class.
 */
public static void application_shortcutRemove_method2(Context context, Class appClass, String appName) {
    Intent intent = new Intent();
    String oldShortcutUri = "#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;package="
            + appClass.getPackage().getName() + ";component=" + appClass.getPackage().getName() + "/."
            + appClass.getSimpleName() + ";end";
    try {
        Intent altShortcutIntent = Intent.parseUri(oldShortcutUri, 0);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, altShortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
        //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } catch (URISyntaxException e) {
    }
    intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    context.sendBroadcast(intent);
}

From source file:com.moez.QKSMS.mmssms.Transaction.java

private String fetchRnrSe(String authToken, Context context) throws ExecutionException, InterruptedException {
    JsonObject userInfo = Ion.with(context).load("https://www.google.com/voice/request/user")
            .setHeader("Authorization", "GoogleLogin auth=" + authToken).asJsonObject().get();

    String rnrse = userInfo.get("r").getAsString();

    try {/*from  w  w w .j a v  a 2  s . com*/
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        String number = tm.getLine1Number();
        if (number != null) {
            JsonObject phones = userInfo.getAsJsonObject("phones");
            for (Map.Entry<String, JsonElement> entry : phones.entrySet()) {
                JsonObject phone = entry.getValue().getAsJsonObject();
                if (!PhoneNumberUtils.compare(number, phone.get("phoneNumber").getAsString()))
                    continue;
                if (!phone.get("smsEnabled").getAsBoolean())
                    break;

                Ion.with(context).load("https://www.google.com/voice/settings/editForwardingSms/")
                        .setHeader("Authorization", "GoogleLogin auth=" + authToken)
                        .setBodyParameter("phoneId", entry.getKey()).setBodyParameter("enabled", "0")
                        .setBodyParameter("_rnr_se", rnrse).asJsonObject();
                break;
            }
        }
    } catch (Exception e) {

    }

    // broadcast so you can save it to your shared prefs or something so that it doesn't need to be retrieved every time
    Intent intent = new Intent(VOICE_TOKEN);
    intent.putExtra("_rnr_se", rnrse);
    context.sendBroadcast(intent);

    return rnrse;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Allows to install a new icon for the application.
 *
 * This method need two additional permissions in the application:
 *
 * <code>//w w w .j a v a 2 s  . c  om
 *  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 * </code>
 *
 * @param context       The application context.
 * @param appMain       The application main class
 * @param appName       The application name
 * @param appIcon       The bitmap of the application icon. Can be null. If null, the
 *                      appIconResId must be provided.
 * @param appIconResId  Specify this only if no bitmap is set in the call to this method.
 */
public static void application_shortcutAdd(Context context, Class appMain, String appName, Bitmap appIcon,
        int appIconResId, boolean removeCurrent) {

    // Intent launcher of the application
    Intent shortcutIntent = new Intent("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.setClass(context, appMain);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    //Intent to add the new application icon.
    //
    // Decorate the shortcut
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);

    if (appIcon != null) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, appIcon);
    } else if (appIconResId != 0) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(context.getApplicationContext(), appIconResId));
    }

    // Inform launcher to create shortcut
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}

From source file:com.mk4droid.IMC_Services.DatabaseHandler.java

/**
 *   Download and update the local table of Issues. 
 *   //w w  w.  ja va  2s . c  om
 * @param CurrLong  Download center position longitude
 * @param CurrLat   Download center position latitude
 * @param distance  Range around center position to download
 * @param IssuesNo  Max number of issues to download
 * @return downloaded bytes number 
 */
public int addUpdIssues(double CurrLong, double CurrLat, int distance, int IssuesNo, Context ctx) {

    // Make borders of Long and Lat based on distance 
    double x0up = (CurrLong + (distance * 0.0115) / 1000);
    double x0down = (CurrLong - (distance * 0.0115) / 1000);

    double y0up = (CurrLat + (distance * 0.0090) / 1000);
    double y0down = (CurrLat - (distance * 0.0090) / 1000);

    // Download
    String response = Download_Data.Download_Issues(x0down, x0up, y0down, y0up, IssuesNo);

    int response_BytesLength = response.getBytes().length;

    if (response == null || response_BytesLength == 0)
        return 0;

    if (!db.isOpen())
        db = this.getWritableDatabase();

    // Delete *
    db.execSQL("DELETE FROM " + TABLE_Issues);

    // Insert
    try {
        JSONArray jArrIssues = new JSONArray(response);

        int NIssues = jArrIssues.length();

        //--------- Create Helpers for Local db -----------------
        final InsertHelper iHelpI = new InsertHelper(db, TABLE_Issues);

        int c1 = iHelpI.getColumnIndex(KEY_IssueID);
        int c2 = iHelpI.getColumnIndex(KEY_Title);
        int c3 = iHelpI.getColumnIndex(KEY_CatID);
        int c4 = iHelpI.getColumnIndex(KEY_Lat);
        int c5 = iHelpI.getColumnIndex(KEY_Long);

        int c6 = iHelpI.getColumnIndex(KEY_Description);
        int c7 = iHelpI.getColumnIndex(KEY_Photo);
        int c8 = iHelpI.getColumnIndex(KEY_Address);
        int c9 = iHelpI.getColumnIndex(KEY_Votes);

        int c10 = iHelpI.getColumnIndex(KEY_CurrStat);
        int c11 = iHelpI.getColumnIndex(KEY_Reported);
        int c12 = iHelpI.getColumnIndex(KEY_Ack);
        int c13 = iHelpI.getColumnIndex(KEY_Closed);

        int c14 = iHelpI.getColumnIndex(KEY_UserID);
        int c15 = iHelpI.getColumnIndex(KEY_Ordering);

        int c16 = iHelpI.getColumnIndex(KEY_Params);
        int c17 = iHelpI.getColumnIndex(KEY_State);
        int c18 = iHelpI.getColumnIndex(KEY_Lang);
        int c19 = iHelpI.getColumnIndex(KEY_Hits);
        int c20 = iHelpI.getColumnIndex(KEY_Username);

        try {
            db.beginTransaction();

            Log.e("UPD", "Issues");

            for (int i = 0; i < NIssues; i++) {

                float prog = 67 + 16 * ((float) (i + 1)) / ((float) NIssues);

                ctx.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("progressval", prog));

                int IssueID = jArrIssues.getJSONArray(i).getInt(0); // "id"
                String IssueTitle = jArrIssues.getJSONArray(i).getString(1).trim(); // "title"

                int CatID = jArrIssues.getJSONArray(i).getInt(2); // "catid"
                double Latitude = jArrIssues.getJSONArray(i).getDouble(3);// "latitude"
                double Longitude = jArrIssues.getJSONArray(i).getDouble(4);// "longitude"

                String Description = jArrIssues.getJSONArray(i).getString(5).trim(); // "description"
                String Photo = jArrIssues.getJSONArray(i).getString(6); // "photo"
                String Address = jArrIssues.getJSONArray(i).getString(7).trim(); // "address"
                int votes = jArrIssues.getJSONArray(i).getInt(8); // "votes"

                int Currentstatus = jArrIssues.getJSONArray(i).getInt(9); // "currentstatus"
                String Reported = jArrIssues.getJSONArray(i).getString(10); // "reported"
                String Ack = jArrIssues.getJSONArray(i).getString(11); // "acknowledged"
                String Closed = jArrIssues.getJSONArray(i).getString(12); // "closed"

                int UserID = jArrIssues.getJSONArray(i).getInt(13); // "userid"
                int Ordering = jArrIssues.getJSONArray(i).getInt(14); // "ordering"
                String Params = jArrIssues.getJSONArray(i).getString(15); // "params"
                int State = jArrIssues.getJSONArray(i).getInt(16); // "state"
                String Language = jArrIssues.getJSONArray(i).getString(17); // "language"
                int Hits = jArrIssues.getJSONArray(i).getInt(18); // "hits"

                String Username = jArrIssues.getJSONArray(i).getString(23); // "name"

                // Local db
                Cursor cursorI = db.rawQuery("SELECT (" + KEY_IssueID + ") FROM " + TABLE_Issues + " WHERE "
                        + KEY_IssueID + "=" + Integer.toString(IssueID), null);

                if (cursorI.moveToFirst()) {
                    iHelpI.prepareForReplace();
                } else {
                    iHelpI.prepareForInsert();
                }
                cursorI.close();

                iHelpI.bind(c1, IssueID);
                iHelpI.bind(c2, IssueTitle);
                iHelpI.bind(c3, CatID);
                iHelpI.bind(c4, Latitude);
                iHelpI.bind(c5, Longitude);
                iHelpI.bind(c6, Description);
                iHelpI.bind(c7, Photo);
                iHelpI.bind(c8, Address);
                iHelpI.bind(c9, votes);
                iHelpI.bind(c10, Currentstatus);
                iHelpI.bind(c11, Reported);
                iHelpI.bind(c12, Ack);
                iHelpI.bind(c13, Closed);
                iHelpI.bind(c14, UserID);
                iHelpI.bind(c15, Ordering);
                iHelpI.bind(c16, Params);
                iHelpI.bind(c17, State);
                iHelpI.bind(c18, Language);
                iHelpI.bind(c19, Hits);
                iHelpI.bind(c20, Username);

                iHelpI.execute();
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        } // TRY OF TRANSACTION 
    } catch (JSONException e1) {
        e1.printStackTrace();
    } // TRY OF JSONARRAY

    return response_BytesLength;
}