Нажатие на номер телефона:Я хочу, чтобы мое приложение было в списке приложений

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

Вопрос

Это та же проблема, что и в Пользовательский номеронабиратель Android при нажатии на ссылку с номером телефона.Я сделал все, как там написано.

Я хочу, чтобы мое приложение появлялось в средстве выбора приложений при нажатии на номер телефона.

У меня есть

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

}

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

Но в выборе приложений он не отображается.Есть идеи?

Решение:

Как упоминалось ниже @CommonsWare, это должно быть действие.

Более того, android.intent.category.LAUNCHER не работает, должно быть android.intent.category.DEFAULT.

И можно забыть (по этому :-) о android:priority и android:exported.

Итак, это работает:

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

с помощью этого, чтобы получить номер телефона:

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();
            }
        }    
    }
Это было полезно?

Решение

Твой <intent-filter> предназначен для <activity>.Вам не удастся использовать его с <receiver>.Более того, селектор показывает только деятельность.Следовательно, создайте <activity>, и используйте свой <intent-filter> там (возможно, минус priority).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top