Why does an image captured using camera intent gets rotated on some devices on Android?

Most phone cameras are landscape, meaning if you take the photo in portrait, the resulting photos will be rotated 90 degrees. In this case, the camera software should populate the Exif data with the orientation that the photo should be viewed in. Note that the below solution depends on the camera software/device manufacturer populating the … Read more

How to handle button clicks using the XML onClick within Fragments

I prefer using the following solution for handling onClick events. This works for Activity and Fragments as well. public class StartFragment extends Fragment implements OnClickListener{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_start, container, false); Button b = (Button) v.findViewById(R.id.StartButton); b.setOnClickListener(this); return v; } @Override public void onClick(View v) … Read more

Check orientation on Android phone

The current configuration, as used to determine which resources to retrieve, is available from the Resources’ Configuration object: getResources().getConfiguration().orientation; You can check for orientation by looking at its value: int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { // In landscape } else { // In portrait } More information can be found in the … Read more

Remove all unused resources from an android project

You can easily search for unused resources from Android Studio. Just press CtrlAltShifti and type “unused resources” (without quotes). That will execute lint. Super easy way to run lint commands (and other stuff from IDE). OR In Android Studio Menu > Refactor > Remove Unused Resources… Select the resources you want to remove. You can … Read more

Failed to install android-sdk: “java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema”

Just had this error, solved by downloading the Android SDK Command-line Tools (latest) on Android Studio, under Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools and re-running flutter doctor –android-licenses Finally, add the new tools to your PATH, in your .bashrc, .zshrc or similar, before the obsolete tools: export … Read more

Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536

None of the answers they gave you was exhaustive. The problem lies in the Multidex. You must add the library in the app gradle : implementation ‘com.android.support:multidex:1.0.3’ After, add in the defaultConfig of the app gradle : multiDexEnabled true Your Application must be of the Multidex type.. You must write it in the manifest : … Read more

Mipmap drawables for icons

There are two distinct uses of mipmaps: For launcher icons when building density specific APKs. Some developers build separate APKs for every density, to keep the APK size down. However some launchers (shipped with some devices, or available on the Play Store) use larger icon sizes than the standard 48dp. Launchers use getDrawableForDensity and scale … Read more

Why do most fields (class members) in Android tutorial start with `m`?

This notation comes from AOSP (Android Open Source Project) Code Style Guidelines for Contributors: Follow Field Naming Conventions Non-public, non-static field names start with m. Static field names start with s. Other fields start with a lower case letter. Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES. Note that the linked style guide is for code … Read more

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