gpt4 book ai didi

android - android的蓝牙通知代码

转载 作者:行者123 更新时间:2023-11-29 18:09:51 25 4
gpt4 key购买 nike

我正在为我的拼贴画完成我的最终项目,我一直在寻找适用于 android 的蓝牙通知代码。我需要代码在我的蓝牙打开或关闭时通知我

最佳答案

OK then do it like that when you bluetooth is on or off


private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

if (BluetoothDevice.ACTION_FOUND.equals(action)) {

int icon = R.drawable.nishansahib1; // icon from resources
CharSequence tickerText = "SatShreeAkal"; // ticker-text
long when = System.currentTimeMillis(); // notification time
//Context context = getApplicationContext(); // application Context
CharSequence contentTitle = ""; // message title
//

CharSequence contentText= "YPUR BLUETOOTH IS ON OR OFF"; // message text
final int NOTIF_ID = 1234;
Intent notificationIntent = new Intent(context, your classname);//if u want to call a class

notificationIntent.putExtra("DISPLAY",contentText);//if u want to pass intent
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

notification.defaults = Notification.DEFAULT_SOUND;
notofManager.notify(NOTIF_ID,notification);
}

关于android - android的蓝牙通知代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11356726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com