Last active
February 4, 2019 08:54
-
-
Save baobao/770227b172b25a4a9de3219733a8339a to your computer and use it in GitHub Desktop.
Android8未満最小構成ローカル通知
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Handler; | |
import android.support.v4.app.NotificationCompat; | |
import android.support.v4.app.NotificationManagerCompat; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
public class MainActivity extends AppCompatActivity | |
{ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Button buttonNoti = this.findViewById(R.id.button_noti); | |
// ボタンをクリックしたら3秒後に通知 | |
buttonNoti.setOnClickListener(new View.OnClickListener() | |
{ | |
@Override | |
public void onClick(View v) | |
{ | |
new Handler().postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); | |
builder.setSmallIcon(R.drawable.ic_launcher_foreground); | |
NotificationManagerCompat manager = NotificationManagerCompat.from(getApplicationContext()); | |
manager.notify(0, builder.build()); | |
} | |
}, 3000); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment