Tapping phone number: I want my App to be in the application chooser
-
21-12-2019 - |
Question
It is same problem as in Android custom dialler on tapping phone number links. I did everthings as stated there.
I want my app appear in the application chooser, when a phone number is tapped.
I have
package com.example.editcall;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class OutgoingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.d(OutgoingCallReceiver.class.getSimpleName(), intent.toString() + ", call to: " + phoneNumber);
Toast.makeText(context, "Outgoing call catched: " + phoneNumber, Toast.LENGTH_LONG).show();
}
}
And in AndroidManifest.xml:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<receiver
android:name=".OutgoingCallReceiver"
android:exported="true" >
<intent-filter android:priority="100" >
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
</receiver>
But it does not show up in the application chooser. Any idea?
Solution:
As @CommonsWare mentioned below, it needs to be an activity.
Furthermore, android.intent.category.LAUNCHER
does not work, it must be android.intent.category.DEFAULT
.
And you can forget (for this :-) about android:priority
and android:exported
.
So, this works:
<activity android:name=".ui.SearchActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
</activity>
with this to get the phone number:
public class SearchActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String calledNumber = null;
String inputURI = this.getIntent().getDataString();
if (inputURI != null) {
Uri uri = Uri.parse(Uri.decode(inputURI));
if (uri.getScheme().equals("tel")) {
calledNumber = uri.getSchemeSpecificPart();
}
}
}
Solution
Your <intent-filter>
is designed for an <activity>
. You will have no luck using it with a <receiver>
. Moreover, the chooser only shows activities. Hence, create an <activity>
, and use your <intent-filter>
there (perhaps minus the priority
).