Intent filter does not work to invoke the screen

I am designing a user call screen to display information, such as caller’s address book information, on the screen during a telephone call. My application will start when the user clicks the call button using the Intent Filter , after which I will extract other information from the address book and add it to the screen.

My problem is that when the call button is pressed, my activity does not start. Is my filter correct? Is it possible to intercept an Intent phone call? Share your knowledge of call event handling.

My Intent Filter shown below.

 <activity android:name=".MyCallingScreen"> <intent-filter android:priority="100"> <action android:name="android.intent.action.CALL_BUTTON" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="tel" /> </intent-filter> </activity> 
+6
source share
2 answers

In your case, try changing your code as follows:

 <intent-filter android:priority="100"> <action android:name="android.intent.action.CALL_BUTTON" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> 

It works for me if I click on the call button.

Try using the following code to intercept a call:

 <activity> <intent-filter> <action android:name="android.intent.action.CALL_PRIVILEGED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> 

For HTC, some changes are there:

 <activity> <intent-filter> <action android:name="android.intent.action.CALL_PRIVILEGED" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.item/phone" /> <data android:mimeType="vnd.android.cursor.item/phone_v2" /> <data android:mimeType="vnd.android.cursor.item/person" /> </intent-filter> </activity> 

The intention with the action android.intent.action.CALL_PRIVILEGED is called up when calling from the phonebook as follows: Phonebook-> Contact-> Phone number Long click → Select a call from the drop-down menu.

+4
source

I'm not sure that you can replace the call screen, but it is relatively simple to intercept any outgoing call. You declare the recipient in your manifest:

  <receiver android:name="com.mystuff.CallInterceptor" android:exported="true"> <intent-filter> <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> </intent-filter> </receiver> 

and you create a Java class for this interceptor:

 public class CallInterceptor extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (!intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { return; } String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); //do stuff using the number //assuming you do nothing too bad the call will happen and the regular //call screen comes up - but you can bring up another activity on top of it //for example shwing address info } } 
0
source

Source: https://habr.com/ru/post/902828/


All Articles