我正在创建一个广播接收器应用程序。因为我得到了以下错误
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();
}
}
}
}
答案 0 :(得分:0)
使用
Toast.makeText(context, "Getting Call from "+phoneNumber, Toast.LENGTH_LONG).show();
答案 1 :(得分:0)
而不是传递this
,传递context
,它将解决您的问题。