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

来源:互联网 发布:mac book pro 2018 编辑:程序博客网 时间:2024/04/19 06:26
<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);    }以上是震动提醒和亮屏显示,一下是亮屏后显示的Activitypublic 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(); }@Overrideprotected void onNewIntent(Intent intent) {    getData(intent);    super.onNewIntent(intent);    Log.i("---messagechat", "onnewintent_show"); }}
阅读全文
0 0
原创粉丝点击