我希望我的应用程序显示在 Android 的共享屏幕对话框上。 就像我们使用文件管理器并想要打开任何带有 mp4 扩展名的文件(比如说)一样。然后我们将获得手机上所有 mp4 媒体播放器的列表。或者,如果您选择共享任何文件,那么我们将获得可以共享该文件的所有应用程序的列表,例如 WhatsApp、xender 等。 同样,我想在我的应用程序“文本到 UI”(应用程序名称)中打开 .txt 文件。 虽然我已经知道如何手动打开文件。
最佳答案
在共享时打开的 Activity 下的 list 中添加以下代码
如果MainActivity
不是启动器 Activity ,请在 list 中添加以下代码
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
如果 MainActivity
是您的启动器 Activity ,并且该 Activity 在共享上打开,请在 list 中添加以下代码
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
MimeType "text/*"
仅用于发送文本类型数据。
MimeType "image/*"
仅用于发送图像类型数据。
MimeType "video/*"
仅用于发送视频类型数据。
MimeType "*/*"
能够发送所有类型的数据,如视频、音频、图像、文本
要在应用程序中获取数据,请在 Activity 中尝试以下代码:
Intent receiverdIntent = getIntent();
String receivedAction = receiverdIntent.getAction();
String receivedType = receiverdIntent.getType();
if (receivedAction.equals(Intent.ACTION_SEND)) {
Uri receiveUri = (Uri) receiverdIntent
.getParcelableExtra(Intent.EXTRA_STREAM);
if (receiveUri != null) {
Log.e("Shared",receiveUri.toString());
}else{
Log.e("Shared","Nothing");
}
}
应用程序在共享列表中:
希望它对你有用。
关于java - 如何通过共享屏幕打开我的 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59062758/