How to add a link to a navigation drawer item?

Will

I'm trying to add a simple link to a Rate Theme item in the navigation drawer so when clicked users are brought to the Play Store listing of the application. I want to add it as a main navigation drawer item, right below Icon Request. How do I accomplish this?

https://www.dropbox.com/s/5dufwie8ejgygg2/2015-08-01%2010.28.50.png?dl=0

/*******************************************************************
 ************************* Drawer Clicks ***************************
 *******************************************************************/

private void setNavigationListener(NavigationView view){
    view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            closeDrawer();
            switch (menuItem.getItemId()) {
                case R.id.navigation_home:
                    menuItem.setChecked(true);
                    addFragment(new HomeFrag(), HomeFrag.FRAG_TAG, false, 0, getString(R.string.drawer_home));
                    return true;
                case R.id.navigation_apply:
                    menuItem.setChecked(true);
                    addFragment(new LauncherFrag(), LauncherFrag.FRAG_TAG, true, 1, getString(R.string.drawer_launcher));
                    return true;
                case R.id.navigation_wallpaper:
                    if (!NetworkUtil.getNetworkState(activity)) {
                        dialogConnection();
                    } else {
                        if (UtilCat.getValue() == null) {
                            addFragment(new RetryFrag(), RetryFrag.FRAG_TAG, false, 99, getString(R.string.retry));
                        } else {
                            menuItem.setChecked(true);
                            final Fragment walls = new WallpaperFrag();
                            final Bundle args = new Bundle();
                            mDataCat = UtilCat.getValue();
                            node = mDataCat.get(0);
                            args.putSerializable(WallpaperFrag.BUNDLE_TAG, node.wallpaperList);
                            walls.setArguments(args);
                            addFragment(walls, WallpaperFrag.FRAG_TAG, true, 2, getString(R.string.drawer_wallpaper));
                        }
                    }
                    return true;
                case R.id.navigation_icons:
                    menuItem.setChecked(true);
                    addFragment(new IconsFrag(), IconsFrag.FRAG_TAG, true, 3, getString(R.string.drawer_icons));
                    return true;
                case R.id.navigation_request:
                    menuItem.setChecked(true);
                    addFragment(new IconRequestFrag(), IconRequestFrag.FRAG_TAG, true, 4, getString(R.string.drawer_request));
                    return true;
                case R.id.navigation_sub_contact:
                    addFragment(new ContactFrag(), ContactFrag.FRAG_TAG, false, 99, getString(R.string.drawer_contact));
                    return true;


                case R.id.navigation_sub_changelog:
                    mCurrentSelectedPosition = 99;
                    AsyncTaskIconsNew aTask;
                    MaterialDialog dialog = new MaterialDialog.Builder(activity)
                            .title(R.string.changelog)
                            .customView(R.layout.dialog_changelog, false)
                            .positiveText(getResources().getString(R.string.close))
                            .theme(getDialogTheme())
                            .build();
                    WebView webView = (WebView) dialog.getCustomView().findViewById(R.id.webview);
                    webView.getSettings();
                    int theme = ApplyTheme.getConfigTheme(activity);
                    webView.setBackgroundColor(getResources().getColor(R.color.transparent));
                    if (theme == 0){
                        webView.loadUrl("file:///android_asset/changelog_light.html");
                    } else {
                        webView.loadUrl("file:///android_asset/changelog_dark.html");
                    }
                    webView.setWebViewClient(new WebViewClient() {
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            if (url != null) {
                                view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                                return true;
                            } else {
                                return false;
                            }
                        }
                    });
                    GridView gridView;
                    gridView=(GridView) dialog.getCustomView().findViewById(R.id.icon_grid);
                    gridView.setNumColumns(getResources().getInteger(R.integer.column_count_icon_dialog));
                    gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
                    aTask = new AsyncTaskIconsNew(gridView, dialog);
                    aTask.updateActivity(activity);
                    aTask.execute();
                    dialog.show();
                    return true;

                default:
                    return false;
            }
        }
    });
}

/************************ Setup UI *************************/
    setContentView(R.layout.activity_main);
    AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP).setScreenName(TAG);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    mActionBar = getSupportActionBar();
    if (mActionBar != null) {
        mActionBar.setHomeAsUpIndicator(R.drawable.app_ic_drawer_menu);
        mActionBar.setDisplayHomeAsUpEnabled(true);
    }

    setupPreLollipopStatusBar();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
    setNavigationListener(mNavigationView);

    mProgress = (ProgressBar) findViewById(R.id.base_progressSpinner);

    mFabHome = (FloatingActionButton) findViewById(R.id.fab_home);
    mFabRequest = (FloatingActionButton) findViewById(R.id.fab_request);
    mFabContact = (FloatingActionButton) findViewById(R.id.fab_contact);
    mCoordinator = (CoordinatorLayout) findViewById(R.id.main_content);
    mAppbar = (AppBarLayout) findViewById(R.id.appbar);

    mToolbarCollapse = false;

    activity = this;

    if (savedInstanceState == null) {
        initializeData();
    } else {
        //Not null repoduce last wallpaper state
        //Get data for Wallpaper and Icons fragments to save state on rotation
        node = (NodeCategory) savedInstanceState.get(KEY_LIST_DATA);
        mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
    }

    Intent intent = getIntent();
    int licensed = intent.getIntExtra("LICENSED",0);
    if (licensed == 1)
        Toast.makeText(MainActivity.this, getString(R.string.licensed), Toast.LENGTH_LONG).show();
hhyari
.
.
.
case R.id.rateApp:
                AppRater app = new AppRater();
                app.rateNow(YourActivity.this);
                return true;

Create the following classes:

AppRater class:

public class AppRater{

private static Market market = new GoogleMarket();

public static void rateNow(final Context context) {
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW, market.getMarketURI(context)));
        } catch (ActivityNotFoundException activityNotFoundException1) {
            Log.e(AppRater.class.getSimpleName(), "Market Intent not found");
        }
    }

GoogleMarket class

public class GoogleMarket implements Market {
    private static String marketLink = "market://details?id=";

    @Override
    public Uri getMarketURI(Context context) {
        return Uri.parse(marketLink + context.getPackageName().toString());
    }
}

Market class:

public interface Market {
    public Uri getMarketURI(Context context);
}

If your application is published on google play, it will get your app's id automatically and open the app on play store.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Add a item to a navigation drawer

From Dev

How to add action to a Navigation Drawer item?

From Dev

How to add Spinner as an item in Navigation Drawer

From Dev

How to add a collapsible menu item inside navigation drawer in android?

From Dev

How to add some space under the last item in a Navigation Drawer?

From Dev

How to add some space under the last item in a Navigation Drawer?

From Dev

Add image ABOVE item list in navigation drawer

From Dev

How to add Tabhost in Navigation Drawer

From Dev

How to add a SearchView into a navigation drawer?

From Dev

How to add tabhost with navigation drawer?

From Dev

How to add icons on navigation drawer?

From Dev

How to link each tabs to Navigation Drawer?

From Dev

How to link each tabs to Navigation Drawer?

From Dev

How to pass data to navigation drawer item?

From Dev

Navigation drawer: How to know the current selected item?

From Dev

How to hide a navigation drawer menu item programmatically?

From Dev

How to select item navigation drawer from fragment

From Dev

Navigation Drawer: How to change the colour of item category?

From Dev

How to add Navigation Drawer to all the activities in the application?

From Dev

How to add profile information in android navigation drawer?

From Dev

How to add icons to items in a navigation drawer

From Dev

How to add a group to navigation drawer programmatically

From Dev

How to add draggable icon with navigation drawer

From Dev

How to add an image header in navigation drawer layout

From Dev

How to add menu items runtime in Navigation Drawer?

From Dev

how to add a navigation drawer in an existing layout

From Dev

How to add checkbox to material navigation drawer?

From Dev

How to add icons to titles in navigation Drawer?

From Dev

How to add profile information in android navigation drawer?

Related Related

  1. 1

    Add a item to a navigation drawer

  2. 2

    How to add action to a Navigation Drawer item?

  3. 3

    How to add Spinner as an item in Navigation Drawer

  4. 4

    How to add a collapsible menu item inside navigation drawer in android?

  5. 5

    How to add some space under the last item in a Navigation Drawer?

  6. 6

    How to add some space under the last item in a Navigation Drawer?

  7. 7

    Add image ABOVE item list in navigation drawer

  8. 8

    How to add Tabhost in Navigation Drawer

  9. 9

    How to add a SearchView into a navigation drawer?

  10. 10

    How to add tabhost with navigation drawer?

  11. 11

    How to add icons on navigation drawer?

  12. 12

    How to link each tabs to Navigation Drawer?

  13. 13

    How to link each tabs to Navigation Drawer?

  14. 14

    How to pass data to navigation drawer item?

  15. 15

    Navigation drawer: How to know the current selected item?

  16. 16

    How to hide a navigation drawer menu item programmatically?

  17. 17

    How to select item navigation drawer from fragment

  18. 18

    Navigation Drawer: How to change the colour of item category?

  19. 19

    How to add Navigation Drawer to all the activities in the application?

  20. 20

    How to add profile information in android navigation drawer?

  21. 21

    How to add icons to items in a navigation drawer

  22. 22

    How to add a group to navigation drawer programmatically

  23. 23

    How to add draggable icon with navigation drawer

  24. 24

    How to add an image header in navigation drawer layout

  25. 25

    How to add menu items runtime in Navigation Drawer?

  26. 26

    how to add a navigation drawer in an existing layout

  27. 27

    How to add checkbox to material navigation drawer?

  28. 28

    How to add icons to titles in navigation Drawer?

  29. 29

    How to add profile information in android navigation drawer?

HotTag

Archive