当接收到消息时,亮屏震动提醒

<uses-permission android:name="android.permission.WAKE_LOCK" />
解锁屏权限
<uses-permission android:name="android.permission.VIBRATE" />
震动权限

msgGetRemind();
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |               PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
wl.acquire();
wl.release();
Intent alarmIntent = new Intent(context, WindowMessageActivity.class);            alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
turnTo(alarmIntent);
context.startActivity(alarmIntent);

//震动(需要权限)

private void msgGetRemind() {
        Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
        vib.vibrate(500);
    }

以上是震动提醒和亮屏显示,一下是亮屏后显示的Activity
public class WindowMessageActivity extends ActivityEx {
    private TextView textName;
    private Bundle bundle = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        final Window win = getWindow();
               win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|  WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
setContentView(R.layout.activity_window_message);
Log.i("---messagechat", "oncreate_show");
textName = (TextView) findViewById(R.id.local_screen_message_content);
getData(null);
super.onCreate(savedInstanceState);
}

public void onClick(View view) {
Intent intent = new Intent(this,MessageChat.class);
intent.putExtras(bundle);
startActivity(intent);
this.finish();
}

private void getData(Intent intent) {
  Intent mIntent = null;
  if (intent != null) {
      mIntent = intent;
  } else {
       mIntent = getIntent();
  }
     bundle = mIntent.getExtras();
 }

@Override
protected void onNewIntent(Intent intent) {
    getData(intent);
    super.onNewIntent(intent);
    Log.i("---messagechat", "onnewintent_show");
 }
}

猜你喜欢

转载自blog.csdn.net/qq_35920289/article/details/72674094
0条评论
添加一条新回复