Android-通知,设备未唤醒,无声音或振动

Android-通知,设备未唤醒,无声音或振动,android,notifications,xamarin.android,Android,Notifications,Xamarin.android,我正在尝试为我的应用程序创建一个通知,用于唤醒设备、播放声音和振动。下面是我正在使用的代码。我在SO中发现了几个这样的问题,并尝试了其中的代码。但是通知仍然没有唤醒设备,没有声音或振动。通知显示得很好。有人能帮我找出代码的错误吗 Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification); NotificationCompat.Builder builder = new Notific

我正在尝试为我的应用程序创建一个通知,用于唤醒设备、播放声音和振动。下面是我正在使用的代码。我在SO中发现了几个这样的问题,并尝试了其中的代码。但是通知仍然没有唤醒设备,没有声音或振动。通知显示得很好。有人能帮我找出代码的错误吗

Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .SetAutoCancel(true) 
            .SetContentIntent(resultPendingIntent) 
            .SetContentTitle("Title")
            .SetSmallIcon(Resource.Drawable.Icon) 
            .SetContentText(String.Format("Message!"));
        Notification notification =builder.Build();
        notification.Sound = alarmSound;
        notification.Defaults = NotificationDefaults.Sound| NotificationDefaults.Vibrate | NotificationDefaults.Lights;
        NotificationManager nManager = (NotificationManager)GetSystemService(Context.NotificationService);
        nManager.Notify(0, notification);

在我正在构建的一个应用程序中,我也遇到了类似的情况。我想叫醒电话,关掉键盘。我99%肯定这不是一条路,但可能对我们双方都有帮助。下面的代码忠实地打开设备,按我的要求关闭键盘,并播放警报。然而,它往往会让手机处于一种永远不会让手机将屏幕恢复睡眠的状态,随后的报警只会唤醒设备,但拒绝播放任何报警声音

这就是服务 这就是活动
   @Override
   public void onStart(Intent intent, int startId) {
      PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
      WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
      wakeLock.acquire();

      KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); 
      KeyguardLock keyguardLock =  keyguardManager.newKeyguardLock("TAG");
      keyguardLock.disableKeyguard();

      Bundle bundle = intent.getExtras();
      String why = bundle.getString("WHY");
      Log.d("RemindMe","Wake the hell up "+why);

      Intent i = new Intent(getApplicationContext(), WakeUpShowReminder.class);
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      i.putExtras(bundle);
      startActivity(i);

   }
public class WakeUpShowReminder extends Activity {


    private MediaPlayer mMediaPlayer;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_reminder);

    Button stop = (Button) findViewById(R.id.stop_alarm);
    stop.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            stopPlaySound();
            finish();

        }
    });

    String why = "";
    String sound;
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        why = extras.getString("WHY");
        sound = extras.getString("MEDIA");
    }
    else {
        why = "WTF";
        sound="content://media/internal/audio/media/44";
    }

    TextView reason = (TextView) findViewById(R.id.reason);
    reason.setText(why);


    playSound(this, Uri.parse(sound));
}


@Override
protected void onPause() {
    super.onPause();
    mMediaPlayer.stop();
}

@Override
protected void onResume() {
    super.onResume();
}

@Override
public void onDestroy() {
    super.onDestroy();
    mMediaPlayer.stop();
}

private void stopPlaySound() {
    mMediaPlayer.stop();
}

private void playSound(Context context, Uri alert) {
        mMediaPlayer = new MediaPlayer();
        try {
            mMediaPlayer.setDataSource(context, alert);
            final AudioManager audioManager = (AudioManager) context
                    .getSystemService(context.AUDIO_SERVICE);
            if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
            }
        } catch (IOException e) {
            System.out.println("OOPS");
            Log.d("REMINDME","Media Error "+e.toString());
        }
    }

}