【发布时间】:2019-05-31 06:22:36
【问题描述】:
我实际上是在尝试将来自 API 的数据(作为文本而不是文件)发送给我,并且我想通过许多应用程序将这些数据作为文本文件发送,其中包括像 WhatsApp 这样的文件共享、远足、电报、分享等。
【问题讨论】:
我实际上是在尝试将来自 API 的数据(作为文本而不是文件)发送给我,并且我想通过许多应用程序将这些数据作为文本文件发送,其中包括像 WhatsApp 这样的文件共享、远足、电报、分享等。
【问题讨论】:
-你可以试试这个代码,看看它是否对你有用:
Intent shareIntent = new Intent("android.intent.action.SEND");
shareIntent.setType("text/plain");
shareIntent.putExtra("android.intent.extra.SUBJECT",
"Codes Easy");
shareIntent.putExtra("android.intent.extra.SUBJECT",
"Add a text to be shared here");
startActivity(Intent.createChooser(shareIntent, "Share with"));
【讨论】:
<data android:scheme="file" /> //Means local file
<data android:mimeType="*/*"/> //This accept any mimeType
<data android:pathPattern=".*\\.txt" /> //Your excepted extention
试试这个代码:
private Uri getUriForFile() {
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (TextUtils.equals(Intent.ACTION_SEND, action)
&& !TextUtils.isEmpty(type)) {
Uri uri =
intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
Log.e("uri",uri.toString());
return uri;
}
}
return null;
}
【讨论】: