電話番号をタップする:私は自分のアプリをアプリケーションセレクターに入れたいと思っています

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

質問

それはと同じ問題です 電話番号のリンクをタップすると、Androidのカスタムダイヤラ.私はそこに記載されているようにeverthingsをしました。

電話番号がタップされたときに、自分のアプリをアプリケーションセレクターに表示したい。

私は持っています

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