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

<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");
 }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值