I'm trying to read a text file from WhatsApp and can find the filename in the intent, but not the file itself.
Also confused as to what the MIME type should be. Should "text/plain" be used for both shared text AND a shared text file? How does one differentiate between one and the other?
[IntentFilter(new[] { Intent.ActionSend },
Categories = new[] { Intent.CategoryDefault },
DataMimeType = @"text/plain", Icon = "@drawable/icon")]
void HandleSendIntent(Intent intent)
{
//extra1 = "myfile.txt"
var extra1 = intent?.GetStringExtra(Intent.ExtraText)?.Trim();
//extra2 = null
var extra2 = intent?.GetStringExtra(Intent.ExtraProcessText)?.Trim();
//uri = {content://com.whatsapp.provider.media/item/83019679-d3d1-4e43-805e-7a05734e88df}
Android.Net.Uri uri = (Android.Net.Uri)intent.GetParcelableExtra(Intent.ExtraStream);
string doc_id = "";
using (var c1 = ContentResolver.Query(uri, null, null, null, null))
{
c1.MoveToFirst();
string document_id = c1.GetString(0);
//doc_id = "myfile.txt":
doc_id = document_id.Substring(document_id.LastIndexOf(":") + 1);
}
//a = null
var a = Intent.GetParcelableArrayExtra("com.whatsapp");
//b = null
var b = Intent.GetByteArrayExtra("com.whatsapp");
//c = "text/plain"
var c = Intent.Type;
//
//Where is the file????
//
}