Reputation: 1643
Is it possible to extract file-path from received Intent.ACTION_SEND? I'm trying to list my android app in "Share via" list. To do so, I've the manifest like this:
<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>
Now I select my app from the "Share-via" list. Is it possible to get the full file path from the received intent (for all file types)? This is what I've done so far:
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
}
}
I've seen many solutions for this, but most of them are restricted to image sharing. Any help please?
Upvotes: 1
Views: 2143
Reputation: 14755
if you have
<action android:name="android.intent.action.VIEW" />
you can get the file path
_file = getIntent().getData().toString();
if (_file.startsWith("file:///"))
_file = _file.substring(7);
to get all mime types you can use
<data android:mimeType="*/*" />
If you want to analyse how other apps handle intends you can use the free android app intentintercept to analyse them
Upvotes: 2