2012-06-11 29 views
5

私は自分のアプリケーションをエクステンションに関連付けようとしています。私はこの問題についてdocumentationsomequestionsを読んだ。しかし、主要なファイルエクスプローラ(esファイルエクスプローラ、アストロ、リズムソフトウェアのファイルマネージャなど)はファイルを開くことができません。一般的なファイルエクスプローラのインテントフィルタ

マイ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ファイルエクスプローラまたはリズムファイルエクスプローラで開くと、そのカスタムチューザ(テキスト/画像/ビデオ/オーディオとして開く)が表示されます。これは悪いです。

私がAstroで開くと、OpenIntentのファイルマネージャが開きます。それはまた悪いです。

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

ありがとうございました。

答えて

0

ここでの問題の一部は、AndroidのMIME識別子でtext/plainに解決されるファイルのように、人々が共有する意図を包むさまざまな方法です。

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

次に、あなたが行ったようにアプリから共有を送信してテストします。 1つがうまくいかない場合、私は乾杯のために私が何を得ているのかを見て、それを適合させるために変更します。たとえば、OpenIntentストリームを取得した場合、削除する必要があります。

content://org.openintents.filemanager 

私はパスを残します。ほとんどの場合、私は削除する必要があります:

file:// 

をしかし、全体のコンテンツ/ウリ/テントスキームは自由のために、すべてのクラスタと、whatsitあるので、それは常に何か。

後で。私はちょうどこれをつまずいた:

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

多分それはあなたのためになります。私はすぐにそれを試してみるつもりです。