0
public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener {
private TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new TextToSpeech(this,this);
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
if(state== TelephonyManager.CALL_STATE_RINGING){
tts.speak(incomingNumber+" calling", TextToSpeech.QUEUE_FLUSH, null);
Toast.makeText(getApplicationContext(),"Phone is Ringing : "+incomingNumber,Toast.LENGTH_LONG).show();
}
}
};
}
@Override
public void onInit(int status) {
}
}
但功能speak(String text, int queueMode, HashMap params)
已在API級別21中棄用。我該如何解決此問題?android - 如何使用TextToSpeech與API 21