私はアンドロイドプログラミングにまったく慣れておらず、最高のプログラマーでもなく、次のコードは私の知識に基づいて動作するはずです...したがって、それが問題です:私のアプリケーションをtxtを開くためのオプションとして表示したい-私の電話でファイルします。そのため、次のようにマニフェストで指定されているブロードキャスト レシーバーを作成しました。
<receiver android:name="MyBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.ACTION_VIEW"/>
<action android:name="android.intent.action.ACTION_EDIT"/>
<action android:name="android.intent.action.ACTION_PICK"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file"/>
<data android:mimeType="text/plain"/>
<data android:pathPattern=".*\\.txt"/>
<data android:host="*"/>
</intent-filter>
</receiver>
そして、私のブロードキャストレシーバー クラスは次のようになります。
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent intentNoteActivity = new Intent(context, NoteActivity.class);
intentNoteActivity.putExtra("URI", intent.getData());
context.startActivity(intentNoteActivity);
}
}
しかし、アプリケーションがインストールされている携帯電話で txt ファイルを開こうとしても、アプリケーションが表示されません。私は何を間違えたのですか?
というわけで放送受信機を作ってみた
ABroadcastReceiver
は、この方法でドキュメントを開くために使用されません。アンActivity
はそうします。
しかし、アプリケーションがインストールされている携帯電話で txt ファイルを開こうとしても、アプリケーションが表示されません。
他のアプリが使用するためですstartActivity()
、ないsendBroadcast()
で、ACTION_VIEW
Intents
。
アクティビティを作成し、<intent-filter>
それを使用します。それほど多くはありませんが、いくつかのアプリで動作するはずです。と を削除<data android:pathPattern=".*\\.txt"/>
して<data android:host="*"/>
を追加すると、<data android:scheme="content"/>
互換性が向上します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加