In this tip we will see how to open an application setting screen from our application. In some application it might be possible that user has denied permission and you need to open application permission screen in order to get that particular permission, but this is not possible to in this case you need to redirect a user to application setting page and from that user can check for permission settings.
|
Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", activity.getPackageName(), null); intent.setData(uri); context.startActivity(intent); |
If you want to open a setting screen of other application, you need to replace activity.getPackageName() with a package name of application whose setting screen you need to open.
Sometimes we might need a functionality where we needs to concat two strings in xml only. So here are the different ways of how can we do it using databinding.
1. Using grave accent(`)
|
android:text="@{`Hello ` + user.firstName}" |
2. Using strings.xml
|
android:text="@{@string/location(user.city,user.state)}" |
and in your string.xml file
|
<string name="location">%1$s, %2$s</string> |
Continue Reading →
Lot of time we have a requirement to hide the view either runtime or from xml. We have seen View.GONE and View.INVISIBLE but very few people knows difference between those two constants.
First we will see what android document says about it.
INVISIBLE
This view is invisible, but it still takes up space for layout purposes.
GONE
This view is invisible, and it doesn’t take any space for layout purposes.
Continue Reading →
As we already know DatePickerDialog will be used to allow user to select date. It is useful when user wants to select Date of Birth or Start Date or End Date etc.
Here is the small code snippet of creating DatePickerDialog.
|
Calendar calendar = Calendar.getInstance(); int mYear = calendar.get(Calendar.YEAR); int mMonth = calendar.get(Calendar.MONTH); int mDay = calendar.get(Calendar.DAY_OF_MONTH); DatePickerDialog dpDialog = new DatePickerDialog(this, myDateListener, mYear, mMonth, mDay); dpDialog.show(); |
Continue Reading →
As we already know getResources().getColor() is deprecated since API level 23 from the official document
So what is the alternative of getColor()?
from API level 23, getColor is added in ContextCompat.
So just call
|
ContextCompat.getColor(context, R.color.color_id); |
from official document of ContextCompat.getColor()
Returns a color associated with a particular resource ID
Starting in M
, the returned color will be styled for the specified Context’s theme.