Customizing a share dialog - java

I'm trying to obtain a share dialog similar to the one below for sharing some plain text with a preselected list of apps (email, Facebook, Twitter, Google+). The problem is that if I launch an intent to share text, the dialog has too many apps.
1) Can I explicitly choose the apps shown in the dialog?
2) If not, I can make a custom dialog. If so, can I specifically choose an app to launch and provide it with my intent? for each dialog option, I'd launch a specific app. First item - email, second item - facebook etc.

1) Can I explicitly choose the apps shown in the dialog?
You cannot modify this list that the OS creates with the app chooser. (I'm guessing that all of these apps accept the very common data type "text/plain".)
2) If not, I can make a custom dialog. If so, can I specifically choose an app to launch and provide it with my intent? for each dialog option, I'd launch a specific app. First item - email, second item - facebook etc.
As far as building your own custom list, you need to consider a few points:
You could create Intents that explicitly open the GMail and Facebook apps, but some users don't use these particular apps. Instead you should display apps that accept specific data types (or MIME types).
Email apps have a specific MIME type: "message/rfc822", but some don't use it. You might be safer using "text/plain".
I am unaware of any specific Facebook MIME type, you will have to use "text/plain" anyways. Alternatively, you could use the PackageManager to search every installed appfor the string "facebook", however a third party Facebook app might not have this string in its package name....
If you are going to use the "text/plain" data type then you will end up with the list that the OS already automatically created for you...
What you want to do is not impossible, but it is harder than it sounds. In the end you accidentally might exclude the user's favorite app from your customized list...
(Android has an insightful blog on this subject: Sharing with Intents.)

Related

Android Settings permissions not not acting as they should

I need to ask for permission from the user. One of the permissions I need is ACTION_MANAGE_OVERLAY_PERMISSION and the other is Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION. When asking for it as you can see in the code below, it takes the user to the Settings screen so the user could tick the permission from there.
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);
On some Android phones and Android versions, it takes the user straight to the specific application setting (the app that it is called from) on other devices it opens up the list of applications from which the user has to find the app and then tick the permission. In most cases on Androids lower than 10 it opens up the specific app settings window and when it's 10 or higher, it opens up the list.
Is there a way to make it consistently open the current application setting that is open?
I tried adding:
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName()));
But that did not help either.
And secondly, is there a way to ask for this and other Settings permissions without opening the Settings menu and instead of doing it in a dialog inside the application?
If not then is there a way to ask for multiple Settings permissions one after another because my application requires two Settings type permissions.
EDIT
Here is what I meant by the specific application settings vs the list.
On the left picture, all apps are listed and on the right picture the specific app is opened (happens if you click on the app in the list).
Now in some cases, it directly opens the right picture but mostly it opens the left. Is there a way to force open the right picture at all times?
Is there a way to force open the right picture at all times?
No.
The Settings app usually is modified substantially by the device manufacturer. They can do whatever they want. This includes ignoring the Uri or outright removing third-party access to this screen, where the latter is what the documentation is warning against:
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
If you make your own Android firmware, you could ensure that this Intent action behaves as you want, for whatever devices run your firmware.

Launch any maps app on Android

I want to create an Intent in my Android app that launches a map application with a specified address in response to the user clicking on the button. It is straightforward enough to do this with Google Maps, as is explained here.
However, I was wondering what the correct way to do this would be in order to launch any maps application (i.e., not necessarily Google Maps). This way, if the user prefers a different maps application, it would open in their app of choice instead.
For example, to launch the user's preferred calendar application, one sends an Intent to com.android.calendar, and it opens whichever calendar application is the default, not necessarily Google Calendar.
Use a geo: URI, as stated here. Disappointingly, this does not provide a mechanism for launching directly into turn-by-turn navigation.

How to open dialer screen/make a phone call using GWT phonegap

I have a GWT application that is using phonegap (Cordova) to make it into a mobile app.
I want to make a phone call in a native way (be it Android or iOS) how can I do this using GWT APIs. http://www.openlogic.com/wazi/bid/313383/Using-GWT-and-PhoneGap-for-complex-mobile-applications seems to give some pointers but it seems too complex to understand
useful information in that link is
Access basic functions through special URIs
URI scheme Meaning
href="tel:555-5555"
href="mailto:someone#somewhere?subject=something...&body=some.text..."
href="sms:555-5555?body=some.text..."
href="mailto:someone#somewhere?subject=something...&body=some.text..."
**Meaning**
Open the dialer application to call the given phone number.
Open the SMS application to send an SMS with the given body text to the provided phone number.
Open the email application to write a message to the provided email account with the given subject and body. There are more options, such as sending cc or bcc copies.
In the sample application, I added a couple of hyperlinks to show how to call someone or how to send an SMS. Of course, by using GWT DOM manipulation methods, you could set up the URIs dynamically, instead of hardcoding them as I did in the sample.
Can someone tell me how to make a phonecall/open dialer using GWT
Make a phone call programatically using Libgdx
Look if this answer is good for you.
I'm using libgdx and I'm trying to make able the app to do phonecall using both android and iOS. But, if in Android is simple doing this using the native, in the other hand I cannot find a way to do the same for iOS in java without using objective c.

Android Intent choose set default app

I am working on an android app and when a user clicks on a link and/or file, I want to give them the choice of choosing which app they want to use to open that link and/or file. At the moment it works the way it was intended to, but I am having trouble trying to let the user select a checkbox which lets them choose the default app to open that file with so they won't have to keep selecting it each time. I was thinking of having a checkbox in the dialog and then committing the value of it to the Shared prefs along with the app choice. After that, each time they click that file, the default app will be opened. In essence I am trying to get a dialog like this one,
But I keep getting this one,
Here is the code:
Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, mimeChoice);
startActivity(Intent.createChooser(intent,getActivity().getString(R.string.open_with_title)));
like tambykojak point out, the "The Android OS will take care of this depending on the Intent you've constructed" and thereĀ“s no option for default app. But you will construct your own custom dialog by gettin the apps installed determined by the package:
for example:
Facebook: "com.facebook.katana"; Whatsapp: "com.whatsapp"; Twitter: "com.twitter.android"; Google Playstore: "com.android.vending"; Chrome: "com.android.chrome" etc...
And saving the "default" option in preferences.
More info:
How to force Share Intent to open a specific app?
How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

Extending Android's Default Gmail/Email Applications

I would like to extend the Android platform's default Gmail/Email applications either by plugging into their ContentProvider or by using intent filters. Essentially, I want to be able to scan incoming emails for special rules that will trigger events in my Android application. If scanning emails automatically isn't possible, then I would at least like to add a menu item to the email viewer screen that would allow the user to flag the email content as needing to be scanned.
Does the Gmail/Email applications allow you to extend them in this way?
For future reference, besides finding sample code or reading documentation provided by the author of an application, is there a standard way of finding out what intents are available for my application to use? Like a tool maybe?
Thanks,
Marc
Does the Gmail/Email applications allow you to extend them in this way?
Gmail is closed source, and so it is difficult to know what it does or does not support.
The Email application is not part of the public SDK, so trying to rely upon any ContentProvider it may have (and I don't know that it has one) would be a mistake, as your application is liable to break with subsequent Android updates.
I would at least like to add a menu item to the email viewer screen that would allow the user to flag the email content as needing to be scanned.
The only way to do that assumes Gmail/Email uses Menu#addIntentOptions(), and via Google Code Search, this does not appear to be the case.
You might consider contacting the developers of K9 to see if you could hook into their Android email application.
is there a standard way of finding out what intents are available for my application to use? Like a tool maybe?
Not really. Intent actions are just strings.

Categories