5

アプリを拡張機能に関連付けようとしています。ドキュメントと問題に関するいくつかの 質問を読みました。しかし、主要なファイル エクスプローラー (es ファイル エクスプローラー、astro、Rhythm ソフトウェアのファイル マネージャーなど) でファイルを開くことができません。

私のmanifestファイル:

<activity android:name="com.comapping.android.map.MapActivity" android:configChanges="orientation|keyboardHidden">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="file" android:host="*" android:pathPattern=".*\\.comap" android:mimeType="*/*" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="content" android:host="*" android:pathPattern=".*\\.comap" android:mimeType="*/*" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.SEARCH" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    <meta-data android:name="android.app.searchable"
        android:resource="@xml/searchable" />
</activity>

そして、次のコードを使用してアプリケーションからファイルを開こうとすると、すべて正常に動作します (セレクターは表示されません):

String extension = "";
int dotIndex = downloadedFile.lastIndexOf('.');
if (dotIndex != -1) {
    extension = downloadedFile.substring(dotIndex + 1, downloadedFile.length());
}

// create an intent
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.fromFile(new File(downloadedFile));
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (type == null || type.length() == 0) {
    // if there is no acceptable mime type
    type = "application/octet-stream";
}
intent.setDataAndType(data, type);

// get the list of the activities which can open the file
List resolvers = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolvers.isEmpty()) {
    (new AlertDialog.Builder(context)
            .setMessage(R.string.AttachmentUnknownFileType)
            .setNeutralButton(R.string.NeutralButtonText, null)
            .create()).show();
} else {
    context.startActivity(intent);
}

OpenIntentsファイルマネージャーを使用して開こうとすると、すべてが正常です-リストに多くのアプリと私のアプリが表示された長いチューザーが表示されました。

しかし、es ファイル エクスプローラーまたは Rhythm ファイル エクスプローラーで開こうとすると、カスタム チューザー (テキスト/画像/ビデオ/オーディオとして開く) が表示されます。これは悪いです。

Astro で開こうとすると、OpenIntent のファイル マネージャーが開きます。それも悪いです。

問題の解決策はありますか?そのような行動で誰が間違っていますか?

助けてくれてありがとう。

4

1 に答える 1

0

ここでの問題の一部は、Android MIME 識別子で text/plain に解決されるファイルなどの共有インテントをラップするさまざまな方法にあります。

私のアプローチは、必要なファイルがどのような MIME タイプであるかを調べることでした。次に、マニフェスト フィルターをそれらのタイプに設定します。2つのフィルターを使用しています。最初のものは、必要なマイムをフィルタリングするだけです。2 番目は、最初のプラス スキームのコピーです。

次に、あなたが行ったように、アプリから共有を送信してテストします。うまくいかない場合は、トーストを使用して、STREAM で何が得られているかを確認し、それに合うように変更します。たとえば、OpenIntent STREAM を取得した場合、削除する必要があります

content://org.openintents.filemanager

それは私に道を残します。ほとんどの場合、次のものを削除するだけです。

file://

しかし、コンテンツ/Uri/インテント スキーム全体が自由に使えるクラスター whatsit であるため、それは常に何かです。

後で。私はこれにつまずいた:

Intent intent = getIntent();                
String name = intent.getData().getPath();

多分それはあなたのためにするでしょう。自分も早速やってみます。

于 2014-01-04T23:05:38.523 に答える