using android dialer in 3rd party app - android

guys. I am trying to build a voip app for android. I want to make use of the built-in android phone dialer. Can you guys give me some reference to it. I have been googling with no luck. Thanks

What you need to do is setup an Intent filter on the Activity you want to make the call. You do this inside your AndroidManifest.xml file. Modify your activity definition to include this intent filter:
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
Note: there are some alternative ways to call people (which can be seeing in the AndroidManifest.xml of the source I linked bellow, however this is the main one
Adding this will give the user the option to use your app when making a call, and this can be set as the default app if the user wishes.
You can then get the phone number by adding something like this code to your onCreate() method of your activity:
final Intent i = getIntent();
final Uri phoneUri = i.getData();
phoneUri now contains tel:00000000000 and you can easily get the number out of the Uri object
If you have problems in to future take a look at the android source. I got these bits of code from the phone app source if you want to take a look.

This should open the dialer with new special permissions:
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:0000000000"));
startActivity(i);
That should open the dialer with the required telephone number already inserted.

Related

Intent filter with navigation component to Receiving image data from other app

My Android application uses the navigation component to navigate between fragments.
And the project only has a single Activity and all the others are fragments.
My application is a social media application. I want to share an image from my phone gallery with my application. When a user clicks the share button on the gallery, my application wants to show in the sharing dialogue.
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
I have used this intent filter on my main activity, and then the share dialogue displays my app.
But my requirement is, I want to get that image on my fragment. How to use this intent filter on my fragment.
Can I use the deep-link for that? but what value will give on the uri section?.
<deepLink
app:uri="android.intent.category.DEFAULT"
app:action="android.intent.action.SEND"
app:mimeType="image/*"
/>
I tried this. but not working.
In short, I want to receive the data (image) in my fragment. How can I achieve this using the Navigation component?
To explain why it's not working for you, let's examine this piece of code,
app:uri="android.intent.category.DEFAULT"
app:action="android.intent.action.SEND"
app:mimeType="image/*"/>
app:uri attribute requires a scheme and a host e.g., https://example.com (it could be any made up uri like myapp://example.com) , but you are passing a category string to it.
To fix this, just pass "myapp://example.com" or any made up uri you can think of. That will work. Now, the important bit - you must add deeplink tag to the fragment which receives the image. Now, your code will work, however, if your application is already running, it will not receive the image from shared intent. For that, you need to override onNewIntent method in you activity and call NavController.handleDeepLink(intent), you have to pass the intent received in onNewIntent method to it, followed by a call to super.onNewIntent(). Now, your app can receive image from any application that can share it, whether your application is already running, or started by the intent itself.

Which intent-filter scheme use for Youtube in Android

I want to register an intent-filter exclusively for the share in the Youtube app.
So far I'm able to receive the intent from Youtube successfully. The problem is my intent filer is not specific enough. My app is displayed as available for other share features in other apps (not only for Youtube).
This is what I'm using right now:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
I have reviewed several questions (most are much like this one) the problem is there is an inaccuracy in those types of answers:
<data android:host="www.youtube.com" ... />
According to the data documentation the scheme most be provided in order for the host to be valid. So in those answers simply adding the host, doesn't make the intent-filter specific for Youtube, because there is no scheme, therefore, the host is ignored.
So I have been trying to figure this out by using the available methods of the intent when the Activity is started:
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
for (String key : bundle.keySet()) {
Log.d("KEY", key);
}
//The above loop will log
//... D/KEY: android.intent.extra.SUBJECT
//... D/KEY: android.intent.extra.TEXT
//This is are the same keys than above, but using the available constants
String subject = getIntent().getStringExtra(Intent.EXTRA_SUBJECT);
String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
//The subject is the video title
Log.d("SUBJECT", subject);
//The text is the video url, example: https://youtu.be/p6qX_lg4wTc
Log.d("TEXT", text);
//Action is consistent with the intent-filter android.intent.action.SEND
Log.d("ACTION", intent.getAction());
//This is consistent with the intent-filter data mime type text/plain
Log.d("TYPE", intent.getType());
/*
This is the problem.
The scheme is null (that is why I'm using String value of).
*/
Log.d("scheme", String.valueOf(intent.getScheme()));
So, when the available information in the intent is checked, everything seems to be in order, but not the scheme. So, based on what is gotten, I have done some blind attempts to figure it out:
<data android:scheme="http" android:mimeType="text/plain"/>
//I'm adding youtu.be here because is the url format in the text extra
<data android:scheme="http" android:host="youtu.be" android:mimeType="text/plain"/>
Adding http or https won't work, it makes the app is no longer available in the chooser. This means it will neither work the other attempt adding the host.
Doe's anybody knows how to create an intent-filter exclusively for Youtube share?
PS: I know I could validate the url to see if it match a Youtube url, but having my app in every chooser matching SEND doesn't seem user friendly
tldr: You can't make an intent-filter exclusively for Youtube app, the intent for sharing a video doesn't have anything to narrow it down.
So I got really obsessed about this, the only way to find out seems to check the Youtube app code. I found the apk here and then decompile with this. I think I found the code in this file (the text error seems to confirm my finding).
So, if my deductions are correct, then what is going on is Youtube app make an intent with no scheme or nothing else to make it specific. It only uses SEND.
This not answer your specific question, but I think achieves the same you want.
You can use the youtube android player api library and the YouTubeIntents
Like this:
Intent youtubeIntent =
YouTubeIntents.createPlayVideoIntent(getApplicationContext(), VIDEO_ID);
startActivity(youtubeIntent);

android development: how does my intent / icon get added to user's list like other social media in Android

I would like to allow users to highlight text and post it to my web site.
Is there a way to create an Android Intent running as a service which will show up on the social media / share list that appears in the Android system?
You know, when the user selects a picture and then the three dotted share icon appears and gives a list? How can I get my application's intent and icon added to the list just as the Twitter, FB etc. ones that show up?
To receive data from an external application in your application vis Share functionality, you need to create an activity in your application which will accept the incoming data. Add the following details in AndroidManifest.xml for the Activity which will accept the data:
<activity android:name=".ui.MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
So , now if any application, shares a single image, your application will be visible in the list, and if the user selects your application, ui.MyActivity activity will be launched. You can change or add multiple mimeType as per your requirement.
Also, you can add/change action as MULTIPLE_SEND to receive multiple shared files.
Once this is done, in onCreate() method of your activity, you can fetch the data in the following manner:
void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
//Play with the data, as per your need
...
}
You can get more details regarding this, in the Official Documentation

"android.intent.extra.STREAM"

While doing some R&D I found a code using the following statement
Uri uri = (Uri) getIntent().getExtras().get("android.intent.extra.STREAM");
I have scanned the whole project to find whether the activity was called from any other activity, but did'nt find any. Can any one tell me what will this statement return and what is the statement "android.intent.extra.STREAM" doing in the code, whether it is a constant, if yes what is its value?
Thanks in advance.
Happy Coding
This statement will return the extra named "android.intent.extra.STREAM". Whatever activity issued the intent set that value, and there's no easy way to tell what that data is without seeing how it is used, or where/how it was set. Don't forget that the intent could be issued by any activity or application.
Found your answer:
public static final String EXTRA_STREAM Since: API Level 1
A content: URI holding a stream of data associated with the Intent, used with
ACTION_SEND to supply the data being sent.
Constant Value: "android.intent.extra.STREAM"
So, I would posit that it's the result of poor coding (using the value rather than the defined static constant) for an intent designed to share images. The intent includes the Intent.EXTRA_STREAM extra as the data stream for the image (in this case) to be shared. IMO, the code should have been:
Uri uri = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM);
But regardless, it appears to be the documented/standardized way of attaching a binary datastream to an intent.
Continued research seems to indicate that it adds Campyre (a Campfire client) as a "Share" option. So from Gallery, if you choose to Share an image, Campyre shows up as one of the options.
Google and the Android dev site are your friends. It took me all of about 2 minutes total to get all that information. Not as long as it took to type the replies and subsequent edits...
More elaboration:
Here is the relevant section from AndroidManifest.xml:
<activity android:name=".ShareImage"
android:theme="#android:style/Theme.Dialog"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
Which indicates that the Activity can handle Intents for sharing where the item being shared is an image.

How to implement my very own URI scheme on Android

Say I want to define that an URI such as:
myapp://path/to/what/i/want?d=This%20is%20a%20test
must be handled by my own application, or service. Notice that the scheme is "myapp" and not "http", or "ftp". That is precisely what I intend: to define my own URI schema globally for the Android OS. Is this possible?
This is somewhat analogous to what some programs already do on, e.g., Windows systems, such as Skype (skype://) or any torrent downloader program (torrent://).
This is very possible; you define the URI scheme in your AndroidManifest.xml, using the <data> element. You setup an intent filter with the <data> element filled out, and you'll be able to create your own scheme. (More on intent filters and intent resolution here.)
Here's a short example:
<activity android:name=".MyUriActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="path" />
</intent-filter>
</activity>
As per how implicit intents work, you need to define at least one action and one category as well; here I picked VIEW as the action (though it could be anything), and made sure to add the DEFAULT category (as this is required for all implicit intents). Also notice how I added the category BROWSABLE - this is not necessary, but it will allow your URIs to be openable from the browser (a nifty feature).
Complementing the #DanielLew answer, to get the values of the parameteres you have to do this:
URI example: myapp://path/to/what/i/want?keyOne=valueOne&keyTwo=valueTwo
in your activity:
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String valueOne = uri.getQueryParameter("keyOne");
String valueTwo = uri.getQueryParameter("keyTwo");
}
I strongly recommend that you not define your own scheme. This goes against the web standards for URI schemes, which attempts to rigidly control those names for good reason -- to avoid name conflicts between different entities. Once you put a link to your scheme on a web site, you have put that little name into entire the entire Internet's namespace, and should be following those standards.
If you just want to be able to have a link to your own app, I recommend you follow the approach I described here:
How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?
Another alternate approach to Diego's is to use a library:
https://github.com/airbnb/DeepLinkDispatch
You can easily declare the URIs you'd like to handle and the parameters you'd like to extract through annotations on the Activity, like:
#DeepLink("path/to/what/i/want")
public class SomeActivity extends Activity {
...
}
As a plus, the query parameters will also be passed along to the Activity as well.
As the question is asked years ago, and Android is evolved a lot on this URI scheme.
From original URI scheme, to deep link, and now Android App Links.
Android now recommends to use HTTP URLs, not define your own URI scheme. Because Android App Links use HTTP URLs that link to a website domain you own, so no other app can use your links. You can check the comparison of deep link and Android App links from here
Now you can easily add a URI scheme by using Android Studio option: Tools > App Links Assistant.
Please refer the detail to Android document: https://developer.android.com/studio/write/app-link-indexing.html

Categories

Resources