Example usage for android.database.sqlite SQLiteDatabase insert

List of usage examples for android.database.sqlite SQLiteDatabase insert

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase insert.

Prototype

public long insert(String table, String nullColumnHack, ContentValues values) 

Source Link

Document

Convenience method for inserting a row into the database.

Usage

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public boolean addBlockedDomain(String domain, String exfiltrated) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_APP_INFO, domain.trim());
    values.put(KEY_PERMISSIONS, exfiltrated);
    int id = (int) db.insert(TABLE_BLOCKED_DOMAINS, null, values);
    return id >= 0;
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) {
    Context context = getContext();
    if (context == null) {
        return null;
    }/*from   w  w  w.j av a  2  s.c o m*/
    if (values == null) {
        throw new IllegalArgumentException("Invalid ContentValues: must not be null");
    }
    if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)
            || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) {
        throw new IllegalArgumentException("Initial values must contain component name: " + values);
    }

    // Check to make sure the component name is valid
    ComponentName componentName = ComponentName
            .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME));
    if (componentName == null) {
        throw new IllegalArgumentException("Invalid component name: "
                + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME));
    }
    // Make sure they are using the short string format
    values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString());

    // Ensure the app inserting the artwork is either Muzei or the same app as the source
    String callingPackageName = getCallingPackage();
    if (!context.getPackageName().equals(callingPackageName)
            && !TextUtils.equals(callingPackageName, componentName.getPackageName())) {
        throw new IllegalArgumentException("Calling package name (" + callingPackageName
                + ") must match the source's package name (" + componentName.getPackageName() + ")");
    }

    if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) {
        String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        Intent viewIntent;
        try {
            if (!TextUtils.isEmpty(viewIntentString)) {
                // Make sure it is a valid Intent URI
                viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME);
                // Make sure we can construct a PendingIntent for the Intent
                PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            }
        } catch (URISyntaxException e) {
            Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e);
            values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        } catch (RuntimeException e) {
            // This is actually meant to catch a FileUriExposedException, but you can't
            // have catch statements for exceptions that don't exist at your minSdkVersion
            Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e);
            values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        }
    }

    // Ensure the related source has been added to the database.
    // This should be true in 99.9% of cases, but the insert will fail if this isn't true
    Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID },
            MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?",
            new String[] { componentName.flattenToShortString() }, null);
    if (sourceQuery == null || sourceQuery.getCount() == 0) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME,
                componentName.flattenToShortString());
        insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues);
    }
    if (sourceQuery != null) {
        sourceQuery.close();
    }

    values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis());
    final SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI,
            values);
    // If the insert succeeded, the row ID exists.
    if (rowId > 0) {
        // Creates a URI with the artwork ID pattern and the new row ID appended to it.
        final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId);
        File artwork = getCacheFileForArtworkUri(artworkUri);
        if (artwork != null && artwork.exists()) {
            // The image already exists so we'll notifyChange() to say the new artwork is ready
            // Otherwise, this will be called when the file is written with openFile()
            // using this Uri and the actual artwork is written successfully
            notifyChange(artworkUri);
        }
        return artworkUri;
    }
    // If the insert didn't succeed, then the rowID is <= 0
    throw new SQLException("Failed to insert row into " + uri);
}

From source file:com.fan3cn.fishrecorder.ContentFragment.java

/**
 * ??//from  w w  w . j  a v a 2 s  . c o  m
 * @param view
 */
private void handleCompanyEvent(final View view) {
    Button addButton = (Button) view.findViewById(R.id.button_add);
    addButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText nameET = (EditText) view.findViewById(R.id.editText_com_name);
            EditText phoneET = (EditText) view.findViewById(R.id.editText_com_phone);
            EditText faxET = (EditText) view.findViewById(R.id.editText_com_fax);
            EditText emailET = (EditText) view.findViewById(R.id.editText_com_email);
            EditText addressET = (EditText) view.findViewById(R.id.editText_com_addr);
            CheckBox ckBox = (CheckBox) view.findViewById(R.id.checkBox_is_default);

            int isDefault = ckBox.isChecked() ? 1 : 0;

            String name = nameET.getText().toString();
            String phone = phoneET.getText().toString();
            String fax = faxET.getText().toString();
            String email = emailET.getText().toString();
            String address = addressET.getText().toString();

            if (name.isEmpty() || phone.isEmpty() || fax.isEmpty() || email.isEmpty() || address.isEmpty()) {
                new AlertDialog.Builder(getActivity()).setTitle("??").setPositiveButton("", null)
                        .setMessage("?").show();
                return;
            }
            SQLiteDatabase db = MainActivity.getDbHelper().getWritableDatabase();

            Cursor cursor = db.query(Constants.table.get(menuId), null, "is_default=?", new String[] { 1 + "" },
                    null, null, null);

            if (isDefault == 1 && cursor.getCount() > 0) {
                //?
                ContentValues cv1 = new ContentValues();
                cv1.put("is_default", 0);
                db.update(Constants.table.get(menuId), cv1, "is_default=?", new String[] { 1 + "" });
            }

            ContentValues cv = new ContentValues();
            cv.put("name", name);
            cv.put("tel", phone);
            cv.put("fax", fax);
            cv.put("email", email);
            cv.put("address", address);
            cv.put("is_default", isDefault);
            db.insert(Constants.table.get(menuId), null, cv);
            //??  
            db.close();

            Toast.makeText(getActivity(), "?!", Toast.LENGTH_SHORT).show();
        }
    });

    Button clearButton = (Button) view.findViewById(R.id.button_clear);

    clearButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            EditText nameET = (EditText) view.findViewById(R.id.editText_com_name);
            EditText phoneET = (EditText) view.findViewById(R.id.editText_com_phone);
            EditText faxET = (EditText) view.findViewById(R.id.editText_com_fax);
            EditText emailET = (EditText) view.findViewById(R.id.editText_com_email);
            EditText addressET = (EditText) view.findViewById(R.id.editText_com_addr);
            CheckBox ckBox = (CheckBox) view.findViewById(R.id.checkBox_is_default);

            nameET.setText("");
            phoneET.setText("");
            faxET.setText("");
            emailET.setText("");
            addressET.setText("");
            ckBox.setChecked(false);
        }
    });

}

From source file:org.totschnig.myexpenses.provider.TransactionDatabase.java

private void insertCurrencies(SQLiteDatabase db) {
    ContentValues initialValues = new ContentValues();
    for (CurrencyEnum currency : CurrencyEnum.values()) {
        initialValues.put(KEY_CODE, currency.name());
        db.insert(TABLE_CURRENCIES, null, initialValues);
    }//ww  w. j av a  2  s  . c o  m
}

From source file:net.smart_json_database.JSONDatabase.java

/**
 * Insert or update a property to db// w ww  .  j  a v  a 2s .co  m
 * 
 * @param key
 * @param value
 * @return 
 */
public long setProperty(String key, String value) {

    SQLiteDatabase db = dbHelper.getWritableDatabase();

    String checkKey = Util.DateToString(new Date());

    ContentValues values = new ContentValues();

    values.put("value", value);
    long i = -1;
    if (checkKey.equals(getPropterty(db, key, checkKey))) {
        values.put("key", key);
        i = db.insert(TABLE_Meta, null, values);
    } else {
        i = db.update(TABLE_Meta, values, "key = ?", new String[] { key });
    }

    db.close();

    return i;
}

From source file:com.germainz.identiconizer.xposed.XposedMod.java

@Override
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
    if ("com.android.providers.contacts".equals(lpparam.packageName)) {
        try {/*from www.j a  v a2s  .co  m*/
            findAndHookMethod("com.android.providers.contacts.DataRowHandlerForStructuredName",
                    lpparam.classLoader, "insert", SQLiteDatabase.class,
                    "com.android.providers.contacts.TransactionContext", long.class, ContentValues.class,
                    new XC_MethodHook() {

                        @Override
                        protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param)
                                throws Throwable {
                            CONFIG.reload();
                            if (CONFIG.isEnabled()) {
                                ContentValues values = (ContentValues) param.args[3];
                                String name = values.getAsString(
                                        ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);

                                if (!TextUtils.isEmpty(name)) {
                                    long rawContactId = ((Number) param.args[2]).longValue();
                                    SQLiteDatabase db = (SQLiteDatabase) param.args[0];
                                    Identicon identicon = IdenticonFactory.makeIdenticon(
                                            CONFIG.getIdenticonStyle(), CONFIG.getIdenticonSize(),
                                            CONFIG.getIdenticonBgColor());

                                    ContentValues identiconValues = new ContentValues();
                                    identiconValues.put("mimetype_id", 10);
                                    identiconValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
                                    identiconValues.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
                                            identicon.generateIdenticonByteArray(name));
                                    identiconValues.put(ContactsContract.Data.IS_PRIMARY, 1);
                                    identiconValues.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);

                                    db.insert(ContactsContract.Contacts.Data.CONTENT_DIRECTORY, null,
                                            identiconValues);
                                }
                            }
                        }
                    });
        } catch (Throwable e) {
            Context systemContext = (Context) getStaticObjectField(
                    findClass("android.app.ActivityThread", null), "mSystemContext");
            if (systemContext == null) {
                Object activityThread = callStaticMethod(findClass("android.app.ActivityThread", null),
                        "currentActivityThread");
                systemContext = (Context) callMethod(activityThread, "getSystemContext");
            }

            Context contactsProviderContext = systemContext
                    .createPackageContext("com.android.providers.contacts", Context.CONTEXT_IGNORE_SECURITY);
            Context identiconizerContext = systemContext.createPackageContext(Config.PACKAGE_NAME,
                    Context.CONTEXT_IGNORE_SECURITY);

            String contentText = identiconizerContext.getString(R.string.xposed_error_text);
            Notification notice = new NotificationCompat.Builder(contactsProviderContext)
                    .setSmallIcon(NOTIF_ICON_RES_ID)
                    .setContentTitle(identiconizerContext.getString(R.string.xposed_error_title))
                    .setContentText(contentText)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)).build();
            NotificationManager nm = (NotificationManager) contactsProviderContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            nm.notify(1, notice);
        }
    }

    if (Config.PACKAGE_NAME.equals(lpparam.packageName)) {
        findAndHookMethod(Config.PACKAGE_NAME + ".Config", lpparam.classLoader, "isXposedModActive",
                XC_MethodReplacement.returnConstant(true));
    }
}

From source file:net.olejon.mdapp.DiseasesAndTreatmentsSearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Connected?
    if (!mTools.isDeviceConnected()) {
        mTools.showToast(getString(R.string.device_not_connected), 1);

        finish();//from  w w w  .jav a 2  s  .c  o  m

        return;
    }

    // Intent
    final Intent intent = getIntent();

    mSearchLanguage = intent.getStringExtra("language");

    final String searchString = intent.getStringExtra("string");

    // Layout
    setContentView(R.layout.activity_diseases_and_treatments_search);

    // Toolbar
    mToolbar = (Toolbar) findViewById(R.id.diseases_and_treatments_search_toolbar);
    mToolbar.setTitle(getString(R.string.diseases_and_treatments_search_search) + ": \"" + searchString + "\"");

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.diseases_and_treatments_search_toolbar_progressbar);
    mProgressBar.setVisibility(View.VISIBLE);

    // Spinner
    mSpinner = (Spinner) findViewById(R.id.diseases_and_treatments_search_spinner);

    ArrayAdapter<CharSequence> arrayAdapter;

    if (mSearchLanguage.equals("")) {
        arrayAdapter = ArrayAdapter.createFromResource(mContext,
                R.array.diseases_and_treatments_search_spinner_items_english,
                R.layout.activity_diseases_and_treatments_search_spinner_header);
    } else {
        arrayAdapter = ArrayAdapter.createFromResource(mContext,
                R.array.diseases_and_treatments_search_spinner_items_norwegian,
                R.layout.activity_diseases_and_treatments_search_spinner_header);
    }

    arrayAdapter.setDropDownViewResource(R.layout.activity_diseases_and_treatments_search_spinner_item);

    mSpinner.setAdapter(arrayAdapter);
    mSpinner.setOnItemSelectedListener(this);

    // Refresh
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(
            R.id.diseases_and_treatments_search_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green,
            R.color.accent_purple, R.color.accent_orange);

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            search(mSearchLanguage, searchString, false);
        }
    });

    // Recycler view
    mRecyclerView = (RecyclerView) findViewById(R.id.diseases_and_treatments_search_cards);

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(new DiseasesAndTreatmentsSearchAdapter(mContext, new JSONArray(), ""));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));

    // Search
    search(mSearchLanguage, searchString, true);

    // Correct
    RequestQueue requestQueue = Volley.newRequestQueue(mContext);

    try {
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
                getString(R.string.project_website_uri) + "api/1/correct/?search="
                        + URLEncoder.encode(searchString, "utf-8"),
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            final String correctSearchString = response.getString("correct");

                            if (!correctSearchString.equals("")) {
                                new MaterialDialog.Builder(mContext)
                                        .title(getString(R.string.correct_dialog_title))
                                        .content(Html.fromHtml(getString(R.string.correct_dialog_message)
                                                + ":<br><br><b>" + correctSearchString + "</b>"))
                                        .positiveText(getString(R.string.correct_dialog_positive_button))
                                        .negativeText(getString(R.string.correct_dialog_negative_button))
                                        .callback(new MaterialDialog.ButtonCallback() {
                                            @Override
                                            public void onPositive(MaterialDialog dialog) {
                                                ContentValues contentValues = new ContentValues();
                                                contentValues.put(
                                                        DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING,
                                                        correctSearchString);

                                                SQLiteDatabase sqLiteDatabase = new DiseasesAndTreatmentsSQLiteHelper(
                                                        mContext).getWritableDatabase();

                                                sqLiteDatabase.delete(DiseasesAndTreatmentsSQLiteHelper.TABLE,
                                                        DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING + " = "
                                                                + mTools.sqe(searchString) + " COLLATE NOCASE",
                                                        null);
                                                sqLiteDatabase.insert(DiseasesAndTreatmentsSQLiteHelper.TABLE,
                                                        null, contentValues);

                                                sqLiteDatabase.close();

                                                mToolbar.setTitle(getString(
                                                        R.string.diseases_and_treatments_search_search) + ": \""
                                                        + correctSearchString + "\"");

                                                mProgressBar.setVisibility(View.VISIBLE);

                                                search(mSearchLanguage, correctSearchString, true);
                                            }
                                        }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue)
                                        .negativeColorRes(R.color.black).show();
                            }
                        } catch (Exception e) {
                            Log.e("DiseasesAndTreatments", Log.getStackTraceString(e));
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("DiseasesAndTreatments", error.toString());
                    }
                });

        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        requestQueue.add(jsonObjectRequest);
    } catch (Exception e) {
        Log.e("DiseasesAndTreatments", Log.getStackTraceString(e));
    }
}

From source file:net.potterpcs.recipebook.RecipeData.java

public int insertRecipe(Recipe r) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        int ret = -1;
        try {/*from w  w  w  .ja v  a  2 s . c  om*/
            ContentValues values = createRecipeForInsert(r);
            long rowid = db.insert(RECIPES_TABLE, null, values);

            if (r.ingredients != null) {
                for (String ing : r.ingredients) {
                    ContentValues cvi = createIngredientsCV(rowid, ing);
                    db.insertWithOnConflict(INGREDIENTS_TABLE, null, cvi, SQLiteDatabase.CONFLICT_IGNORE);
                }
            }

            if (r.directions != null) {
                int step = 1;
                for (String dir : r.directions) {
                    ContentValues cdirs = createDirectionsCV(rowid, step, dir, r.directions_photos[step - 1]);
                    db.insertWithOnConflict(DIRECTIONS_TABLE, null, cdirs, SQLiteDatabase.CONFLICT_IGNORE);
                    step++;
                }
            }

            if (r.tags != null) {
                for (String tag : r.tags) {
                    ContentValues ctags = createTagsCV(rowid, tag);
                    db.insertWithOnConflict(TAGS_TABLE, null, ctags, SQLiteDatabase.CONFLICT_IGNORE);
                }
            }
            ret = (int) rowid;
        } finally {
            db.close();
        }
        return ret;
    }
}

From source file:com.citrus.sdk.database.DBHandler.java

public void addPayOption(JSONArray paymentArray) {
    SQLiteDatabase db = this.getWritableDatabase();
    for (int i = 0; i < paymentArray.length(); i++) {
        ContentValues loadValue = new ContentValues();
        try {//from  w w  w.  ja v a2  s .c o  m
            JSONObject payOption = paymentArray.getJSONObject(i);
            loadValue.put(MMID, payOption.getString(MMID));
            loadValue.put(SCHEME, payOption.getString(SCHEME));
            loadValue.put(EXPDATE, payOption.getString(EXPDATE));
            loadValue.put(NAME, payOption.getString(NAME));
            loadValue.put(OWNER, payOption.getString(OWNER));
            loadValue.put(BANK, payOption.getString(BANK));
            loadValue.put(NUMBER, payOption.getString(NUMBER));
            loadValue.put(TYPE, payOption.getString(TYPE).toUpperCase());
            loadValue.put(IMPS_REGISTERED, payOption.getString(IMPS_REGISTERED));
            loadValue.put(TOKEN_ID, payOption.getString(TOKEN_ID));
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        db.insert(PAYOPTION_TABLE, null, loadValue);

    }

}

From source file:br.liveo.ndrawer.ui.fragment.FragmentNotificationsfacebook.java

@Override
public void onCompleted(GraphResponse graphResponse) {

    int postreversecounter = 1;
    ContentValues cv1 = null, cv2 = null, cv3 = null, cv4 = null;
    String abc1 = null, abc2 = null, abc3 = null;

    Log.i("response", graphResponse.toString());

    JSONObject data1 = graphResponse.getJSONObject();
    try {//from ww  w. j  a va 2s  .c o m
        if (data1 != null) {
            JSONArray friends = data1.getJSONArray("data");

            // JSONObject pagingInfo = data1.getJSONObject("paging");
            // Log.i("response-paging",pagingInfo.toString());
            for (int i = 0; i < friends.length(); i++) {

                JSONObject currentFriend = friends.getJSONObject(i);
                Log.i("response1", currentFriend.toString());

                String abc = currentFriend.getString("message");
                String time = currentFriend.getString("created_time");
                // Notification notimessage=new Notification(abc);
                // Notification timestamp=new Notification(time);

                // data2.add(timestamp);
                // adapter2.notifyDataSetChanged();

                //DATE

                String year = time.substring(0, 4);
                String month = time.substring(5, 7);
                String dated = time.substring(8, 10);

                Integer imonth = Integer.parseInt(month);

                switch (imonth) {
                case 1:
                    month = "Jan";
                    break;
                case 2:
                    month = "Feb";
                    break;
                case 3:
                    month = "Mar";
                    break;
                case 4:
                    month = "Apr";
                    break;
                case 5:
                    month = "May";
                    break;
                case 6:
                    month = "June";
                    break;
                case 7:
                    month = "July";
                    break;
                case 8:
                    month = "Aug";
                    break;
                case 9:
                    month = "Sep";
                    break;
                case 10:
                    month = "Oct";
                    break;
                case 11:
                    month = "Nov";
                    break;
                case 12:
                    month = "Dec";
                    break;
                }

                String date = dated + " " + month + ", " + year;

                Log.i("date", date);

                Log.i("response year", year);

                Log.i("response year_m", month);

                Log.i("response year_d", date);

                //DATE END

                Log.i("response3", time);

                //TIme

                String meri = "PM";

                String utchh = time.substring(11, 13);
                String utcmm = time.substring(14, 16);

                Log.i("hh_h", utchh);
                Log.i("hh_m", utcmm);

                Integer iutchh = Integer.parseInt(utchh);
                iutchh = iutchh + 5;

                if (iutchh > 12) {
                    iutchh = iutchh - 12;
                    meri = "PM";
                } else {
                    iutchh = iutchh;
                    meri = "AM";
                }

                Integer iutcmm = Integer.parseInt(utcmm);
                iutcmm = iutcmm + 30;
                if (iutcmm > 59) {
                    iutcmm = iutcmm - 60;
                    iutchh = iutchh + 1;
                }

                String isthh = String.valueOf(iutchh);
                String istmm = String.valueOf(iutcmm);

                Log.i("time", isthh + " : " + istmm);

                String ftime = isthh + ":" + istmm + " " + meri;

                //TIME Ends

                //Toast.makeText(this, time, Toast.LENGTH_SHORT);

                //check for duplicate

                String[] col = new String[1];
                col[0] = NotificationSquliteOpenHelper.NOTIFICATION;
                // col[1]=NotificationSquliteOpenHelper.NOTIFICATION_DATE;
                // col[2]=NotificationSquliteOpenHelper.NOTIFICATION_TIME;

                String text = "text";

                int flag = 0;

                Cursor c = db.query(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, col, null, null, null,
                        null, null);
                while (c.moveToNext()) {
                    text = c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION));
                    //  String datee=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_DATE));
                    //   String timeee=c.getString(c.getColumnIndex(NotificationSquliteOpenHelper.NOTIFICATION_TIME));

                    // String

                    // Notification n1=new Notification(text);
                    //Log.i("text get", text);

                    if (text != null && text.contentEquals(abc)) {

                        flag = 1;
                    }

                    Log.i("text flag", String.valueOf(flag));
                    // postcount++;
                    //  Note nn1=new Note(text);
                    //  data2.add(n1);
                }

                if (postreversecounter == 2) {

                    if (abc.contentEquals(abc1)) {
                        flag = 1;
                    }

                } else if (postreversecounter == 3) {

                    if (abc.contentEquals(abc1) || abc.contentEquals(abc2)) {
                        flag = 1;
                    }

                } else if (postreversecounter == 4) {
                    if (abc.contentEquals(abc1) || abc.contentEquals(abc2) || abc.contentEquals(abc3)) {
                        flag = 1;
                    }

                }

                if (flag != 1)
                //
                {
                    // data2.add(notimessage);
                    // adapter2.notifyDataSetChanged();

                    ContentValues cv = new ContentValues();
                    cv.put(NotificationSquliteOpenHelper.NOTIFICATION, abc);
                    cv.put(NotificationSquliteOpenHelper.NOTIFICATION_DATE, date);
                    cv.put(NotificationSquliteOpenHelper.NOTIFICATION_TIME, ftime);
                    SQLiteDatabase db = helper.getWritableDatabase();
                    //getContentResolver().insert(Studentsquliteopenhelper.STUDENT_TABLE, cv);
                    db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv);

                    if (postreversecounter == 1) {

                        abc1 = abc;

                        cv1 = new ContentValues();
                        cv1.put(NotificationSquliteOpenHelper.NOTIFICATION, abc);
                        cv1.put(NotificationSquliteOpenHelper.NOTIFICATION_DATE, date);
                        cv1.put(NotificationSquliteOpenHelper.NOTIFICATION_TIME, ftime);

                        postreversecounter++;

                    }

                    //

                    //for 1st object

                    if (postreversecounter == 2) {

                        abc2 = abc;

                        cv2 = new ContentValues();
                        cv2.put(NotificationSquliteOpenHelper.NOTIFICATION, abc);
                        cv2.put(NotificationSquliteOpenHelper.NOTIFICATION_DATE, date);
                        cv2.put(NotificationSquliteOpenHelper.NOTIFICATION_TIME, ftime);

                        postreversecounter++;
                    }
                    //

                    //for 1st object

                    if (postreversecounter == 3) {

                        abc3 = abc;

                        cv3 = new ContentValues();
                        cv3.put(NotificationSquliteOpenHelper.NOTIFICATION, abc);
                        cv3.put(NotificationSquliteOpenHelper.NOTIFICATION_DATE, date);
                        cv3.put(NotificationSquliteOpenHelper.NOTIFICATION_TIME, ftime);

                        postreversecounter++;
                    }
                    //

                    //                        ContentValues cv2 = new ContentValues();
                    //                        cv2.put(NotificationSquliteOpenHelper.NOTIFICATION_DATE, date);
                    //                        db = helper.getWritableDatabase();
                    //                        //getContentResolver().insert(Studentsquliteopenhelper.STUDENT_TABLE, cv);
                    //                        db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv2);
                    //
                    //                        ContentValues cv3 = new ContentValues();
                    //                        cv3.put(NotificationSquliteOpenHelper.NOTIFICATION_TIME, ftime);
                    //                        db = helper.getWritableDatabase();
                    //                        //getContentResolver().insert(Studentsquliteopenhelper.STUDENT_TABLE, cv);
                    //                        db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv3);

                    Notification nn1 = new Notification(abc, date, ftime);
                    data2.add(nn1);
                    adapter2.notifyDataSetChanged();

                    // Note nnew=new Note(getnote);

                    //data.add(nnew);
                    //adapter2.notifyDataSetChanged();
                }

            }

        } else {
            Toast.makeText(getActivity(), "No internet Connection found", Toast.LENGTH_SHORT);
        }

        if (postreversecounter == 4) {
            // db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv3);
            // db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv2);
            // db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv1);
        } else if (postreversecounter == 3) {
            // db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv2);
            // db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv1);
        } else if (postreversecounter == 2) {
            //db.insert(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, null, cv1);
        }

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

}