Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Notification;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity
- {
- Button notify;
- EditText e;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- notify= (Button) findViewById(R.id.button);
- e= (EditText) findViewById(R.id.editText);
- notify.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- Intent intent = new Intent(MainActivity.this, SecondActivity.class);
- PendingIntent pending = PendingIntent.getActivity(MainActivity.this, 0, intent,
- 0);
- Notification noti = new
- Notification.Builder(MainActivity.this).setContentTitle("New
- Message").setContentText(e.getText().toString())
- .setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pending).build();
- NotificationManager manager = (NotificationManager)
- getSystemService(NOTIFICATION_SERVICE);
- noti.flags |= Notification.FLAG_AUTO_CANCEL;
- manager.notify(0, noti);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement