Automatically accept all SDK licences

UPDATE 2021 This should be the accepted answer as its easy and upto date AndroidSDK can finally accept licenses. Go to Android\sdk\tools\bin yes | sdkmanager –licenses EDIT: as pointed out in the comments by @MoOx, on macOS, you can do yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager –licenses as pointed out in the comments by @pho, @mikebridge and … Read more

How to implement onBackPressed() in Fragments?

I solved in this way override onBackPressed in the Activity. All the FragmentTransaction are addToBackStack before commit: @Override public void onBackPressed() { int count = getSupportFragmentManager().getBackStackEntryCount(); if (count == 0) { super.onBackPressed(); //additional code } else { getSupportFragmentManager().popBackStack(); } }

How to use SharedPreferences in Android to store, fetch and edit values [closed]

To obtain shared preferences, use the following method In your activity: SharedPreferences prefs = this.getSharedPreferences( “com.example.app”, Context.MODE_PRIVATE); To read preferences: String dateTimeKey = “com.example.app.datetime”; // use a default value using new Date() long l = prefs.getLong(dateTimeKey, new Date().getTime()); To edit and save preferences Date dt = getSomeDate(); prefs.edit().putLong(dateTimeKey, dt.getTime()).apply(); The android sdk’s sample directory contains … Read more

How to set the text color of TextView in code?

You should use: holder.text.setTextColor(Color.RED); You can use various functions from the Color class to get the same effect of course. Color.parseColor (Manual) (like LEX uses) text.setTextColor(Color.parseColor(“#FFFFFF”)); Color.rgb and Color.argb (Manual rgb) (Manual argb) (like Ganapathy uses) holder.text.setTextColor(Color.rgb(200,0,0)); holder.text.setTextColor(Color.argb(0,200,0,0)); And of course, if you want to define your color in an XML file, you can do … Read more

Why fragments, and when to use fragments instead of activities?

#1 & #2 what are the purposes of using a fragment & what are the advantages and disadvantages of using fragments compared to using activities/views/layouts? Fragments are Android’s solution to creating reusable user interfaces. You can achieve some of the same things using activities and layouts (for example by using includes). However; fragments are wired … Read more

How to make an Android Spinner with initial text “Select One”?

What you can do is decorate your SpinnerAdapter with one that presents a ‘Select Option…’ View initially for the Spinner to display with nothing selected. Here is a working example tested for Android 2.3, and 4.0 (it uses nothing in the compatibility library, so it should be fine for awhile) Since it’s a decorator, it … Read more

What is an Android PendingIntent?

A PendingIntent is a token that you give to a foreign application (e.g. NotificationManager, AlarmManager, Home Screen AppWidgetManager, or other 3rd party applications), which allows the foreign application to use your application’s permissions to execute a predefined piece of code. If you give the foreign application an Intent, it will execute your Intent with its … Read more

Install an apk file from command prompt?

You can use the code below to install application from command line adb install example.apk this apk is installed in the internal memory of current opened emulator. adb install -s example.apk this apk is installed in the sd-card of current opened emulator. You can also install an apk to specific device in connected device list … Read more

How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?

You need to subclass ViewPager. onTouchEvent has a lot of good things in it that you don’t want to change like allowing child views to get touches. onInterceptTouchEvent is what you want to change. If you look at the code for ViewPager, you’ll see the comment: /* * This method JUST determines whether we want … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)