android - 从 android Intent.ACTION_SEND 中提取文件路径

标签 android android-intent

是否可以从收到的 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/

相关文章:

android - 在 com.google.android.maps.MapView 中禁用平移/缩放

android - 在 Android 上执行周期性任务的最可靠方法

android - 您如何根据 Intent 的数据在android中启动不同的 Activity

android - 通过 intent - uri 权限共享图像

适用于所有类型的 Android NFC Intent-filter

android - 防止 FragmentStatePagerAdapter 不销毁 fragment

java - 如何在android中获取一个地方的时区?

android - TaskStackBuilder addParentStack 在 Android 2.3 中工作吗

android - ACTION_GET_CONTENT 到 Google 图片

android - 在分享 Intent android 中使用 Facebook sdk 的 ShareContent