Android GCM打开Lights [英] Android GCM turn on Lights

查看:97
本文介绍了Android GCM打开Lights的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个Android项目。我可以成功接收推送通知。

如何在收到推送通知时打开灯光?



此外,当收到推送通知时,我还需要振动移动设备。 >

有关更多信息,请参阅此链接



为清单文件添加权限

 < uses-permission android:name =android。 permission.VIBRATE>< /使用的许可> 

编辑
// 1.获取NotificationManager

  String ns = Context.NOTIFICATION_SERVICE; 
NotificationManager mNotificationManager =(NotificationManager)getSystemService(ns);

// 2.实例化通知

  int icon = R.drawable.notification_icon; 
CharSequence tickerText =Hello;
long when = System.currentTimeMillis();
通知通知=新通知(icon,tickerText,何时);

// 3.定义通知的扩展消息和意图

  Context context = getApplicationContext(); 
CharSequence contentTitle =我的通知;
CharSequence contentText =Hello World!;
Intent notificationIntent = new Intent(this,MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent);

// 4.将通知传递给NotificationManager

  private static final int HELLO_ID = 1; 
mNotificationManager.notify(HELLO_ID,通知);

// ------------------- ---
//添加声音
// ----------------------
// a。默认声音


  notification.defaults | = Notification.DEFAULT_SOUND; 

// b。来自SD卡的自定义声音

  notification.sound = Uri.parse(file:///sdcard/notification/SOUND.mp3 ); 

// ------------------- ---
//添加振动
// ----------------------
// a。默认振动


  notification.defaults | = Notification.DEFAULT_VIBRATE; 

// b。自定义振动

  long [] vibrate = {0,100,200,300}; 
notification.vibrate = vibrate;

// ------------------- -----
//添加闪光灯
// ------------------------
//一个。默认灯

  notification.defaults | = Notification.DEFAULT_LIGHTS; 

// b。自定义灯光

  notification.ledARGB = 0xff00ff00; 
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags | = Notification.FLAG_SHOW_LIGHTS;


I'm doing a project in Android. I can successfully receive push notifications.

How to turn on the lights when I receive the push notification?

And also I need to vibrate my mobile when receiving the push notification.

解决方案

For More Information refer this Link.

Add permission to your manifest file

<uses-permission android:name="android.permission.VIBRATE"></uses-permission>

EDIT // 1. Get a reference to the NotificationManager

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

// 2. Instantiate the Notification

int icon = R.drawable.notification_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);

// 3. Define the Notification's expanded message and Intent

Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

// 4. Pass the Notification to the NotificationManager

private static final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);

// ---------------------- // Add Sound // ---------------------- // a. Default sound

notification.defaults |= Notification.DEFAULT_SOUND;

// b. Custom sound from SD card

notification.sound = Uri.parse("file:///sdcard/notification/SOUND.mp3");

// ---------------------- // Add Vibration // ---------------------- // a. Default vibration

notification.defaults |= Notification.DEFAULT_VIBRATE;

// b. Custom vibration

long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;

// ------------------------ // Add Flashing Lights // ------------------------ // a. Default lights

notification.defaults |= Notification.DEFAULT_LIGHTS;

// b. Custom lights

notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;

这篇关于Android GCM打开Lights的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆