Image not attaching In Massaging Android - android

I am trying to send MMS through My Application But attachment of Image is not working In HTC device. My code is :
Intent inten = new Intent(Intent.ACTION_SEND);
inten.setClassName("com.android.mms",com.android.mms.ui.ComposeMessageActivity);
inten.setType("image/*");
inten.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(Path)));
startActivity(inten);
And I have Searched applications through wich I can send Image. By this code:
Intent sendOption = new Intent(Intent.ACTION_SEND);
sendOption.setType("image/*");
List<ResolveInfo> ris = getPackageManager().queryIntentActivities(
sendOption, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo ri : ris)
{
String appname = (String) ri.loadLabel(getPackageManager());
String packagename = ri.activityInfo.packageName;
String classname = ri.activityInfo.name;
Share.add(appname);
Classname.add(classname);
Packagename.add(packagename);
}
But Massaging Application name is not coming in that list. This problem is in HTC . I have tasted in Samsung and Micromax in this it's working I have searched But not Getting Any proper Answer. There is to Many Question Having Same problem

The following code work for me.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hi how are you");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/file.gif")));
intent.setType("image/gif");
startActivity(Intent.createChooser(intent,"Send"));

Related

Android M sharing chooser filter

I have a problem with sharing on Android M and exactly with creating intent chooser with filter. I've create a standard text share intent:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, getSharingText());
return intent;
Then I've applied the filter for chooser:
List<Intent> targetedShareIntents = new ArrayList<>();
List<ResolveInfo> resolves = getActivity().getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolves) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedShareIntent = new Intent(mPromoIntent);
if (!packageName.equals("com.facebook.katana")
&& !packageName.equals("com.vkontakte.android")) {
ComponentName componentName = new ComponentName(packageName, resolveInfo.activityInfo.name);
targetedShareIntents.add(targetedShareIntent.setComponent(componentName));
}
}
if (targetedShareIntents.isEmpty()) {
return null;
}
Intent chooser = targetedShareIntents.remove(0);
return Intent.createChooser(chooser, chooserText)
.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
And the I've started the standard chooser ChooserActivity using chooser intent
startActivity(mAppsChooserIntent);
But on Android M it doesn't show chooser, it takes the first intent (in my case bluetooth) and shares with it.
I've looked through the ChooserActivity class, which in Android MNC is much bigger than in Android L and didn't find a solution where.
Does somebody know the answer or it's Android M preview bug?

Cannot share images to WeChat and Line using ACTION_SEND intent

My code is as below -
Intent prototype = new Intent(Intent.ACTION_SEND);
prototype.setData(uri); // uri is of the image file
prototype.setType(image/*);
prototype.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
prototype.putExtra(Intent.EXTRA_STREAM, uri);
List<ResolveInfo> resInfo = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (!resInfo.isEmpty())
{
for (ResolveInfo resolveInfo : resInfo)
{
if (resolveInfo.activityInfo == null)
{
continue;
}
// Retrieve the package name and class name to populate the chooser intent
Intent intent = (Intent) prototype.clone();
String packageName = resolveInfo.activityInfo.packageName;
intent.setPackage(packageName);
intent.setClassName(packageName, resolveInfo.activityInfo.name);
targetedIntents.add(intent);
}}
Intent chooserIntent = Intent.createChooser(topIntents.remove(targetedIntents.size() - 1), chooserTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedIntents.toArray(new Parcelable[] {}));
When I select WeChat and Line app from the chooser, nothing happens. Line app just displays an error that it is unable to share. WeChat doesn't give any message. Sharing works fine on Whatsapp and Hangouts using my code.
We can share images on WeChat and Line from Gallery. How does that work? Is it not a Send action intent?
I was having the same problem so I implemented the following :
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT,sharesubject);
shareIntent.putExtra(Intent.EXTRA_TEXT, sharetext);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(destination));
shareIntent.setPackage(info.activityInfo.packageName);
//destination is the name of the file containing the image to be shared.
Note : This works only for api 23 and below.
Building share intent by ShareCompat works to me
val shareIntent = ShareCompat.IntentBuilder(context)
.setType(context.contentResolver.getType(uri))
.setStream(uri)
.setText(text)
.intent
.apply { addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) }
startActivity(Intent.createChooser(shareIntent, "chooserTitle")
I guess the key point is
mIntent.putExtra(EXTRA_CALLING_PACKAGE, launchingContext.getPackageName());
which is specified in ShareCompat.IntentBuilder(Context)

Need to share text via applications

I need to share text from my applications via other social applications.I have got a piece of code that is working fine but it shows apps list in dialogue box:
And I want same feature in this way.May be I need to create views dynamically as per application installed in device.
Please suggest me how can I achieve this
This code will let you find all the apps available for the specified intent:
public static ArrayList<Availables> getAvailableAppsForIntent(Intent intent, Context context) {
ArrayList<Availables> availables = new ArrayList<Availables>();
PackageManager manager = context.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
for(ResolveInfo info : infos) {
ActivityInfo activityInfo = info.activityInfo;
IntentFilter filter = info.filter;
if (filter != null && filter.hasAction(intent.getAction())) {
// This activity resolves my Intent with the filter I'm looking for
String activityPackageName = activityInfo.packageName;
String activityName = activityInfo.loadLabel(manager).toString();
String activityFullName = activityInfo.name;
Drawable icon = activityInfo.loadIcon(manager);
Availables available = new Availables(activityName, activityFullName, activityPackageName, icon);
available.setForIntent(intent);
availables.add(available);
}
}
return availables;
}
Availables is just a class i created to store all the informations about the apps but you can manage it however you want.
then you can start the app this way:
Intent intent = available.getForIntent();
intent.setPackage(available.getAppPackage());
context.startActivity(intent);
Hope it helps!
hare is button click event use it
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
String shareBody = "Here is the share content body";
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(intent, "Share via"));
Write code on click of any View:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject Here");
intent.putExtra(Intent.EXTRA_TEXT, "Your Message Here...");
return intent;

how to find my android application's storing path of apk file

I want to make an application that could send itself (apk file) by bluetooth. but i have trouble with finding the apk file path. i tried this code:
final PackageManager pm = this.getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
String st = null;
for (PackageInfo packageInfo : packages) {
if(packageInfo.packageName.contains("testbutton"))
st=packageInfo.packageName;
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
String uri = "/data/app/";
uri+=st;
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(uri)));
startActivity(intent);
but st returns null value.
please help me with this. thanks in advance
finally i'd found the right answer that works in this purpose, thanks to #Kanak for her help :)
PackageManager pm = getPackageManager();
String uri = null;
for (ApplicationInfo app : pm.getInstalledApplications(0)) {
if(!((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1))
if(!((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1)){
uri=app.sourceDir;
if(uri.contains("com.example.test"))
break;
}
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(uri)));
startActivity(intent);
There is no need to iteration. Getting the application itself APK file uri is as easy as this:
String appUri = getApplicationInfo().publicSourceDir;
Also note that doc says this about publicSourceDir:
Full path to the publicly available parts of sourceDir,
including resources and manifest. This may be different from
sourceDir if an application is forward locked.
And also note that to send an APK file, you need to set the type to application/vnd.android.package-archive instead of image/*
So the complete snippet would be:
String appUri = getApplicationInfo().publicSourceDir;
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("application/vnd.android.package-archive");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(appUri)));
startActivity(Intent.createChooser(sharingIntent, "Share via"));

Android - How to open the email client directly

I want to open the default email client instead of showing the options. I tried but i am not getting please can anyone help me.
I used the following code:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Allergy Journal");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<small>"+sb.toString()+"</small>"));
startActivity(Intent.createChooser(emailIntent, "Email:"));
It's show the options
But I want to open then Default email client directly.
Frame a String in the format String URI="mailto:?subject=" + subject + "&body=" + body;
and
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse(URI);
intent.setData(data);
startActivity(intent);
This will open up the default e-mail program selected by the user.
Linkify does it this way. Check out it's source code, if you like.
You can used the following code to open whatever intent you want eg gmail, facebook, email etc..Simple in the type as used in my code pass "gmail" if you want to open gmail, pass "face" if u want to open facebook
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/html");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);
if (!resInfo.isEmpty())
{
for (ResolveInfo info : resInfo)
{
if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type))
{
intent.putExtra(android.content.Intent.EXTRA_TEXT, htmlBody);
intent.setPackage(info.activityInfo.packageName);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_send_text)));
}
}

Categories

Resources