是否可以从收到的 Intent.ACTION_SEND 中提取文件路径?我正在尝试在“共享方式”列表中列出我的 Android 应用程序。为此,我有这样的 list :
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:mimeType="image/*" />
<data android:mimeType="audio/*" />
<data android:mimeType="video/*" />
<data android:mimeType="application/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
现在我从“Share-via”列表中选择我的应用程序。是否可以从接收到的 Intent 中获取完整的文件路径(对于所有文件类型)?这是我到目前为止所做的:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
TextView output=(TextView)findViewById(R.id.textview1);
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_SEND) && intent.hasExtra(Intent.EXTRA_TEXT)) {
String s = intent.getStringExtra(Intent.EXTRA_TEXT);
output.setText(s); //output: a TextView that holds the URL
}
}
我见过很多解决方案,但大多数都仅限于图像共享。有什么帮助吗?
最佳答案
如果你有
<action android:name="android.intent.action.VIEW" />
可以得到文件路径
_file = getIntent().getData().toString();
if (_file.startsWith("file:///"))
_file = _file.substring(7);
获取所有可以使用的 mime 类型
<data android:mimeType="*/*" />
如果您想分析其他应用程序如何处理 Intent ,您可以使用免费的安卓应用程序 intentintercept分析它们
关于android - 从 android Intent.ACTION_SEND 中提取文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22460620/