小编use*_*922的帖子

Android中的Android选择图片不起作用(Android 6.0和Android 5.1.1)

我正在使用下面的代码从设备库中选择一个图像文件:

首先,我称这段代码:

Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(i, "Select Picture"), RESULT_LOAD_IMAGE);
Run Code Online (Sandbox Code Playgroud)

这是我的onActivityResult方法:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {

            photoPath  = getPath(data.getData());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            FileInputStream fis;
            try {
                fis = new FileInputStream(new File(photoPath));
                byte[] buf = new byte[1024];
                int n;
                while (-1 != (n = fis.read(buf))) {
                    baos.write(buf, 0, n);
                }

                img.setImageBitmap(BitmapFactory.decodeFile(photoPath));

            } catch …
Run Code Online (Sandbox Code Playgroud)

android action image gallery photo-gallery

5
推荐指数
1
解决办法
5317
查看次数

Android Studio - 包含和使用.so库

我需要在我的android项目中使用一些本机库(.so).根据StackOverflow中关于这个主题的一些答案,我创建了一个jniLibs文件夹app/src/main并放在那里我的文件:

armeabi/my_lib.so
armeabi-v7a/my_lib.so
x86/my_lib.so
Run Code Online (Sandbox Code Playgroud)

然后,在我的活动类中,我使用:

static {
        System.loadLibrary("my_lib");
    }
Run Code Online (Sandbox Code Playgroud)

但是当我运行应用程序时,UnsatisfiedLinkError会生成异常.如果这一点很重要,我没有Android.mk文件,而且我没有在我的gradle文件中更改任何与此有关的内容.所以,我唯一想到的就是复制粘贴我的.so文件jniLibs并在我的活动中编写上面的代码.那么这个问题可能是什么原因呢?我错过了什么吗?

编辑

这是我的傻瓜:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 15
    buildToolsVersion "23.0.3"

    compileOptions.encoding = 'ISO-8859-1'

    defaultConfig {
        applicationId "my.package"
        minSdkVersion 4
        targetSdkVersion 4

        ndk {
            moduleName "my_so_lib"
        }
    }

    sourceSets {
        main {
            jni.srcDirs = ["libs"]
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true
        }
    }


    splits {
        abi {
            enable …
Run Code Online (Sandbox Code Playgroud)

java android gradle android-studio

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×2

action ×1

android-studio ×1

gallery ×1

gradle ×1

image ×1

java ×1

photo-gallery ×1