Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GCM turn on 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.

like image 468
Amarnath Avatar asked Jan 07 '13 11:01

Amarnath


People also ask

How to integrate GCM with Android push notifications?

Implement an Android Client app to register with GCM, send the registration id to your push notification server and manage the notifications sent from your server via GCM. Implement a server side API to get and store registration ids from the client app and optionally provide an Admin panel to send push notification from.

How do I use GCM?

Send data from your server to your users' devices, and receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to client applications running on target devices, and it is completely free.

What is GCM (Google Cloud Messaging)?

GCM (Google Cloud Messaging) documentation says: Send data from your server to your users' devices, and receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to client applications running on target devices, and it is completely free.

How to turn on flash light programatically in Android?

How to turn on Flash light programmatically in android? This example demonstrates how do I turn on Flash light programatically in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.


1 Answers

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;
like image 76
Dixit Patel Avatar answered Nov 05 '22 15:11

Dixit Patel