omeliiii
omeliiii

Reputation: 31

How to share audio on Telegram

I want to make a button to share an audio file on Telegram. I have problems only with Telegram (sharing on whatsapp works fine).

My audio file is in raw folder, and i tried with .mp3, .wav and .m4a extensions, but if i try to share audio on telegram i get the toast "Unsupported attachment".

That's my share method:

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/m4a");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + ctx.getPackageName() + "/" + R.raw.my_audio));
startActivity(Intent.createChooser(share, "Share on:"));

Upvotes: 2

Views: 4034

Answers (2)

Siyawash
Siyawash

Reputation: 61

use "Uri.fromFile", this worked for me.

                File file = new File(filePath);
                Uri uri = Uri.fromFile(file);
                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("audio/*");
                share.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(share,
                        "به اشتراک گذاشتن فایل"));

Upvotes: 6

CommonsWare
CommonsWare

Reputation: 1007321

Many Android apps will not handle the ill-used android.resource:// scheme. If you want better compatibility, write the audio to a file and share that, or use a ContentProvider (e.g., my StreamProvider) to serve it via a content:// scheme.

Upvotes: 0

Related Questions