相关疑难解决方法(0)

ListView ImageButton 设置铃声

我想做以下链接:http://imagizer.imageshack.us/v2/800x600q90/42/gbs4.jpg

但是当我按下 ImageButton 时,我希望将声音设置为铃声。

这是我的代码:

    公共类 ListViewAdapter 扩展 BaseAdapter {

        私有Context上下文;
        私人清单项目;
        私有 LayoutInflater 充气器;
        字符串路径=“SD卡/媒体/铃声”;

        公共ListViewAdapter(上下文上下文,
                               列出项目 ) {
            inflater = LayoutInflater.from( 上下文 );
            this.context = 上下文;
            this.items = 项目;
        }

        公共 int getCount() {
            返回 items.size();
        }

        公共对象 getItem(int 位置) {
            返回 items.get(位置);
        }

        公共长 getItemId(int 位置) {
            返回位置;
        }

        公共视图 getView(int 位置,视图 ConvertView,ViewGroup 父级){
            字符串 item = items.get(position);
            查看 v = null;
            if( 转换视图!= null )
                v = 转换视图;
            别的
                v = inflater.inflate( R.layout.list_row, 父级, false); …

android listview imagebutton

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

无法请求READ_EXTERNAL_STORAGE权限

我试图从存储中读取图像路径,我在这里继续获取SecurityException:

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=31409, uid=10053 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
Run Code Online (Sandbox Code Playgroud)

我正在编译反对api 23并且在我的Manifest中明确说明了我的Manifest的直接子项.我也理解新的运行时权限声明,当您想要访问存储时,您必须在运行时请求权限.当我写这行开始检查权限时,我得到一个无法在IDE中解决的问题:

ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
Run Code Online (Sandbox Code Playgroud)

无法解析符号Manifest.permission.READ_EXTERNAL_STORAGE.我可以在我的代码中明确说明的唯一Manifest.permission是Manifest.permission.C2D_MESSAGE而没有得到无法解决的错误.还有其他我需要编译才能访问代码中的其他权限吗?

要清楚这是给我SecurityException的代码块:

public List<String> getCameraImagesFull(Context context) {
        Cursor cursor = null;
        String[] star = {"*"};
        ArrayList<String> result = new ArrayList<>();
        cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, star, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
                    result.add(path);
                } while (cursor.moveToNext());
            }
            cursor.close();
        }
        return result;
    }
Run Code Online (Sandbox Code Playgroud)

这是抛出异常的行:

cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, star, …
Run Code Online (Sandbox Code Playgroud)

android mediastore android-permissions android-6.0-marshmallow

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

如何在代码中找到所需的Android Marshmallow运行时权限?

我正准备将我的应用程序定位到Android 6.0 Marshmallow.

将目标api设置为23时,应用程序会在启动时立即崩溃.logcat输出中没有有用的信息.(它给出了一个"请求的窗口不存在"IllegalStateException,但是,实际上没有什么比类名或行号更有用.)

这很好(不是真的),我最终将其缩小到我的启动活动,在那里我获得了用户的设备IMEI代码(TelephonyManager.getDeviceId()).需要添加运行时权限请求.我理解这一点.

但是,应用程序在众多活动中有60个类,因此需要排序很多代码.如何搜索代码以查找需要运行时权限的所有情况?

当然Google必须想到一种简单的方法让开发人员找到需要权限请求的位置?我想也许注释掉清单中的权限会触发使用权限的编译时错误,或类似的东西,但不是.

我目前的方法是通过浏览应用程序,当它崩溃时,按照我的启动活动进行上述操作,然后慢慢缩小它的位置.这非常低效且耗时.我现在很想把它留在API 22,但我知道迟早要做到这一点.

android android-permissions android-6.0-marshmallow

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

"写设置"权限未授予marshmallow android

<uses-permission android:name="android.permission.WRITE_SETTINGS"
Run Code Online (Sandbox Code Playgroud)

我已经在我的清单中声明了上面的行,并且我要求获得活动开始的许可,但与其他权限不同,重新启动我的应用程序后,它再次请求权限.当我检查是否已授予权限时,我得到的结果不是仅授予此权限,但当我使用其他权限检查相同的内容时,会在用户完成后授予它们.

ActivityCompat.requestPermissions(SplashScreen.this,PERMISSIONS, 1);
Run Code Online (Sandbox Code Playgroud)

我查看:EasyPermissions.hasPermissions(this,PERMISSIONS)

permissions android android-permissions android-6.0-marshmallow

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

获取文件未找到异常

我有我的android活动:

try {  
            File root=Environment.getExternalStorageDirectory();  
            Log.i("root",root.toString());  
                            File dir=new File(root.getAbsolutePath() + "/downloads");  
            dir.mkdirs();  
            file=new File(dir,"mytext.txt");  
            FileOutputStream out=new FileOutputStream(file,true);  
            PrintWriter pw=new PrintWriter(out);  
            pw.println("Hello! Welcome");  
            pw.println("You are Here...!!!");  
            pw.flush();  
            pw.close();  
            try {  
                 out.close();  
            } catch (IOException e) {  
            // TODO Auto-generated catch block  
                e.printStackTrace();  
          }
        } catch (FileNotFoundException e) {  
             // TODO Auto-generated catch block  
             e.printStackTrace();
        }  
Run Code Online (Sandbox Code Playgroud)

还补充说:

   <uses-permission android:name="androd.permission.WRITE_EXTERNAL_STORAGE"/>   
Run Code Online (Sandbox Code Playgroud)

但它抛出我FileNotfound异常:01-13 09:06:44.442:WARN/System.err(419):java.io.FileNotFoundException:/mnt/sdcard/downloads/mytext.txt(没有这样的文件或目录)

如果我加

 if(file.exists()){  
   System.out.println("file exists");  
  }  
  else{  
     System.out.println("No such Fileeeeeeeeee");  
   }  
Run Code Online (Sandbox Code Playgroud)

它进入"其他"部分.

谢谢
Sneha

android filenotfoundexception

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

如何允许在棉花糖中改变屏幕亮度

我正在使用以下代码来增加亮度.它适用于棉花糖以下的设备.它在Marshmallow崩溃了,我没有找到任何给动态写入设置的权限.有人有想法请帮帮我.

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); 
    Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255);

int br = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.screenBrightness = (float) br / 255;
    getWindow().setAttributes(lp);
Run Code Online (Sandbox Code Playgroud)

错误日志:

java.lang.SecurityException: com.package was not granted  this permission: android.permission.WRITE_SETTINGS.
   at                 android.provider.Settings.isCallingPackageAllowedToPerformAppOpsProtectedOperation(Settings.java:8465)
   at    android.provider.Settings.checkAndNoteWriteSettingsOperation(Settings.java:8338)
at com.android.providers.settings.SettingsProvider.mutateSystemSetting(SettingsProvider.java:899)
at com.android.providers.settings.SettingsProvider.insertSystemSetting(SettingsProvider.java:874)
at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:257)
at android.content.ContentProvider$Transport.call(ContentProvider.java:398)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:283)
at android.os.Binder.execTransact(Binder.java:453)
Run Code Online (Sandbox Code Playgroud)

android screen-brightness

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

棉花糖的权限和解释

可以解释一下我应该如何向用户许可解释

我使用Camera2API,我实现了这样的代码片段,以恐怖的方式询问permishion

private void openCamera(int width, int height) {
    setUpCameraOutputs(width, height);
    CameraHelper.configureTransform(width, height, textureView, previewSize, getActivity());
    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

    try {
        if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) !=
                PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {

                // Show an explanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try …
Run Code Online (Sandbox Code Playgroud)

java permissions camera android android-camera

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

使用 Android (ndk) 在 C++ 中打开和读取文本文件

我正在尝试在 Android 中制作一个使用 C++ 中的 OpenCV 的应用程序。我面临的问题是我想从本机部分打开一个文本文件来逐字阅读,但它打不开。我的代码如下:

JNI方法:

JNIEXPORT jboolean JNICALL Java_com_alejandro_nativeopencv_NativeClass_initRecognizer(JNIEnv * env, jclass clazz){

    recognizer = Recognizer("ORB","ORB","BruteForce-Hamming");
    recognizer.createObject("/storage/emulated/0/TFG/Fotos/Carpeta", true);
    recognizer.createObject("/storage/emulated/0/TFG/Fotos/Cereales", true);

    return true;
}
Run Code Online (Sandbox Code Playgroud)

以及我正在使用的 Recognizer::createObject 方法:

识别器.cpp

#include "headers/Recognizer.h"
#include <fstream>
#include <iostream>
#include <string>
#include <android/log.h>

using namespace std;
using namespace cv;

//...other methods, constructors and stuff...

Object Recognizer::createObject(String path, bool add) {
    __android_log_print(ANDROID_LOG_DEBUG,"path","%s",(path + "/info.txt").c_str());
    ifstream file((path + "/info.txt").c_str());
    if (!file.is_open()){
        //always enters here
        return Object(true);  //null object
    } else{
        //never enters here
        String …
Run Code Online (Sandbox Code Playgroud)

c++ java android opencv android-ndk

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

Java android Java.io.FileNotFoundException:无内容提供者:/storage/emulated/0/Android/data

我想拍一张照片并在 imageView 中显示这张照片,它在 api 23 和 24 上无法正常工作我尝试添加了一个文件提供程序,这就是我所做的。

我的活动:

public class TestActivity extends AppCompatActivity {

    ImageView iv;
    private File photoFile;
    private String mCurrentPhotoPath;
    private static final String TAG = "PHOTO";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        iv = (ImageView) findViewById(R.id.iv);

        photo();


    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            if (mCurrentPhotoPath != null) {
                File file = new File(mCurrentPhotoPath);
                if(file.exists())
                    Log.e(TAG , "photo jest");
                try { …
Run Code Online (Sandbox Code Playgroud)

java android

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

将所有异常写入文件

我正在使用 Timber 将一些日志写入位于设备上的文件。现在,我正在使用 HTTP 拦截器编写我选择的日志和来自服务器的一些响应。但我想在文件中写入所有异常(例如致命的)。木材或其他图书馆可以吗?

现在我正在使用 Fabric,但我的应用程序并不总是与外部世界有互联网连接

PS我想在没有try/catch的情况下编写所有致命异常

TimberLooger.class

public class FileLoggingTree
{
    /**
     * Sends an error message to LogCat and to a log file.
     * @param context The context of the application.
     * @param logMessageTag A tag identifying a group of log messages. Should be a constant in the
     *                      class calling the logger.
     * @param logMessage The message to add to the log.
     */
    public static void e(Context context, String logMessageTag, String logMessage)
    {
        if (!Log.isLoggable(logMessageTag, Log.ERROR)) …
Run Code Online (Sandbox Code Playgroud)

android timber-android

3
推荐指数
1
解决办法
1200
查看次数