I have an application that allows the user to send a picture. This picture can be sent via a number of different ways, like g-mail, facebook, flickr, and the one I am interested in, text messaging. When the following code is run, a dialog box pops up with a number of these options available.
Uri uri = Uri.fromFile(new File(externalDirectory + FILE_DIRECTORY + fileName));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(intent);
On my Droid X, the text messaging option is shown, and this code adds the picture to the MMS perfectly.
On the emulator, text messaging is chosen automatically (since there are no other options) and once again it works great.
On my Droid Incredible, there is no text messaging option. However, I can manually bring up the built-in text messaging utility, add the picture and then send it. I also downloaded an SMS/MMS app from the market, and afterward the option to use this 3rd party program to send the picture was available from the list.
So, why isn't text messaging an available option on the Droid Incredible? What do I need to do to make it an option, and how do I evaluate this problem (OR UNKNOWN PROBLEMS) with phone types I have no access to?
So, why isn't text messaging an available option on the Droid Incredible?
Because they chose not to offer it.
What do I need to do to make it an option
In the abstract, you can't.
Quoting the Android Compatibility Definition Document:
The Android upstream project defines a number of core applications, such as a phone dialer, calendar, contacts book, music player, and so on. Device
implementers MAY replace these applications with alternative versions.
However, any such alternative versions MUST honor the same Intent patterns provided by the upstream project. For example, if a device contains an
alternative music player, it must still honor the Intent pattern issued by third-party applications to pick a song.
The catch is, the Messenger app is not considered a "core application" by Google. Hence, device manufacturers are welcome to include their own SMS clients, with their own Intent filters. In the case of the HTC Incredible, apparently they did not include support for MMS via an image/png ACTION_SEND Intent.
Now, IMHO, Messenger probably should be a core application. However, your opinion and mine do not change reality as it stands today.
how do I evaluate this problem (OR UNKNOWN PROBLEMS) with phone types I have no access to
You redefine your application such that it is not a "problem". You have no guarantee that you can send an MMS that way, just as you have no guarantee that a user has a Facebook app installed.
I don't know much about MMS and am uncertain if there is a way other than ACTION_SEND to send an MMS. You might consider poking through the source code to the Messenger app to see how it does it. Then, bake the capability directly into your app. This will require a few extra permissions (SEND_SMS, and probably READ_CONTACTS) and will be annoying to write, but it will be more likely to work across devices.
I did manage to come up with a work around for this, thanks to some help from some other questions on SO.
Basically the key was determining the intent used by HTC, which appears to be the only company (currently) that's modified the android.intent.action.SEND Intent. Here is the code to add the option to the list.
Uri uri = Uri.fromFile(new File(mFile));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
Intent htcIntent = new Intent("android.intent.action.SEND_MSG");
htcIntent.setType("image/png");
htcIntent.putExtra(Intent.EXTRA_STREAM, uri);
Intent chooser = Intent.createChooser(intent, "Send Method");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { htcIntent });
startActivity(chooser);
Related
the email app is not opening on my android device. there are no error in code but don't know why app isn't working
You are using an old or deprecated way to start activity for ACTION_SEND scenarios. Use below snippet for the correct way.
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)
You can check out the code snippet and detailed explanation here.
https://developer.android.com/training/sharing/send#using-android-system-sharesheet
Starting with API level 30, if you're targeting that version or higher, your app cannot see, or directly interact with, most external packages without explicitly requesting allowance.
Check this answer, it works for me.
https://stackoverflow.com/a/65166064/7248394
I am using a foreground service to track the live location of the user. it is working fine in stock android devices, but in brands like oppo, vivo, Mi etc, the app is killed when the device comes into doze mode. I also tried to use FCM notifications still of no use. I am just wondering has Uber or Ola been able to crack this, bcuz i have seen most of the drivers have been using these brands. How are the able to keep their app alive in doze mode?
you need enable auto start permission for apps in oppo , vivo and mi
try below code worked for me
private void keepServicesInChineseDevices() {
Intent intent = new Intent();
String manufacturer = android.os.Build.MANUFACTURER;
switch (manufacturer) {
case "xiaomi":
intent.setComponent(new ComponentName("com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"));
break;
case "oppo":
intent.setComponent(new ComponentName("com.coloros.safecenter",
"com.coloros.safecenter.permission.startup.StartupAppListActivity"));
break;
case "vivo":
intent.setComponent(new ComponentName("com.vivo.permissionmanager",
"com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
break;
}
List<ResolveInfo> arrayList = getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (arrayList.size() > 0) {
AppDataHolder.getSession(MyApplication.getAppContext()).setPermissionForChineseDevices(true);
startActivity(intent);
}
}
this article is also helpful
Thank you so much guys, for your responses. I would like to tell you that I wrote an email to google support and highlighted the issue to google support, in reply they mentioned below reply:
"Thanks for reaching out.
It seems that you can’t receive a push notification on some Android devices. Upon checking the affected device, it is affected by a device specific (known) issue, and it's caused by OEM features for battery optimization. When the app is swiped away, in some of OEMs which has implemented such a feature, the application is treated similar to "force-stopped" mechanism and services registered with the app that's swiped, is stopped.
For now, I strongly recommend contacting the support team of those affected OEMs to help get it resolved from their end.
You can read more about this issue and a possible way of solving it in this blog post(https://www.freecodecamp.org/news/why-your-push-notifications-never-see-the-light-of-day-3fa297520793/).
I am trying to use android.provider.Telephony.Mms.* items. However it isn't in the sdk. How do you about linking against those classes?
I can probably do it using this method:
Where is com.google.android.mms.*?
Class pduparserclass = Class.forName("android.provider.Telephony.Mms.");
Mms and other apps use private or hidden APIs that are not available through the SDK. Third party apps can't use the private API for various reasons, one being security.
If you want to modify and build MMS you have to create your own ROM so you have to interact with the firmware build.
You can send an SMS/MMS via an itent with this code:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("image/png");
Currently I have a button that when pushed calls the Intent below.
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { toString });
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
"New Files from Safe Storage");
sharingIntent.setType("text/*");
startActivity(sharingIntent);
This intent then uses the default share activity to share the email with my attached file (which i took out for this example). When this code goes off it opens the gmail activity for me, but i still need to push the send button even though everything is filled in. Is there a way to make this instead just send automatically without showing the user the activity and having them forced to push "Send"?
Have a look on the following link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)
I know that the SMS content provider is not part of the public API (at least not documented), but if I understand correctly it's still possible to use many of the SMS features as long as you know how to use the API(?).
E.g it's pretty straightforward to insert an SMS into your inbox:
ContentValues values = new ContentValues();
values.put("address", "+457014921911");
contentResolver.insert(Uri.parse("content://sms"), values);
Unfortunately this does not trigger the standard "new-SMS-in-your-inbox" notification. Is it possible to trigger this manually?
Edit: AFAIK the "standard mail application (Messaging)" in Android is listening for incoming SMSes using the android.permission.RECEIVE_SMS permission. And then, when a new SMS has arrived, a status bar notification is inserted with a "special" notification id.
So one solution to my problem (stated above) could be to find, and send the correct broadcast intent; something like "NEW SMS HAS ARRIVED"-intent.
Edit: Downloaded a third party messaging application (chompsms) from Android market. This application satisfies my needs better. When i execute the code above the chompsms notice the new sms and shows the "standard status bar notification". So I would say that the standard Android Messaging application is not detecting sms properly? Or am I wrong?
Unfortunately the code responsible for these notifications is hidden in the messaging application. The class MessagingNotification has a static method updateAllNotifications that you could call using a PathClassLoader and reflection:
PathClassLoader c = new PathClassLoader("/system/app/Mms.apk", getClassLoader());
Class.forName("com.android.mms.util.ContactInfoCache", true, c)
.getMethod("init", Context.class).invoke(null, context);
Class.forName("com.android.mms.transaction.MessagingNotification", true, c)
.getMethod("updateAllNotifications", Context.class).invoke(null, context);
This is obviously a very bad idea for several reasons but I can't think of another way to do what you described.
Could you trigger a PUSH notification after the SMS?
Thread: Does Android support near real time push notification?
Maybe you should replace
content://sms
with
content://sms/inbox