如果收到sms,如何在android中执行操作?
以下代码无效:
public class Sms extends BroadcastReceiver{
AudioManager audioManager;
public void onReceive(Context context, Intent arg1) {
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
答案 0 :(得分:0)
您需要在AndroidManifest.xml中声明接收器,如下所示:
<receiver android:name=".Sms">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
注意优先级 - 这将允许此接收者(首先)处理收到的短信