package nodomain.freeyourgadget.gadgetbridge; import android.app.NotificationManager; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.support.v4.app.NotificationCompat; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import java.util.UUID; public class ControlCenter extends ActionBarActivity { // SPP Serial Device UUID private static final UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); Button sendButton; Button testNotificationButton; Button startServiceButton; EditText editTitle; EditText editContent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_controlcenter); editTitle = (EditText) findViewById(R.id.editTitle); editContent = (EditText) findViewById(R.id.editContent); startServiceButton = (Button) findViewById(R.id.startServiceButton); startServiceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class); startIntent.setAction(BluetoothCommunicationService.ACTION_STARTBLUETOOTHCOMMUNITCATIONSERVICE); startService(startIntent); } }); sendButton = (Button) findViewById(R.id.sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class); startIntent.setAction(BluetoothCommunicationService.ACTION_SENDBLUETOOTHMESSAGE); startIntent.putExtra("notification_title", editTitle.getText().toString()); startIntent.putExtra("notification_content", editTitle.getText().toString()); startService(startIntent); } }); testNotificationButton = (Button) findViewById(R.id.testNotificationButton); testNotificationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { testNotification(); } }); Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); startActivity(enableIntent); IntentFilter filter = new IntentFilter(); filter.addAction("nodomain.freeyourgadget.gadgetbridge.NOTIFICATION_LISTENER"); } private void testNotification() { NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this); ncomp.setContentTitle("Test Notification"); ncomp.setContentText("This is a Test Notification from Gadgetbridge"); ncomp.setTicker("This is a Test Notification from Gadgetbridge"); ncomp.setSmallIcon(R.drawable.ic_launcher); ncomp.setAutoCancel(true); nManager.notify((int) System.currentTimeMillis(), ncomp.build()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { //Intent intent = new Intent(this, SettingsActivity.class); //startActivity(intent); return true; } return super.onOptionsItemSelected(item); } }