Hello,
i'm trying to make an app that when you press the "Start Led" button, the Led from Nexus 5 phone will start beeping in a certain color.When i try using the app the notification appears in the top bar (Hello World) but after i turn off the screen the Led doesn't start. Can you please help me?
Main activity:
It says the contructor Notification is deprecated and
The method SetLastestEventInfo is also deprecated
i'm trying to make an app that when you press the "Start Led" button, the Led from Nexus 5 phone will start beeping in a certain color.When i try using the app the notification appears in the top bar (Hello World) but after i turn off the screen the Led doesn't start. Can you please help me?
Main activity:
package com.example.led;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
//import android.content.DialogInterface.OnClickListener;
import android.view.View.OnClickListener;
//import android.contect.View.OnClickListener;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
static final int NOTIFICATION_ID = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(buttonOnClick);
}
public OnClickListener buttonOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(com.example.led.R.drawable.ic_launcher, "Hello", System.currentTimeMillis());
notification.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;
notification.ledARGB = Color.BLUE;
notification.ledOnMS = 1000;
notification.ledOffMS = 300;
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(MainActivity.this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(MainActivity.this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
It says the contructor Notification is deprecated and
The method SetLastestEventInfo is also deprecated