문제

Android 4.4의 Storage Access Framework를 사용해 보고 있습니다.

활동 시작 시 의도를 실행하는 더미 앱을 개발했습니다.

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, READ_REQUEST_CODE);

또한 파일 제공자 역할을 하는 또 다른 더미 앱을 개발했습니다.

        <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.saf"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="19"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.saf.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <provider
        android:name="com.example.saf.MyFileProvider"
        android:authorities="com.example.saf.documents"
        android:exported="@bool/is_kitkat"
        android:enabled="@bool/is_kitkat"
        android:grantUriPermissions="@bool/is_kitkat"
        android:permission="android.permission.MANAGE_DOCUMENTS">
        <intent-filter>
            <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
        </intent-filter>
    </provider>

</application>

MyFileProvider 클래스를 구현했습니다.

하지만 사용자 앱(인텐트를 실행하는 앱)을 실행하면 다음 오류가 발생합니다.

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] }

나는 안드로이드 개발자 문서를 따르고 있었습니다.내가 뭘 잘못하고 있는지 어떤 아이디어가 있습니까?

편집하다:여기 내 최신 매니페스트가 있습니다.또한 MyFileProvider "확장 DocumentsProvider"를 "적절하게" 구현해야 합니까?지금은 함수에서 null을 반환할 수 있나요?

도움이 되었습니까?

해결책

MIME 유형을 추가하거나 간단히 intent.setType("*/*").

이것은 것 같다 알려진 문제. setType() 필요합니다.

편집하다:너도 추가해야 해 android:enabled="true", >=kitkat에 대해서만 활성화하기 위해 직접 참조하는 것이 아니라 값에서 참조해야 합니다.그래서 android:enabled="@bool/is_kitkat", <bool name="atLeastKitKat">false</bool> ~에 /res/values/ 그리고 <bool name="atLeastKitKat">true</bool> ~에 /res/values-v19/

다른 팁

모든 파일을 열려면이 줄을 추가하십시오.

intent.setType("*/*") ;
.

이미지를 표시하려면 필터링 해야하는 경우이 줄을 추가하십시오 :

intent.setType("image/*");
.

그냥 당신의 의도를 던지십시오, 좋아요,

     Intent intent = new Intent("android.intent.action.GET_CONTENT");
    ((Intent)intent).addCategory("android.intent.category.OPENABLE");
    ((Intent)intent).setType("*/*");
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top