Tag Archives: Android

Android solves the gliding problem of EditText

problem description

when presenting (and editing) multiple lines of text using EditText, slide up and down without feeling fluid or inertia.

solution

wraps EditText with ScrollView.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:fillViewport="true">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:gravity="top"
        android:inputType="textMultiLine" />

</ScrollView>

Differences between the assets directory in Android project and the purpose of resource

assets: will not generate the corresponding tag under r.java file, assets folder is not created by default need to create their own folder and resource folder with the same parent directory, using the AssetsManager class to access, stored here when running the packaging of resources will be entered into the program installation package.
resource : the tag will be generated under the r.java file. The resource here will determine what is used when running the packaging operation. The file resources that are not used will not be packaged into the installation package . The file using resource is called by the R class according to the path

Android:More than one file was found with OS independent path ‘res/values/values.xml

More than one file was found with OS independent path ‘res/values/values.xml
More than one file was found with OS independent path ‘res/values/values.xml

analysis question:
1. First, according to the error report diary: this is due to the same name of the resource file is repeated, so the system compilation time can not identify which file to load; 2. Then, follow the train of thought, go to the global search to see if your own resource file or the jar, aar or resource file used for guidance has more than one resource file with diary error; 3. After searching, it was found that multiple files with the same name did exist in the imported aar package:

4. So now that the cause of the problem has been identified, the problem is how to solve it.

According to the advice of most people on the Internet, there are mainly the following kinds:
1. Find the corresponding resource file and change the name (this method depends on the size of the project, the number of conflicting files, or only one or two resource files, find out and change the following, o; However, if there are too many conflicting files, this method is not recommended); 2. Exclude files or directories from APK, act on APK, and do not filter aar and jar contents:

...
android{
    packagingOptions {
        exclude 'res/values/values.xml'
        exclude 'libs/loginsdk1.0.4-release.aar/res/values/values.xml'
    }
}
...

exclude is the path of the file to be filtered. This method is straightforward, simple, and the method most people use.
3. Similar to method 2: packagingOptions USES pickFirst, matches to multiple identical files, and extracts only the first. APK only, files in AAR and JAR cannot be filtered.
for example:

...
android{
    packagingOptions {
//        pickFirst 'res/values/values.xml'
//        pickFirst 'AndroidManifest.xml'
    }
    }
    ...

4. However, when we are referenced by the three parties jar packages or aar resource file, can’t modify repeatedly named resource file, at the same time, although the same name, but the file content is different, several methods obviously cannot solve the problem, therefore, at this time, we can bold guess: since packagingOptions configuration items can filter files, extract, etc., will it be all right if we can be repeated by identifying the complete name of a resource file, and then let the system to extract, or, we can also make duplicate naming files to merge?And, along the way of thinking, I baidu about gradle configuration items packagingOptions instructions
gradle configuration items packagingOptions instructions
from this post, so he found a solution:
the merge, will match the files are added to the APK, contrary to some pickFirst, will merge all files
so, combine the duplicate files:

android{
    packagingOptions {
        merge 'res/values/values.xml'
        merge 'AndroidManifest.xml'
        merge 'res/drawable/login_bg.xml'
        merge 'R.txt'
        merge 'classes.jar'
    }
    }

finally, compile, pass.

:
sometimes encounter problems, according to the online most people encounter similar problems and offer you the train of thought, if not solve, can follow the same train of thought to further try, maybe problem solved, such as: from gradle configuration items packagingOptions use of filtering, extracting, if still can’t solve problems, you can follow the train of thought, guess packagingOptions whether there will be other use method, to try, maybe can solve problem. Of course, I don’t know if using this Merg will cause any other problems. I also welcome your advice. thank you

Solve the problem of available for offline mode in Android studio compilation

reprint please indicate the source:
http://blog.csdn.net/aa464971/article/details/68948650

anomaly full text

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
   > Could not resolve com.squareup.okhttp3:okhttp:3.5.0.
     Required by:
         retrofit-rxjava-okhttp:app:unspecified > com.squareup.retrofit2:retrofit:2.1.0
      > No cached version of com.squareup.okhttp3:okhttp:3.5.0 available for offline mode.

solution

screenshot is version 2.2

Settings – Build. Execution, Deployment – Gradle – uncheck the Offline Work, recompile.

Appium connecting to the ADB 5037 port of nocturnal simulator is occupied by itself

The reason for the error of

is that the adb. Exe in the
SDK platform is inconsistent with the adb version in the night god simulator, so just replace it.
replace adb. Exe in SDK with adb. Exe in nox, the nocturne simulator, and reconnect.
copies adb.exe from the night god simulator into appium and replaces
to connect again in the command window: enter adb connect 127.0.0.1:62001

Android has applied for permission and still prompts open failed: eacces (permission denied)

solution

people need to upload the latest file in Android10, declare and dynamically apply for permissions, but it still indicates that the file cannot be opened. To solve this problem, the following steps should be done:

  1. permissions that are requested in the Manifest file

< USES – permission android: name = “android. Permission. WRITE_EXTERNAL_STORAGE”/& gt;
< USES – permission android: name = “android. Permission. READ_INTERNAL_STORAGE”/& gt;

  1. dynamically applies for read file permissions (called in the activity)
private  final int REQUEST_EXTERNAL_STORAGE = 1;
private  String[] PERMISSIONS_STORAGE = {
        Manifest.permission.READ_EXTERNAL_STORAGE,
         Manifest.permission.WRITE_EXTERNAL_STORAGE };
public  void verifyStoragePermissions(Activity activity) {
    // Check if we have write permission
    int permission = ActivityCompat.checkSelfPermission(activity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permission != PackageManager.PERMISSION_GRANTED) {
        // We don't have permission so prompt the user
        ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,
                REQUEST_EXTERNAL_STORAGE);
    }
}
    The new Android10

  1. requires a property
  2. to be declared in the Application

< application
Android: requestLegacyExternalStorage = “true”/& gt;

at this point, you can really read the files in the system.

No value has been specified for this provider

The project on github has encountered a problem for the first time:

No value has been specified for this provider

remove Settings. Include “xxxapp” in gradle and then File-> Sync project with gradles

Settings. Gradle include “xxxapp” and then File-> Sync project with gradles

https://www.jianshu.com/p/25c57ba7421a

met Unable to resolve the dependency for ‘: app @ the debug/compileClasspath: Could not resolve com. Google. Android. The GMS: play – services – basement: [15.0.0, 16.0.0)

Android 10 open file exception open failed: eacces (permission denied) android:requestLegacyExternalStorage= “true“

in Android development, we generally use the following code to get the storage path, and the results are generally /storage/emulated/0

in AndroidManifest. Application node in the XML file with the android: requestLegacyExternalStorage = “true” attribute, as follows: </ p>

<application
    android:requestLegacyExternalStorage="true"

may be easy for developers, but for those who are new to android, it doesn’t use

now most mobile phones are Android version 10.0, when reading and writing files to the memory card, the problem of: open failed: EACCES (Permission denied) will occur. After adding the above one sentence of code to baidu, it has not been solved. The possible reason is that there is no dynamic access Permission added in the code snippet

dynamic read and write permission code:

final int REQUEST_EXTERNAL_STORAGE = 1;
if (ContextCompat.checkSelfPermission(MainActivity.this,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
                } else {
                    //downloadFile();
                    /**
                     * Write the code you want to execute here
                     */
                }

Where is

used?

for example, we now have a button, we get its click event in the Activity, click we want to add a photo in: /storage/emulated/0/DCIM, we want to perform the operation in else can

example:

no dynamic permissions added:

 utils_get.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getDataFromokHttpUtils();
            }
        });

add dynamic permissions:

utils_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final int REQUEST_EXTERNAL_STORAGE = 1;
                String[] PERMISSIONS_STORAGE = {
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE };
                if (ContextCompat.checkSelfPermission(MainActivity.this,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
                } else {
                    downloadFile();
                }

            }
        });

</ div>

Error inflating class in WebView in Android 5. X android.webkit.WebView Solutions

using WebView in Android version 5.x May report the following error

android.view.InflateException: Binary XML file line #24: Error inflating class android.webkit.WebView

solution 1:

use createConfigurationContext () method to get the Context

public class LollipopFixedWebView extends WebView {

    public LollipopFixedWebView(Context context) {
        super(getFixedContext(context));
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs) {
        super(getFixedContext(context), attrs);
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(getFixedContext(context), attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
        super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
    }

    public static Context getFixedContext(Context context) {
        // Android Lollipop 5.0 & 5.1
        if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT <= 22) 
            return context.createConfigurationContext(new Configuration());
        return context;
    }
}

solution 2:

in the build.gradle of the project, appcompat version 1.1.0 May be buggy, use the following version to solve the problem

implementation 'androidx.appcompat:appcompat:1.2.0'


Java and Android commons codec usage and nosuch method error

introduction

Commons codec, a utility class package provided by the Apache open source organization for handling common encoding methods, such as DES, SHA1, MD5, Base64, URL, Soundx, and so on. Not only encoding, but also decoding.

common classes and functions

1, Base64 encoding and decoding 2, Hex encoding and decoding 3, MD5 encryption (MD5 is an irreversible algorithm, encryption only) 4, SHA encryption 5, Metaphone and Soundex 6, URLCodec

source

the address https://commons.apache.org/proper/commons-codec/download_codec.cgi
or
https://github.com/apache/commons-codec </ p>

Java project using

<dependency>
  <groupId>commons-codec</groupId>
  <artifactId>commons-codec</artifactId>
  <version>1.15</version>
</dependency>

Android USES

it’s a pity that did not provide gradle dependence, only from the source code or download bin file copies jars to the Android projects in use, can appear but in Android USES Java. Lang. NoSuchMethodError: No static method decodeHex (Ljava/lang/String;)
[B in class Lorg/apache/commons/codec/binary/Hex; or its super classes (declaration of ‘org.apache.commons.codec.binary.Hex’ appears in /system/framework/org.apache.http.legacy.boot.jar)

why

Android also has a copy of the package name and class name of the API we use, but the point is there is no such method in the system! This results in a package name conflict, and the system finds the same class with the same name in its SDK, and then calls the method we use below the system’s own class.
however the system does not have that method at all, it is not called at all. And then there’s no and then there’s less than /p>

solution

obtained the source code by itself, modified the package name, and then recompiled into a jar package, and then imported into the Android project for use; Recompile and run your Own Android project, and you’ll see that the previous problems are gone;