التنصت على رقم الهاتف:أريد أن يكون تطبيقي في منتقي التطبيق

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

سؤال

إنها نفس المشكلة كما في الروبوت طالب مخصص على التنصت الروابط رقم الهاتف.لقد فعلت كل شيء كما هو مذكور هناك.

أريد أن يظهر تطبيقي في منتقي التطبيق ، عند النقر على رقم هاتف.

لدي

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

}

وفي الروبوتواضح.شمل:

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

لكنها لا تظهر في منتقي التطبيق.أي فكرة?

الحل:

كما @ كومونسوار المذكورة أدناه ، فإنه يحتاج إلى أن يكون النشاط.

علاوة على ذلك, 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