The challenge of class must be met



  • Finding an example of implementation http://javarticles.com/2015/10/android-rate-app-example.html

    The essence of this example is: After the 3rd launches of the annex, a communication is issued requesting an assessment of the annex. I'm trying to do the same in my annex, but I can't understand how to link or trigger the implementation of these actions. Classes themselves, class Raiting

     public class Rating extends AppCompatActivity {
       int mlaunchCount = 3;
        public boolean bool;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        AppPreferences.getInstance(getApplicationContext()).incrementLaunchCount();
    
        showRateAppDialogIfNeeded();
        mlaunchCount++;
    }
    
    public void showRateAppDialogIfNeeded() {
        bool = AppPreferences.getInstance(getApplicationContext()).getAppRate();
        int i = AppPreferences.getInstance(getApplicationContext()).getLaunchCount();
        if ((bool) && (i == 3)) {
            createAppRatingDialog(getString(R.string.rate_app_title), getString(R.string.rate_app_message)).show();
        }
    }
    
    public AlertDialog createAppRatingDialog(String rateAppTitle, String rateAppMessage) {
        AlertDialog dialog = new AlertDialog.Builder(this).setPositiveButton(getString(R.string.dialog_app_rate), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
                openAppInPlayStore(getApplication());
                AppPreferences.getInstance(getApplicationContext()).setAppRate(false);
            }
        }).setNegativeButton(getString(R.string.dialog_your_feedback), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
                openFeedback(getApplication());
                AppPreferences.getInstance(getApplicationContext()).setAppRate(false);
            }
        }).setNeutralButton(getString(R.string.dialog_ask_later), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
                paramAnonymousDialogInterface.dismiss();
                AppPreferences.getInstance(getApplicationContext()).resetLaunchCount();
            }
        }).setMessage(rateAppMessage).setTitle(rateAppTitle).create();
        return dialog;
    }
    
    public static void openAppInPlayStore(Context paramContext) {
        paramContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("ссылка на приложение")));
    }
    
    public static void openFeedback(Context paramContext) {
        Intent localIntent = new Intent(Intent.ACTION_SEND);
        localIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"почта"});
        localIntent.putExtra(Intent.EXTRA_CC, "");
        String str = null;
        try {
            str = paramContext.getPackageManager().getPackageInfo(paramContext.getPackageName(), 0).versionName;
            localIntent.putExtra(Intent.EXTRA_SUBJECT, "Обратная связь");
            localIntent.putExtra(Intent.EXTRA_TEXT, "\n\n----------------------------------\n Device OS: Android \n Device OS version: " +
                    Build.VERSION.RELEASE + "\n App Version: " + str + "\n Device Brand: " + Build.BRAND +
                    "\n Device Model: " + Build.MODEL + "\n Device Manufacturer: " + Build.MANUFACTURER);
            localIntent.setType("message/rfc822");
            paramContext.startActivity(Intent.createChooser(localIntent, "Выберите e-mail пользователя :"));
        } catch (Exception e) {
            Log.d("Открыть отзыв", e.getMessage());
        }
    }
    

    }

    Class preference

      public class AppPreferences {
    private static AppPreferences sInstance;
    private SharedPreferences mPrefs;
    private static final String PREF_APP_RATE = "pref_app_rate";
    private static final String PREF_LAUNCH_COUNT = "pref_launch_count";

    private AppPreferences(Context paramContext) {
        this.mPrefs = paramContext.getSharedPreferences("app_prefs", 0);
    }
    
    public static AppPreferences getInstance(Context paramContext) {
        if (sInstance == null) {
            sInstance = new AppPreferences(paramContext);
        }
        return sInstance;
    }
    
    public boolean getAppRate() {
        return this.mPrefs.getBoolean(PREF_APP_RATE, true);
    }
    
    public void setAppRate(boolean paramBoolean) {
        SharedPreferences.Editor localEditor = this.mPrefs.edit();
        localEditor.putBoolean(PREF_APP_RATE, paramBoolean);
        localEditor.commit();
    }
    
    public int getLaunchCount() {
        return this.mPrefs.getInt(PREF_LAUNCH_COUNT, 0);
    }
    
    public void incrementLaunchCount() {
        int i = getLaunchCount();
        SharedPreferences.Editor localEditor = this.mPrefs.edit();
        localEditor.putInt(PREF_LAUNCH_COUNT, i + 1);
        localEditor.commit();
    }
    
    public void resetLaunchCount() {
        SharedPreferences.Editor localEditor = this.mPrefs.edit();
        localEditor.remove(PREF_LAUNCH_COUNT);
        localEditor.commit();
    }
    

    }

    And the main class where I want to be directly implemented

       public class MainActivity extends FragmentActivity {

    String name = "ПЕРВЫЙ ЭКРАН";
    private static final String TAG = "Fragment";
    SharedPreferences prefs = null;
    Intent intent;
    public Tracker mTracker;
    ViewPager pager;
    
    PagerAdapter pagerAdapter;
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    

    rating=new Rating();
    pager = (ViewPager) findViewById(R.id.pager);

        pagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
        pager.setAdapter(pagerAdapter);
        pager.setBackgroundResource(R.drawable.potehki_fon);
    
        pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
    
            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    pager.setBackgroundResource(R.drawable.potehki_fon);
                    mTracker.send(new HitBuilders.EventBuilder()
                            .setCategory("Action")
                            .setAction("ПОТЕШКИ ЭКРАН")
                            .build());
    
               }
    
                if (position == 1) {
                    pager.setBackgroundResource(R.drawable.music_background);
                    mTracker.send(new HitBuilders.EventBuilder()
                            .setCategory("Action")
                            .setAction("МУЗЫКАЛЬНЫЙ ЭКРНА")
                            .build());
    
                }
            }
    
            @Override
            public void onPageScrollStateChanged(int state) {
    
            }
        });
        ///загрузка первого экрана
        intent = new Intent(this, First_activity.class);
        prefs = getSharedPreferences("com.example.potehki.potehki", MODE_PRIVATE);
        AnalyticsApplication application = (AnalyticsApplication) getApplication();
        mTracker = application.getDefaultTracker();
    
    
        Log.i(TAG, "Setting screen name: " + name);
        mTracker.setScreenName("Потешки " + name);
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
    
    }
    



  • Similar https://github.com/kobakei/Android-RateThisApp

    Add it. MainActivity The following method:

    @Override
    protected void onStart() {
        super.onStart();
    
    Rating.onStart(this);
    Rating.showRateDialogIfNeeded(this);
    

    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2