gpt4 book ai didi

Android GCM 开灯

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:37:58 25 4
gpt4 key购买 nike

我正在 Android 中做一个项目。我可以成功接收推送通知。

收到推送通知后如何开灯?

而且我还需要在收到推送通知时让我的手机振动。

最佳答案

有关更多信息,请参阅此 Link .

为您的 list 文件添加权限

<uses-permission android:name="android.permission.VIBRATE"></uses-permission>

编辑

// 1. Get a reference to the NotificationManager

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

// 2. Instantiate the Notification

int icon = R.drawable.notification_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);

// 3. Define the Notification's expanded message and Intent

Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

// 4. Pass the Notification to the NotificationManager

private static final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);


// ----------------------
// Add Sound
// ----------------------
// a. Default sound

notification.defaults |= Notification.DEFAULT_SOUND;

// b. Custom sound from SD card

notification.sound = Uri.parse("file:///sdcard/notification/SOUND.mp3");


// ----------------------
// Add Vibration
// ----------------------
// a. Default vibration

notification.defaults |= Notification.DEFAULT_VIBRATE;

// b. Custom vibration

long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;

// ------------------------
// Add Flashing Lights
// ------------------------
// a. Default lights

notification.defaults |= Notification.DEFAULT_LIGHTS;

// b. Custom lights

notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;

关于Android GCM 开灯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14195067/

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