I'm trying to share custom data using the Sharesheet and the first question is: is it possible?
Example: In my app there is an address book and I want to share with a friend via Whatsapp a single contact [class: Contact]. When he receive the message he should be able to open the contact directly in the app or, if it's not installed, he should be directed to the play store to download the app.
I found how to send simple text and I've build for each class I want to share a corresponding Parcelable. Now the following is my code, the Sharesheet is opening but if I select the contact I want to share with it give me an error message: "Sharing failed, retry" (Whatsapp) or "Unsupported content" (Telegram).
sContact = new Contact();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
ArrayList<Contact> ContactsList = new ArrayList<Contact>();
ContactsList.add(sContact);
Parcel.obtain().readList(ContactsList, Contact.class.getClassLoader());
sendIntent.putParcelableArrayListExtra("ShareContact", ContactsList);
sendIntent.setType("image/*");
Intent shareIntent = Intent.createChooser(sendIntent, null);
startActivity(shareIntent);
Another thing I can't understand is that if I add an item to the ContactsList the app crashes with error "android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.myapp.Contact", instead with the list empty the sharesheet opens.