Numéro de téléphone sur écoute :Je veux que mon application soit dans le sélecteur d'application

StackOverflow https://stackoverflow.com//questions/25013754

Question

C'est le même problème que dans Numéroteur personnalisé Android en appuyant sur les liens de numéros de téléphone.J'ai tout fait comme indiqué ici.

Je souhaite que mon application apparaisse dans le sélecteur d'applications lorsqu'un numéro de téléphone est sélectionné.

J'ai

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(); 
    }

}

Et dans 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>

Mais il n'apparaît pas dans le sélecteur d'application.Une idée?

Solution:

Comme @CommonsWare l'a mentionné ci-dessous, il doit s'agir d'une activité.

En outre, android.intent.category.LAUNCHER ça ne marche pas, ça doit être android.intent.category.DEFAULT.

Et vous pouvez oublier (pour ça :-) android:priority et android:exported.

Donc ça marche :

    <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>

avec ceci pour obtenir le numéro de téléphone :

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();
            }
        }    
    }
Était-ce utile?

La solution

Ton <intent-filter> est conçu pour un <activity>.Vous n'aurez aucune chance de l'utiliser avec un <receiver>.De plus, le sélecteur affiche uniquement les activités.Par conséquent, créez un <activity>, et utilisez votre <intent-filter> là (peut-être moins le priority).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top