I have an app that can send a normal intent by calling startActivity with:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("audio/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(filepath));
startActivity(sharingIntent);
But i want my app on whatsapp attach menu (Audio Item specifically) like this related discussion example: Returning an Image to whatsapp
So, i used the code below, my app is showed on menu but when i do the share steps i get whatsapp "Share failed, please try again" error message. Others similar apps do the steps with the final step showing the Whatsapp Recorder dialog to apply sound on chat.
On this second feature (whatsapp internal intent-filter sharing) i use the same intent but with this:
setResult(RESULT_OK, buildSoundShareIntent(soundId));
finish();
instead of startActivity
Is there something specific and hidden that i dont find?
The solution is below my noose all the time, its simple: call the Intent constructor with action and data (Uri.fromFile(File)):
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));
setResult(sharingIntent);
In camera Settings; set storage to "Ext. SD card". Also, move any older photos you want to share to Ext. SD card. This worked perfectly with me. Hope it will work for you.
Related
I'm trying to set my Android application so that it's available to share links from other apps such as Chrome running on Android.
I have set an Intent Filter on an activity so that my app displays in the "Share via" dialog. That part works fine, but I'm not sure how to actually get the data into my "new post" dialog when it launches.
I read an existing StackOverflow question that suggests using this code:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "I'm being sent!!");
startActivity(Intent.createChooser(share, "Share Text"));
I have an existing method for creating posts that looks like this:
public void onNewPostMenuSelected(MenuItem item) {
Intent intent = new Intent(this, CreatePostActivity.class);
startActivity(intent);
}
Should I modify this existing method and, if so, how? Or should I be doing something else? Thanks in advance!
I have set an Intent Filter on an activity so that my app displays in the "Share via" dialog. That part works fine, but I'm not sure how to actually get the data into my "new post" dialog when it launches.
If by "the data", you mean the text that was shared, call getIntent() on your activity and read the EXTRA_TEXT extra for that. In the case of browsers sharing URLs, EXTRA_TEXT should be the URL.
I am using this code to share link in android app.
Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject test");
i.putExtra(android.content.Intent.EXTRA_TEXT, "extra text that you want to put");
startActivity(Intent.createChooser(i,"Share via"));
But i want to add cutom intent option in dialoag box.
If i have twitter and facebook app in my phone, then above code give me share option
1) Twitter
2) Facebook
3) Bluetooth(if phn supported)
Also with this I want to add
4) Commnets (on comments click user will go my Comment activity)
I want to make share like this.
Can anyone help. Thanks in advance.
You are creating a chooser. It contains all intents that reply to ACTION_SEND text/plain.
To have your comment activity in that list, you need make an intent-filter in your manifest matching that actions for your comment Activity.
Alternatively (and moreeasily, too), if you don't want your Comment activity to respond to external ACTION_SEND text/plain, you can use the response given to this question : Custom filtering of intent chooser based on installed Android package name : Add a Intent.EXTRA_INITIAL_INTENTS extra to the intent.
I have an app which wants to view an image in the gallery app.
I use this code to view it:
File cachedImage = cache.getFile(image.getImageUrl());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(cachedImage), "image/*");
startActivity(intent);
This works except when I click the edit setting here:
and I get the no apps can perform this action message:
Is there some way to make this work? Do I need to pass additional extras? I know the Gmail app is able to view an image attachment in the gallery and the edit function works. This is on JellyBean.
Is there some way to make this work?
Install an app that can edit pictures. Your screenshots appear to be of the Gallery app, which is presumably trying to use ACTION_EDIT to start an activity to edit the picture, and there is no such activity available.
I have been taking a look over stackoverflow but I did't find a definition about what is "createChooser" and why I can use and in whick kind of situations is good to use it.
Thanks in advance.
For example: you have a share picture option in your application.
You define an intent like this:
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
File downloadedPic = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS),
"q.jpeg");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
Than when you call:
startActivity(picMessageIntent);
all applications on your phone capable of getting this picture will be listed.
If you want to custimize the title of that list, you can use createChooser like this:
startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
When startActivity(intent) is called for the first time from your app the user sees a list of all apps capable to handle this intent.
There is also an option to always handle this intent using one of the apps from the list. If this option is used then the list will never be shown again.
If you use createChooser in your intent then the "always use this app" option is not shown. The user always sees this list.
This method is used when you want to create a Custom Action using an Intent... Just like what android provides ACTION_VIEW etc... but here when there are multiple choices to perform an an Action this chooser will bring up a dialog which will have all available options and let the user select one... here is an example
Assuming I know that the Gallery has an album with a certain name X, what intent or broadcast can I make to open Album X with the Gallery app?
There are plenty of examples showing how to select a picture from the Gallery, but I don't see any describing how to accomplish the above.
Thanks.
try this
Intent intent = new Intent();
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Main.this.startActivity(intent);
program will browser all application are support with image file
but user can set default program
If you prepared the Gallery which is called X, yes you can do it.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.Xapp");
if (launchIntent != null) {
launchIntent.setData("PHOTO ID OR ANYTHING ELSE");
startActivity(launchIntent);
}
After then you can set data in intent. And X app parses intent data and you can open it.
Otherwise, you can't this action. You only call the app, If the application does not provide API support for send data with intent.