Android Facebook Messenger intent not working - android

im trying to share audio file on facebook messenger. Following as mention https://developers.facebook.com/docs/messenger/android#integration_with_intents here but it work to share simple text not audio file. App crash when i try to send audio on messenger.
This is intent share code
String mimeType = "audio/aac";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);
this.startActivityForResult(intent, SHARE_TO_MESSENGER_REQUEST_CODE);

There is no option for Facebook, but you can share email and MMS with Bluetooth. Here is my code. Take a look if it helps you:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///"+mypath));
startActivity(Intent.createChooser(share, "Share Sound File"));
break;

Related

Android: Is it possible to open the browser from a share intent?

I am wondering if there is a possibility to open the browser out of the share intent. Let me give an example to clarify:
I have an app with news in it. Each news has an url, so that the user can share this link with the known android share intent per whatsapp, bluetooth, hangouts or something else). Now I wonder if it is possible, that the user could also open this link in the browser out of this share intent. So: am I able to tell the intent, that he should also show the opportunity to open the news-url in the browser?
My current share intent looks like the following:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("text/plain");
String shareString = news.getLink();
intent.putExtra(Intent.EXTRA_TEXT, shareString);
context.startActivity(intent);
I had this same requirement. I used below code
//Creating intent for sharing
//TODO edit your share link
String shareString = "http://www.stackoverflow.com";
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, shareString);
//Creating intent for broswer
//TODO edit you link to open in browser
String url = "http://www.stackoverflow.com";
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
viewIntent.setData(Uri.parse(url));
Intent chooserIntent = Intent.createChooser(sendIntent, "Open in...");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{viewIntent});
startActivity(chooserIntent);
This answer provides a complete example. You can choose the apps you want from the original share intent list and add your own intent.

How to attach an image directly (automatically) to an email on Android?

I would like to ask if anyone knows how to attach an image directly to a send email portal instead of opening up the gallery for users to select?
Thanks a lot.
use the below code
File file = new File(Environment.getExternalStorageDirectory(),"image.png");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+file));
startActivity(Intent.createChooser(intent, "Share Picture Via Email"));

Google mobile compose page URL

I want to send a predifined google+ message via android, but I\m not sure I found the right URL for that. I found https://plus.google.com/app/plus/mp/430/#~loop:view=compose , but it's not setting my text. Is there actually another official app URL that could allow that? Twitter has the one bellow. 10x
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, msg);
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://mobile.twitter.com/compose/tweet"));
ctx.startActivity(i);
You can share text and images on Google+ with the ACTION_SEND intent.
Example:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello World!");
shareIntent.setType("text/plain");
startActivity(shareIntent);
If you would like to target the Google+ app directly, you can call setPackage on the shareIntent before calling startActivity.
shareIntent.setPackage("com.google.android.apps.plus");

How to send recorded voice in email?

I am developing a Android Application, In which I need to send voice by email.
Ans I want that such flow,
record a voice and send mail as a audio file in attachment.
and I want that voice should not remaining in phone or SD card.
is it possible ?
Here is what you need, It works with me.......
Uri uri = Uri.fromFile(new File(YOUR_DIR, YOUR_FILE_NAME)));
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "TITLE");
it.putExtra(Intent.EXTRA_TEXT, "CONTENT");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("audio/rfc822");
context.startActivity(Intent.createChooser(it,context.getString(R.string.share)));
One of the solution according to me is..
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("audio/3gp");
startActivityForResult(Intent.createChooser(sendIntent, "Send mail..."),0);
with above code you can send the voice as email attachment and in the onActivityResult() you can delete the file from sdcard/memory.

Share audio file (.mp3) via Facebook, email, and SMS/MMS

I have an audio file (.mp3) and some information related to it. I want to share with Facebook, E-mail, SMS/MMS, etc..
What I have done is: when user clicks on the share button, it pops up list of all supported applications that can handle this Intent. But this does not show Facebook and SMS/MMS options.
Here is my code..
public void shareWithFriends(int resId)
{
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/mp3");
share.putExtra(Intent.EXTRA_SUBJECT,"Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
share.putExtra(Intent.EXTRA_TEXT,"Ringtone File : "+getResources().getResourceEntryName(resId)+".mp3");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.my.android.soundfiles/"+resId));
share.putExtra("sms_body","Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
startActivity(Intent.createChooser(share, "Share Sound File"));
}
Here are some results:
When I use MIME type audio/mp3, only the email options pops up. No Facebook and SMS/MMS share.
When I use MIME type */*, Email and SMS options pops up. No Facebook option is there.
Here it is interesting to note that when I click on the SMS option, only text appears. I don't see any MP3 file attached (the same thing happens in Whatsapp (as I have Whatsapp installed on my phone). However, when I click on any mail application (for example, Gmail or Yahoo mail) it shows me the MP3 file attached.
Where am I going wrong?
There is no option for Facebook, but you can share email and MMS with Bluetooth. Here is my code. Take a look if it helps you:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///"+mypath));
startActivity(Intent.createChooser(share, "Share Sound File"));
break;
Here my path is the path of the sound file on the SD card.
You are trying to share an mp3 over services that don't support it.
Facebook supports text, pictures and videos.
SMS is plain text (and only very short plain text)
MMS does support audio, but (as far as I can tell from observation (i.e. without reading the spec)) only very low bit rate audio in some format that usually comes in a file with a .3g extension
The apps do not show up in the list of supported apps for mp3 because they are not supported.
File f=new File("full audio path");
Uri uri = Uri.parse("file://"+f.getAbsolutePath());
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("audio/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(share, "Share audio File"));
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("audio/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.fromFile(new File("filepath")));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
You are try this.
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "bod of sms");
sendIntent.setType("*/*");
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.amr");
Uri uri = Uri.fromFile(file1);
Log.e("Path", "" + uri);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sendIntent, ""));
Use following code its working for me to share audio via intent.
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/abc.mp3";
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + path));
startActivity(Intent.createChooser(share, "Share Sound File"));
String sharePath = Environment.getExternalStorageDirectory().getPath()
+ "/Soundboard/Ringtones/custom_ringtone.ogg";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));

Categories

Resources