- Android App Defaults: A Guide to Android File Associations
- File Types and Apps on Android
- Setting, Changing File Associations on Your Android Device; The Native Way
- Setting and Changing File Associations on Your Android Device With Astro File Manager
- File Associations and Your Android Device
- How to Change the Default App to Open a File in Android
- Ashish Mundhra
- Change Default Application for File Types in Android Phone
- Step 1:
- Step 2:
- Step 3:
- That’s All, Folks!
- Read Next
- How to Get Desktop Mode For Websites in Chrome for Android Permanently
- How to Change Default PDF Viewer on Android
- 2 Best Ways to Change Default Ringtone App on Android
- How to Lock and Protect Specific Apps on Android
- A Review of CCleaner for Android Beta: Good But Not Good Enough
- Top 10 Apple Files Tips and Tricks to Use It like a Pro
- Gmail vs Gmail Go: Comparing the Lite App with the Main One
- How to Change APK File Names and Icons Quickly and Easily
- Did You Know
- Kotlin Android Extensions deprecated. Что делать? Инструкция по миграции
- Кратко о Kotlin Android Extensions
- Проблемы Kotlin Android Extensions
- Альтернативные способы
- View Binding от Google
- Начало работы с View Binding
- Использование в Activity
- Keddit — Part 3: Extension Functions, Android Extensions and more…
- Content
- Part 3: NewsFragment.kt: Extensions Function, Android Extensions and more…
- Create our NewsFragment.kt
- Extension Functions (Utility class?)
- Default Values in Parameters
- Commit
- Android Extensions
- Commit
- Delegated Properties
- Commit
- Conclusion
Android App Defaults: A Guide to Android File Associations
File Types and Apps on Android
Your Android smartphone is essentially a pocket computer. Just like its bigger counterpart it is able to deal with a large amount of files, and just like its big brother, these files can be associated with certain apps. As the Android Market is open, there are a large number of applications available that will pretty much do the same thing and can all be associated with a single file type. Luckily, file associations on Android can be managed, and here is how.
Setting, Changing File Associations on Your Android Device; The Native Way
Most files that you put on your Android device that are supported usually will have their native counterpart. An MP3 file, for instance, will play on the default music player and an .avi movie will be played with the default movie player. As the Android system does not have a default file manager installed, the problem with file associations does not arise that quickly. Most files are shown and selected within the app that manages them anyway. However, when third party software is installed that somehow manages files, such as Dropbox or any file manager app in the Android Market, the problem may exist.
When selecting a file through any of these mediums, the Android system will look for an app that can deal with the file. If there is only one app installed that can manage the file, the user will not be presented with any other options but that one. This is similar to how a desktop computer behaves. However, when the user decides to install an alternative to a default app, the Android phone will let you make a decision through a popup screen. Here all the apps are shown that can possibly be associated with that file type. It is also here where a user can make a certain app a default for that type of file. For Instance in the case of a photo taken with the Android camera:
- After a photo is taken there is a shortcut available to viewing photos, this will lead to the picture viewer app on your Android phone.
- When there is an alternative present, the user will be asked to choose which app to use to view the photos. At this stage the user will choose the preferred app.
- If the user does not check the option to make the choice a default, each time the process is repeated the question will pop up. However, if the checkmark is indeed checked, the Android platform will revert to the default each time.
As there are many apps in the Android Market, a user will often change between them. Changing a default is then needed. This can be done as follows, using the above-mentioned situation as an example:
- From your Android home screen select the menu button > Settings > Applications > Manage Applications > All Apps > Camera (this can be any applicable app).
- Here the option ‘Clear Defaults’ has to be chosen to indeed clear the default file association for that app.
- To set a new default, repeat the before-mentioned steps for setting a default.
Setting and Changing File Associations on Your Android Device With Astro File Manager
The above-mentioned procedure is the native way of dealing with file associations on Android and currently the only way to truly achieve application association in the system. However, there is an alternative, which can ease the process a bit. This has to be done with a third party application, in this case Astro File Manager. Although defaults can not be set in this app, Astro File Manager can alter extensions to not be mistaken by the wrong apps. A good example of wrong association would be when an APK will trigger a game emulator, whereas there is no association whatsoever. The following steps will give you the opportunity to better describe certain file types:
- Download Astro File Manager from the Android Market.
- Follow the following steps after opening the app: Press the Menu Button > More > Preferences > Under the ‘Data’ header select ‘Edit File Extensions’.
- A list with all known-by-Astro file extensions is shown. Select any file extension you want to select or modify an associated app with.
- The cube on the top-right of the screen will show the current icon, click on it to change. A list of all possible icons will show.
- In the two fields the Mime type and SubType can be changed. Change these descriptions to better describe file extensions.
The above method will be especially useful for apps when selected in the file manager itself but can also be useful to properly deal with file associations. As Astro is one of the most popular file managers in the market the built-in extension manager is an excellent way of making sure the right file extensions are at least properly interpreted by the associated app or apps.
File Associations and Your Android Device
Your Android device is much like an ordinary computer, and file associations are a part of this. It is important to know your way around assigning file types to certain apps as it is a bit of a hassle to reverse the process. The above guide should set you in the right direction. Use it to get the most out of your device and learn one of the lesser-known functions of your Android phone.
Источник
How to Change the Default App to Open a File in Android
Ashish Mundhra
02 Aug 2012
Just like in Windows, we have multiple software to open a particular file type, we have a number of apps in Android to take care of a single file type. For example, we can have multiple audio/video players installed on the Android device that can play all types of media files.
Google Play Store has a plethrora of applications to better open different media files. Be it a new app to make calls, your new web browser, a swift messaging app or a swanky music player — an Android user is always on the lookout for a new app to adorn his or her home screen.
Now, let’s say you use different apps to play videos and listening to music but you accidentally hit Set default and created default action to use a player to play all the media files.
When you choose an app to be the default application to open a particular file type, it will do so whenever any third-party app is trying to access that particular file type as part of the default settings.
Change Default Application for File Types in Android Phone
Listen up Android users, if you have set a mistakenly default app to open a particular file type and want to undo the action, here’s what to do.
Step 1:
Open Android Apps settings. Android Ice Cream Sandwich (ICS) users can open Settings > Apps while the former builds can open Settings > Application > Manage applications.
Different versions of Android may also show different names of the tabs mentioned above. So, whether you are stuck with Android Marshmallow or are more upbeat Android Nougat, these instructions may vary.
Step 2:
Now search for the app you want to change the default settings for and tap on the app settings to open the info page of that application.
Step 3:
Scroll down the page to find the button Clear defaults. If the app is a default app for any of the file type on your device, the button will be enabled, otherwise disabled. Simply tap on the button to clear all the files associated with the app.
That’s All, Folks!
Next time you try to open the same file type, you will get all the suggestions to choose from again. Just make sure you make the right decision this time.
Last updated on 31 Aug, 2018
The above article may contain affiliate links which help support Guiding Tech. However, it does not affect our editorial integrity. The content remains unbiased and authentic.
Read Next
How to Get Desktop Mode For Websites in Chrome for Android Permanently
Learn How to Get Desktop Mode For Websites in # Chrome for # Android Permanently.
How to Change Default PDF Viewer on Android
Are you having trouble opening the # PDF files on your # Android phone? Follow our guide to change the default # PDF viewer and everything is going to be okay.
2 Best Ways to Change Default Ringtone App on Android
Did you accidentally select Always while choosing a # ringtone picker app on your # Android? Find out how to reset or change the default # ringtone app on Android.
How to Lock and Protect Specific Apps on Android
Find Out How to Lock and Protect Specific Apps on # Android Instead of Locking the Entire Phone.
A Review of CCleaner for Android Beta: Good But Not Good Enough
A Review of # CCleaner for # Android Beta: Good But Not Good Enough.
Top 10 Apple Files Tips and Tricks to Use It like a Pro
# Apple Files is more than a basic file manager for # iOS devices. Read the post to find the more about the excellent file manager from # Apple.
Gmail vs Gmail Go: Comparing the Lite App with the Main One
Wondering how # Gmail Go differs from the main Gmail app? Here we compare the two Gmail apps from # Google.
How to Change APK File Names and Icons Quickly and Easily
Learn How to Change APK File Names and Icons Quickly and Easily With APK Editor.
Did You Know
The B612 app is named after the B-612 asteroid which appears in ‘The Little Prince’ novella.
Источник
Kotlin Android Extensions deprecated. Что делать? Инструкция по миграции
kotlinx.android.synthetic is no longer a recommended practice. Removing in favour of explicit findViewById
Кратко о Kotlin Android Extensions
Kotlin Android Extensions — это плагин для Kotlin, позволяющий восстанавливать view из Activities, Fragments, и Views без написания стандартного бойлерплэйт-кода типа findViewById.
Плагин генерирует дополнительный код, который позволяет получить доступ к view в виде XML, так же, как если бы вы имели дело с properties с именем id, который вы использовали при определении структуры.
Также он создаёт локальный кэш view. При первом использовании свойства, плагин выполнит стандартный findViewById. В последующем, view будет восстановлен из кэша, поэтому доступ к нему будет быстрее.
Если это всё так удобно, то зачем его сделали deprecated?
Проблемы Kotlin Android Extensions
Альтернативные способы
View Binding от Google
Итак, победителем в этом списке выглядит ViewBinding от Google (не путайте с DataBinding). Давайте кратко рассмотрим, что это такое.
View Binding — это инструмент, который позволяет проще писать код для взаимодействия с view. При включении View Binding в определенном модуле он генерирует binding классы для каждого файла разметки (layout) в модуле. Объект сгенерированного binding класса содержит ссылки на все view из файла разметки, для которых указан android:id
Главные преимущества View Binding — это Null safety и Type safety.
Начало работы с View Binding
Начать работать с ViewBinding достаточно просто. Нужно добавить опцию в build.gradle:
После этого можно уже использовать. Каждый сгенерированный binding класс содержит ссылку на корневой view разметки (root) и ссылки на все view, которые имеют id. Имя генерируемого класса формируется как «название файла разметки», переведенное в camel case + «Binding». Например, для файла разметки result_profile.xml:
Будет сгенерирован класс ResultProfileBinding, содержащий 2 поля: TextView name и Button button.
Использование в Activity
Например у вас вот такой layout:
Результат работы ViewBinding:
Использовать viewBinding можно так:
И теперь, после того, как получили ссылки на view:
Если вы используете ViewBinding во фрагменте и держите ссылку на binding во фрагменте (а не только в методе onCreateView()) то не забывайте очищать ссылки в методе onDestroyView().
Это необходимо делать из-за жизненного цикла фрагмента и view:
Источник
Keddit — Part 3: Extension Functions, Android Extensions and more…
Juan Ignacio Saravia
Feb 17, 2016 · 7 min read
Content
Part 3: NewsFragment.kt: Extensions Function, Android Extensions and more…
In this Part we are going to see different Kotlin concepts that will help us to create our NewsFragment fragment. At the end of this story, you will learn:
- Extension Functions (Utility class?)
- Default Values in Parameters
- Android Extensions (bind view)
- Delegated Properties
Create our NewsFragment.kt
Let’s create our NewsFragment.kt file, it will be responsible to show the latests news from the Reddit API and we are going to use a RecyclerView to show the news.
In Java we would normally create a private field to store the RecyclerView locally and assign it when we are inflating the view. Trying to do the same in Kotlin, it’ll be like this:
This is a valid code and works but! it’s not a “Kotlin-ized” code so we are going to make it better. With this small piece of code we are going to incorporate some new concepts about the language:
- Extension Functions
- Default Values in Parameters
- Android Extensions (bind view)
- Delegated Properties
Extension Functions (Utility class?)
Extension functions allow us to extend the functionality of a class by adding new functions. The class doesn’t have to belongs to us (could it be a third party library) and also without requiring us to inherit the class.
This is really a super powerful feature! As we will be able to add new functions to existing classes and that’s what we are going to see right now with the ViewGroup class, a great trick that I found in this link by Antonio Leiva which I really encourage you to follow him on Twitter . Also we are going to understand how it works and how to consume it from Java.
As you know ViewGroup is a class from the Android SDK and in order to inflate it we have to do this:
But this is not really an intuitive way to do this. This should be something that the ViewGroup should be able to do like this:
It’s like the ViewGroup is able to inflate by itself! Awesome trick! But how to do that? Let’s create our first Extention Function:
I created a file called “ Extensions.kt” in the package “commons”. Checkout the code to see it. And the code is like this:
What we are doing here is to add a new method to ViewGroup (see how we add the ViewGroup with a dot before the “inflate” method name) but we are not modifying the ViewGroup class but adding a new function. This function will be internally a static method but you will be calling it from an instance of a class with the dot-notation, in this case: container.inflate(…) and not ViewGroup.inflate(). This is because the compiler will be creating a Util class for us. If you want to use this Extension Function from Java you will be using it in this way:
In the Kotlin world it’s in a more convenient way. Remember that we are adding the “?” mark just because in our example container could be a null object and this prevent us to get a NullPointerException.
The name of the Utility class will be the same as the file’s name plus “Kt” suffix or you can override it with an specific annotation:
More details about interoperability can be found here.
Coming back to our function:
Inside the code block it’s like you are writing code as it is a real new method of the class (like a regular method) that’s why you can access to the instance of the class with the “ this” keyword and access to the local variable “ context”.
Great! This is our first Extension Function and we know a lot more about this concept. Our code was updated in this way:
But here we are losing our attachToRoot parameter that we have in the inflater inflate method. Let’s add this to our code.
Default Values in Parameters
In Kotlin you are able to define default values in the parameters of a function (also in a class constructor but we are not going to see this now). So we are going to add a default value for the attachToRoot parameter:
In case you don’t specify the attachToRoot parameter it will take the default value, so you can call it in different ways:
Commit
Here you can see the commit of all these changes:
Android Extensions
This is the Kotlin alternative for the famous “ findViewById()” method (or other third party libraries to bind properties to an element of a view). Android Extensions add some convenient extension properties which allow us to access the elements of a view as it’s a property inside our Activity or Fragment with the proper view’s type already set.
Before to start changing our code let’s configure our project to enable Android Extensions. Modify the build.gradle file from our app module, apply the kotlin-android-extensions plugin and re-sync with gradle:
That’s all! Let’s replace the findViewById with this.
We will be able to access the news_list RecyclerView from our NewsFragment fragment. We are going to include an import to the synthetic properties generated by the plugin:
In this way you have access to all the elements in the layout that you choose in this import and use it directly from your code. In order to make sure the layout was already inflated, we are going to move our newsList assignment from onViewCreated() method to the onActivityCreated() where we are sure that the view (news_fragment) was already inflated.
We are going to be able to access news_list directly now:
Notice that we use news_lists and it’s a non-nullable object so we can use it in our code without the “?” question mark. This could be a problem if you run this code in another part of the Activity lifecycle and the view was not previously inflated, this will throw an exception at runtime.
Well our code is getting better! But wait! What if we want to have news_list locally to perform some other actions like setting the adapter?
For sure, you can still use the extended property news_list but for purpose of this tutorial we are going to see Delegated Properties which will help us to do so.
Commit
Delegated Properties
Delegated Properties are an excellent way to reuse common behavior that you may recurrently need for a property. In Kotlin you already have some common delegated properties defined in the language (also you can create your own). Here we are going to use this existing delegated property:
- Lazy properties: The value gets computed only upon first access.
This topic is really a world so here we are going to see just the lazy property and in other parts we are going to continue introducing another concepts about Delegated Properties.
This is a great delegated property that we are going to use to avoid initializing our newsList as a nullable object. With Lazy we are going to create it as a non-nullable property and will be executed just when you use it and just the first time.
Lazy will be initializing newsList with the value that you execute in the code block:
Here we can use the news_list synthetic property to avoid using findViewById and as the type can be inferred by the context we can also remove the property type:
The lazy block will be executed when we use it, in this case in the onActivityCreated() method:
Also we could move this initialization code inside the onActivityCreated into the lazy block in this way:
But as we are not calling the newsList in any place, the RecyclerView will raise an Exception as it doesn’t have a layout manager set. So we are going to leave it as we have it previously but we are going to change it in this way later.
Commit
Conclusion
Well we are ready to start developing the Adapter in the next story. Now we have a new Fragment created with Kotlin 🙂
Источник