0

我正在创建一个 Broadcat 接收器应用程序。因为我收到以下错误

The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (MyPhoneCall, String, int)

Java代码:

package com.example.myphonecall;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class MyPhoneCall extends BroadcastReceiver {

    @
    Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            String state = extras.getString(TelephonyManager.EXTRA_STATE);
            Log.w("MY_DEBUG_TAG", state);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                String phoneNumber = extras
                    .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                //Log.w("MY_DEBUG_TAG", phoneNumber);
                Toast.makeText(this, "Getting Call from " + phoneNumber, Toast.LENGTH_LONG).show();
            }
        }
    }
}
4

2 回答 2

0

利用

Toast.makeText(context, "Getting Call from "+phoneNumber, Toast.LENGTH_LONG).show();
于 2013-05-13T05:44:05.170 回答
0

而不是通过this,通过context,它将解决您的问题。

于 2013-05-13T05:45:24.767 回答