1

そのコードを使用して、標準のダイヤルパッドからの呼び出しをキャッチしてみます:

        <action android:name="android.intent.action.CALL" />
        <data android:scheme="tel" />
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.CALL_PRIVILEGED" />
   </intent-filter>


</activity>

ユーザーが標準の電話ダイヤルパッドからダイヤルすると、すべて問題なく、アプリが開きました。しかし、どのユーザーがダイヤルしたか、電話番号を取得する方法がわかりません。PhonePadActivity アクティビティ onCreate ブロック内のそのコード:

Intent intent = getIntent();

String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(this, "Call was made to-->>" + number, 5000).show();

最後にnullを返します:(

ブロードキャストレシーバーを使用しようとしました:

マニフェストで:

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

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />

これはクラス DialBroadcastReceiver です。

package com.myapps.android;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class DialBroadcastReceiver extends BroadcastReceiver {
    private static final String THIS_FILE = "PhonePadActivity";

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Log.e(THIS_FILE,"In onReceive()");

        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
             String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

             Log.e(THIS_FILE,"Number is: "+number);

        }
    }

}

ただし、ユーザーがダイヤルを押すと、nodが発生したことをログに記録します

4

4 に答える 4

3

これは私のために働きます:

マニフェスト:

<intent-filter>
    <action android:name="android.intent.action.CALL"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <action android:name="android.intent.action.CALL_PRIVILEGED"/>
    <data android:scheme="tel"/>
</intent-filter>

活動中:

String inputURI = this.getIntent().getDataString();
if (inputURI != null) {
    Uri uri = Uri.parse(Uri.decode(inputURI));
    if (uri.getScheme().equals("tel")) {
        String calledNumber = uri.toString();
    }
}
于 2012-12-30T11:12:35.547 に答える
2

間違ったコードで番号を取得しています。交換:

Intent intent = getIntent();

String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(this, "Call was made to-->>" + number, 5000).show();

と:

Uri data = getIntent().getData(); 
if (data != null && ("tel".equals(data.getScheme()))) { 
    String number = PhoneNumberUtils.getNumberFromIntent(getIntent(), this); 
    if (number != null) { 
      Toast.makeText(this, "Call was made to-->>" + number, 5000).show();
    } 
}
于 2012-12-30T12:10:43.553 に答える
1
  • マニフェストのインテント フィルター宣言に追加<intent-filter android:priority="9999">して、先頭にいることを確認します
  • com.myapps.androidマニフェストのレシーバー宣言のプロパティから -part を削除しandroid:nameます (つまり、次のようにする必要がありますandroid:name=".DialBroadcastReceiver") 。
于 2012-12-30T11:11:01.120 に答える