Example usage for android.database.sqlite SQLiteDatabase query

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

Introduction

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

Prototype

public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy,
        String having, String orderBy) 

Source Link

Document

Query the given table, returning a Cursor over the result set.

Usage

From source file:ru.valle.safetrade.SellActivity.java

private void loadState(final long id) {
    cancelAllTasks();/*from w  ww.  j  a va 2  s. c om*/
    loadStateTask = new AsyncTask<Void, Void, TradeRecord>() {
        @Override
        protected TradeRecord doInBackground(Void... params) {
            SQLiteDatabase db = DatabaseHelper.getInstance(SellActivity.this).getReadableDatabase();
            if (db != null) {
                Cursor cursor = db.query(DatabaseHelper.TABLE_HISTORY, null, BaseColumns._ID + "=?",
                        new String[] { String.valueOf(id) }, null, null, null);
                ArrayList<TradeRecord> tradeRecords = DatabaseHelper.readTradeRecords(cursor);
                return tradeRecords.isEmpty() ? null : tradeRecords.get(0);
            } else {
                return null;
            }
        }

        @Override
        protected void onPostExecute(final TradeRecord tradeRecord) {
            tradeInfo = tradeRecord;
            loadStateTask = null;
            rowId = tradeRecord.id;
            passwordView.setText(tradeRecord.password);
            intermediateCodeView.setText(tradeRecord.intermediateCode);
            if (confirmationCodeDecodingTask == null) {
                confirmationCodeView.setText(tradeRecord.confirmationCode);
            }
            if (TextUtils.isEmpty(tradeRecord.address)) {
                addressLabelView.setVisibility(View.GONE);
                addressView.setVisibility(View.GONE);
            } else {
                addressView.setText(tradeRecord.address);
                addressLabelView.setVisibility(View.VISIBLE);
                addressView.setVisibility(View.VISIBLE);
            }
            finalAddressView.setText(tradeRecord.destinationAddress);
            if (privateKeyDecodingTask == null) {
                privateKeyView.setText(tradeRecord.encryptedPrivateKey);
            }
            MainActivity.updateBalance(SellActivity.this, id, tradeInfo.address,
                    onAddressStateReceivedListener);
        }
    };
    if (Build.VERSION.SDK_INT >= 11) {
        loadStateTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        loadStateTask.execute();
    }
}

From source file:com.data.pack.ViewVideo.java

/**
 * Get raw data/*from  www  .  jav a 2 s  .  c  o  m*/
 * 
 * @param String
 * @return Cursor
 */
private Cursor getRawcursorsExcersiceEvents(String table) {
    SQLiteDatabase db = (placeData).getReadableDatabase();
    Cursor cursor = db.query(table,
            new String[] { "WorkoutId", "MainvideoUrl", "MainvideoName", "MainvideoRepeatCount", "PosterUrl",
                    "PosterName", "PosterRepeatCount", "RecoveryVideo", "RecoveryVideoName", "StopVideo",
                    "StopName", "StopRepeatCount", "OtherSidePosterVideo", "OtherSidePosterName",
                    "OtherSidePosterRepeatCount", "OtherSideVideo", "OtherSideName", "OtherSideRepeatCount",
                    "NextVideo", "NextVideoName", "NextRepeatCount", "CompletedVideo", "CompletedVideoName",
                    "CompletedRepeatCount", "MainVideoSize", "PosterSize", "OtherSideSize" },
            "WorkoutId = ?", new String[] { String.valueOf(workoutID) }, null, null, null);

    startManagingCursor(cursor);
    return cursor;
}

From source file:com.spoiledmilk.ibikecph.util.DB.java

public int getApiId(int id) {
    int ret = -1;
    SQLiteDatabase db = getWritableDatabase();
    if (db == null)
        return -1;
    String strFilter = "_id= ?";
    Cursor cur = db.query(TABLE_FAVORITES, new String[] { KEY_API_ID }, strFilter, new String[] { id + "" },
            null, null, null);/*from  w  w w  .  j ava2s .c  om*/
    if (cur != null && cur.moveToFirst()) {
        if (cur != null && !cur.isAfterLast()) {
            ret = cur.getInt(cur.getColumnIndex(KEY_API_ID));
        }
    }
    db.close();
    return ret;
}

From source file:com.maxwen.wallpaper.board.databases.Database.java

public Set<Wallpaper> getWallpapersNewer(long millis) {
    Set<Wallpaper> wallpapers = new HashSet<>();
    SQLiteDatabase db = this.getReadableDatabase();
    StringBuilder CONDITION = new StringBuilder();
    List<String> selection = new ArrayList<>();
    CONDITION.append(KEY_ADDED_ON + " > ?");
    selection.add(String.valueOf(millis));
    Cursor cursor = db.query(TABLE_WALLPAPERS, null, CONDITION.toString(),
            selection.toArray(new String[selection.size()]), null, null, KEY_CATEGORY);
    if (cursor.moveToFirst()) {
        do {/* ww w .ja v  a  2s  .com*/
            Wallpaper wallpaper = new Wallpaper(cursor.getInt(0), cursor.getString(1), cursor.getString(2),
                    cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getInt(6) == 1,
                    cursor.getLong(7));
            wallpapers.add(wallpaper);
        } while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return wallpapers;
}

From source file:com.maxwen.wallpaper.board.databases.Database.java

public Set<Wallpaper> getWallpapersNewer(long millis, Set<String> categories) {
    Set<Wallpaper> wallpapers = new HashSet<>();
    SQLiteDatabase db = this.getReadableDatabase();
    StringBuilder CONDITION = new StringBuilder();
    List<String> selection = new ArrayList<>();
    CONDITION.append(KEY_ADDED_ON + " > ?");
    selection.add(String.valueOf(millis));
    Cursor cursor = db.query(TABLE_WALLPAPERS, null, CONDITION.toString(),
            selection.toArray(new String[selection.size()]), null, null, KEY_CATEGORY);
    if (cursor.moveToFirst()) {
        do {/*from   w  ww . j a v a 2 s. co  m*/
            Wallpaper wallpaper = new Wallpaper(cursor.getInt(0), cursor.getString(1), cursor.getString(2),
                    cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getInt(6) == 1,
                    cursor.getLong(7));
            wallpapers.add(wallpaper);
            categories.add(cursor.getString(5));
        } while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return wallpapers;
}

From source file:org.opendatakit.common.android.provider.impl.FormsProviderImpl.java

@Override
public Cursor query(Uri uri, String[] projection, String where, String[] whereArgs, String sortOrder) {
    List<String> segments = uri.getPathSegments();

    if (segments.size() < 1 || segments.size() > 2) {
        throw new IllegalArgumentException("Unknown URI (incorrect number of segments!) " + uri);
    }/*from www.  ja va2 s . co m*/

    String appName = segments.get(0);
    ODKFileUtils.verifyExternalStorageAvailability();
    ODKFileUtils.assertDirectoryStructure(appName);
    WebLogger log = WebLogger.getLogger(appName);

    String uriFormId = ((segments.size() == 2) ? segments.get(1) : null);
    boolean isNumericId = StringUtils.isNumeric(uriFormId);

    // Modify the where clause to account for the presence of
    // a form id. Accept either:
    // (1) numeric _ID value
    // (2) string FORM_ID value.
    String whereId;
    String[] whereIdArgs;

    if (uriFormId == null) {
        whereId = where;
        whereIdArgs = whereArgs;
    } else {
        if (TextUtils.isEmpty(where)) {
            whereId = (isNumericId ? FormsColumns._ID : FormsColumns.FORM_ID) + "=?";
            whereIdArgs = new String[1];
            whereIdArgs[0] = uriFormId;
        } else {
            whereId = (isNumericId ? FormsColumns._ID : FormsColumns.FORM_ID) + "=? AND (" + where + ")";
            whereIdArgs = new String[whereArgs.length + 1];
            whereIdArgs[0] = uriFormId;
            for (int i = 0; i < whereArgs.length; ++i) {
                whereIdArgs[i + 1] = whereArgs[i];
            }
        }
    }

    // Get the database and run the query
    SQLiteDatabase db = null;
    boolean success = false;
    Cursor c = null;
    try {
        db = DatabaseFactory.get().getDatabase(getContext(), appName);
        c = db.query(DatabaseConstants.FORMS_TABLE_NAME, projection, whereId, whereIdArgs, null, null,
                sortOrder);
        success = true;
    } catch (Exception e) {
        log.w(t, "Unable to query database for appName: " + appName);
        return null;
    } finally {
        if (!success && db != null) {
            db.close();
        }
    }

    if (c == null) {
        log.w(t, "Unable to query database for appName: " + appName);
        return null;
    }
    // Tell the cursor what uri to watch, so it knows when its source data
    // changes
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}

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

private boolean isFavorite() {
    SQLiteDatabase sqLiteDatabase = new MedicationsFavoritesSQLiteHelper(mContext).getReadableDatabase();

    String[] queryColumns = { MedicationsFavoritesSQLiteHelper.COLUMN_NAME,
            MedicationsFavoritesSQLiteHelper.COLUMN_MANUFACTURER };
    Cursor cursor = sqLiteDatabase.query(MedicationsFavoritesSQLiteHelper.TABLE, queryColumns,
            MedicationsFavoritesSQLiteHelper.COLUMN_NAME + " = " + mTools.sqe(medicationName) + " AND "
                    + MedicationsFavoritesSQLiteHelper.COLUMN_MANUFACTURER + " = "
                    + mTools.sqe(medicationManufacturer),
            null, null, null, null);/*from  w  ww .  ja  v a2 s  .c  o  m*/

    int count = cursor.getCount();

    cursor.close();
    sqLiteDatabase.close();

    return (count != 0);
}

From source file:org.lastmilehealth.collect.android.tasks.BluetoothService.java

private void instancesProcessing() {
    //fill db with new values
    String dbpath = Collect.TMP_PATH + "/instances.db";
    SQLiteDatabase db = SQLiteDatabase.openDatabase(dbpath, null, SQLiteDatabase.OPEN_READONLY);
    Cursor cursor = db.query(InstanceProvider.INSTANCES_TABLE_NAME, null, null, null, null, null, null);
    Log.d("~", "cursor.getCount(): " + cursor.getCount());

    cursor.moveToPosition(-1);//from   www. j a  v a2  s .  c  o m
    while (cursor.moveToNext()) {
        String newInstanceName = cursor
                .getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.DISPLAY_NAME));
        String instanceFilePath = cursor
                .getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.INSTANCE_FILE_PATH));
        String newFilePath;

        if (new File(instanceFilePath).exists()) { //instance with this path already exist, rare case but not impossible
            newFilePath = getInstanceFilePath(instanceFilePath, 1);
            Log.d(TAG, "instance already exists, new path: " + newFilePath);

            String num = newFilePath.substring(newFilePath.lastIndexOf("(") + 1, newFilePath.lastIndexOf(")"));
            newInstanceName += "(" + num + ")";
            //Log.d(TAG, "newInstanceName: "+newInstanceName);

            final String fromName = instanceFilePath.substring(instanceFilePath.lastIndexOf("instances/") + 10);
            final String toName = newFilePath.substring(instanceFilePath.lastIndexOf("instances/") + 10);

            //raname file in tmp folder to prepare for copy direcory
            try {
                Log.d(TAG, "rename " + fromName + " to " + toName);
                org.apache.commons.io.FileUtils.copyFile(new File(Collect.TMP_PATH, fromName),
                        new File(Collect.TMP_PATH, toName));
                org.apache.commons.io.FileUtils.deleteQuietly(new File(Collect.TMP_PATH, fromName));
            } catch (Exception e) {
            }
        } else {
            newFilePath = new File(Collect.INSTANCES_PATH,
                    instanceFilePath.substring(instanceFilePath.lastIndexOf("/"))).getAbsolutePath();
            Log.d(TAG, "not exist, new path " + newFilePath);
        }

        String submissionUri = null;
        if (!cursor.isNull(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.SUBMISSION_URI))) {
            submissionUri = cursor
                    .getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.SUBMISSION_URI));
        }

        //add to db with new name, it it was duplicated
        ContentValues values = new ContentValues();
        values.put(InstanceProviderAPI.InstanceColumns.DISPLAY_NAME, newInstanceName);
        values.put(InstanceProviderAPI.InstanceColumns.SUBMISSION_URI, submissionUri);
        values.put(InstanceProviderAPI.InstanceColumns.INSTANCE_FILE_PATH, newFilePath);
        values.put(InstanceProviderAPI.InstanceColumns.JR_FORM_ID,
                cursor.getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.JR_FORM_ID)));
        values.put(InstanceProviderAPI.InstanceColumns.JR_VERSION,
                cursor.getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.JR_VERSION)));
        values.put(InstanceProviderAPI.InstanceColumns.STATUS,
                cursor.getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.STATUS)));
        values.put(InstanceProviderAPI.InstanceColumns.CAN_EDIT_WHEN_COMPLETE, cursor
                .getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.CAN_EDIT_WHEN_COMPLETE)));

        Log.d(TAG, "insert new instance record: " + newInstanceName + " with path :" + newFilePath);
        Collect.getInstance().getContentResolver().insert(InstanceProviderAPI.InstanceColumns.CONTENT_URI,
                values);
    }
    cursor.close();
    db.close();

    //copy directory after deleting metadata, clear all temporary data
    org.apache.commons.io.FileUtils.deleteQuietly(new File(Collect.TMP_PATH, "instances.db"));
    org.apache.commons.io.FileUtils.deleteQuietly(new File(Collect.ZIP_PATH));
    try {
        org.apache.commons.io.FileUtils.copyDirectory(new File(Collect.TMP_PATH),
                new File(Collect.INSTANCES_PATH));
        org.apache.commons.io.FileUtils.deleteDirectory(new File(Collect.TMP_PATH));
    } catch (Exception e) {
    }
}

From source file:com.triarc.sync.SyncAdapter.java

@SuppressLint("NewApi")
private JSONObject getVersions(SyncType type, SyncTypeCollection collection, MutableBoolean hasUpdates) {
    JSONObject changeSet = new JSONObject();
    JSONArray entityVersions = new JSONArray();
    SQLiteDatabase openDatabase = null;
    Cursor query = null;/*from  ww  w.j  a  v a2  s. c  o m*/
    try {
        changeSet.put("entityVersions", entityVersions);
        openDatabase = openDatabase(collection);

        query = openDatabase.query(type.getName(),
                new String[] { "_id", "_timestamp", "__internalTimestamp", "__state" }, null, null, null, null,
                "__internalTimestamp ASC");
        while (query.moveToNext()) {
            syncResult.stats.numEntries++;
            JSONObject jsonObject = new JSONObject();

            int fieldType = query.getType(0);
            String id = query.getString(0);
            String queryId = this.getQueryId(fieldType, id);

            jsonObject.put("id", id);
            jsonObject.put("timestamp", query.getLong(1));
            jsonObject.put("clientTimestamp", query.getLong(2));
            int state = query.getInt(3);
            if (state != UNCHANGED) {
                hasUpdates.setValue(true);
            }
            if (state == ADDED || state == UPDATED) {
                appendEntity(type, openDatabase, jsonObject, queryId);
            }
            jsonObject.put("state", state);
            entityVersions.put(jsonObject);
        }
    } catch (Exception e) {
        syncResult.stats.numIoExceptions++;
        syncResult.stats.numSkippedEntries++;
        syncResult.databaseError = true;
        e.printStackTrace();
        sendLogs();
    } finally {
        if (query != null)
            query.close();
        if (openDatabase != null && openDatabase.isOpen())
            closeDb(collection.getName());
    }
    return changeSet;
}

From source file:com.develop.autorus.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Fabric.with(this, new Crashlytics());
    super.onCreate(savedInstanceState);
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

    AnalyticsApplication application = (AnalyticsApplication) getApplication();
    mTracker = application.getDefaultTracker();
    mTracker.setScreenName("Main activity");
    mTracker.send(new HitBuilders.ScreenViewBuilder().build());

    if (pref.getBoolean("notificationIsActive", true)) {
        Intent checkIntent = new Intent(getApplicationContext(), MonitoringWork.class);
        Boolean alrarmIsActive = false;
        if (PendingIntent.getService(getApplicationContext(), 0, checkIntent,
                PendingIntent.FLAG_NO_CREATE) != null)
            alrarmIsActive = true;/* www.  java2 s  . c o m*/
        am = (AlarmManager) getSystemService(ALARM_SERVICE);

        if (!alrarmIsActive) {
            Intent serviceIntent = new Intent(getApplicationContext(), MonitoringWork.class);
            PendingIntent pIntent = PendingIntent.getService(getApplicationContext(), 0, serviceIntent, 0);

            int period = pref.getInt("numberOfActiveMonitors", 0) * 180000;

            if (period != 0)
                am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period,
                        period, pIntent);
        }
    }

    /*ForEasyDelete
            
    //Danger! Auchtung! ?, !!!
    String base64EncodedPublicKey =
        "<your license key here>";//?   . !!! ? ,    
    // github ?  .         ?!!!
            
    mHelper = new IabHelper(this, base64EncodedPublicKey);
            
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
        if (!result.isSuccess()) {
            Log.d(TAG, "In-app Billing setup failed: " +
                    result);
        } else {
            Log.d(TAG, "In-app Billing is set up OK");
        }
    }
    });
    */

    //Service inapp
    Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    intent.setPackage("com.android.vending");
    blnBind = bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);

    String themeName = pref.getString("theme", "1");

    if (themeName.equals("1")) {
        setTheme(R.style.AppTheme);
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window statusBar = getWindow();
            statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor));
        }
    } else if (themeName.equals("2")) {
        setTheme(R.style.AppTheme2);
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window statusBar = getWindow();
            statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor2));
        }
    }
    ThemeManager.init(this, 2, 0, null);

    if (isFirstLaunch) {
        SQLiteDatabase db = new DbHelper(this).getWritableDatabase();
        Cursor cursorMonitors = db.query("monitors", null, null, null, null, null, null);
        Boolean monitorsExist = cursorMonitors != null && cursorMonitors.getCount() > 0;
        db.close();

        if (getSupportFragmentManager().findFragmentByTag("MAIN") == null) {
            FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction();
            if (monitorsExist)
                mainFragment = SearchAndMonitorsFragment.newInstance(0);
            else
                mainFragment = SearchAndMonitorsFragment.newInstance(1);
            fTrans.add(R.id.container, mainFragment, "MAIN").commit();
        } else {
            mainFragment = (SearchAndMonitorsFragment) getSupportFragmentManager().findFragmentByTag("MAIN");
            if (getSupportFragmentManager().findFragmentByTag("Second") != null) {
                FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction();
                fTrans.remove(getSupportFragmentManager().findFragmentByTag("Second")).commit();
            }
            pref.edit().remove("NumberOfCallingFragment");
        }
    }

    backToast = Toast.makeText(this, "?   ? ", Toast.LENGTH_SHORT);
    setContentView(R.layout.main_activity);
    mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    mSnackBar = (SnackBar) findViewById(R.id.main_sn);
    setSupportActionBar(mToolbar);

    addMonitorButton = (Button) findViewById(R.id.toolbar_add_monitor_button);

    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_drawer);
    mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);

    Thread threadAvito = new Thread(new Runnable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        public void run() {
            Document doc;
            SharedPreferences sPref;
            try {
                String packageName = getApplicationContext().getPackageName();
                doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + packageName).userAgent(
                        "Mozilla/5.0 (Windows; U; WindowsNT 5.1; ru-RU; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                        .timeout(12000).get();
                //"")

                PackageManager packageManager;
                PackageInfo packageInfo;
                packageManager = getPackageManager();

                packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
                Element mainElems = doc.select(
                        "#body-content > div > div > div.main-content > div.details-wrapper.apps-secondary-color > div > div.details-section-contents > div:nth-child(4) > div.content")
                        .first();

                if (!packageInfo.versionName.equals(mainElems.text())) {
                    sPref = getPreferences(MODE_PRIVATE);
                    SharedPreferences.Editor ed = sPref.edit();
                    ed.putBoolean(SAVED_TEXT_WITH_VERSION, false);
                    ed.commit();
                } else {
                    sPref = getPreferences(MODE_PRIVATE);
                    SharedPreferences.Editor ed = sPref.edit();
                    ed.putBoolean(SAVED_TEXT_WITH_VERSION, true);
                    ed.commit();

                }
                //SharedPreferences sPrefRemind;
                //sPrefRemind = getPreferences(MODE_PRIVATE);
                //sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit();
            } catch (HttpStatusException e) {
                return;
            } catch (IOException e) {
                return;
            } catch (PackageManager.NameNotFoundException e) {

                e.printStackTrace();
            }
        }
    });

    SharedPreferences sPrefVersion;
    sPrefVersion = getPreferences(MODE_PRIVATE);
    Boolean isNewVersion;
    isNewVersion = sPrefVersion.getBoolean(SAVED_TEXT_WITH_VERSION, true);

    threadAvito.start();
    boolean remind = true;
    if (!isNewVersion) {
        Log.d("affa", "isNewVersion= " + isNewVersion);
        SharedPreferences sPref12;
        sPref12 = getPreferences(MODE_PRIVATE);
        String isNewVersion12;

        PackageManager packageManager;
        PackageInfo packageInfo;
        packageManager = getPackageManager();

        try {
            packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
            isNewVersion12 = sPref12.getString("OldVersionName", packageInfo.versionName);

            if (!isNewVersion12.equals(packageInfo.versionName)) {
                SharedPreferences sPref;
                sPref = getPreferences(MODE_PRIVATE);
                SharedPreferences.Editor ed = sPref.edit();
                ed.putBoolean(SAVED_TEXT_WITH_VERSION, false);
                ed.commit();

                SharedPreferences sPrefRemind;
                sPrefRemind = getPreferences(MODE_PRIVATE);
                sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit();
            } else
                remind = false;

            SharedPreferences sPrefRemind;
            sPrefRemind = getPreferences(MODE_PRIVATE);
            sPrefRemind.edit().putString("OldVersionName", packageInfo.versionName).commit();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        SharedPreferences sPrefRemind;
        sPrefRemind = getPreferences(MODE_PRIVATE);
        Boolean dontRemind;
        dontRemind = sPrefRemind.getBoolean(DO_NOT_REMIND, false);
        Log.d("affa", "dontRemind= " + dontRemind.toString());
        Log.d("affa", "remind= " + remind);
        Log.d("affa", "44444444444444444444444= ");
        if ((!dontRemind) && (!remind)) {
            Log.d("affa", "5555555555555555555555555= ");
            SimpleDialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    super.onPositiveActionClicked(fragment);
                    String packageName = getApplicationContext().getPackageName();
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
                    startActivity(intent);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                }

                @Override
                public void onNeutralActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                    SharedPreferences sPrefRemind;
                    sPrefRemind = getPreferences(MODE_PRIVATE);
                    sPrefRemind.edit().putBoolean(DO_NOT_REMIND, true).commit();
                }
            };

            builder.message(
                    "  ??   ? ? ?")
                    .title(" !").positiveAction("")
                    .negativeAction("").neutralAction("? ");
            DialogFragment fragment = DialogFragment.newInstance(builder);
            fragment.show(getSupportFragmentManager(), null);
        }
    }
}