int icon = R.drawable.icon;
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Countdown Complete!";
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent();
Notification notification = new Notification(icon, "is completed!", System.currentTimeMillis());
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notificationManager.notify(myCountDown.getId(), notification);
Run Code Online (Sandbox Code Playgroud)
这个代码在我的Android应用程序中,我收到通知但没有声音或振动.
我已经在多部手机上进行了测试,声音和振动都在设置中打开和关闭.我也确定我要求在android清单中使用振动许可但我仍然只收到通知......
我也尝试过:
notification.defaults = Notification.DEFAULT_ALL;
Run Code Online (Sandbox Code Playgroud)
和
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
Run Code Online (Sandbox Code Playgroud)
如何在通知中获得声音和振动?
SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);
SqlCommand command = new SqlCommand();
command.CommandText =
"INSERT INTO [Users]
VALUES (Username=@username, Firstname=@firstname
, Lastname=@lastname, ProfilePic=NULL, Bio=@bio, Email=@email
, EmailIsVerified=@emailverified, Hash=@hash, CompanyID=@companyid)";
command.Parameters.AddWithValue("@username", m_username);
command.Parameters.AddWithValue("@firstname", m_firstname);
command.Parameters.AddWithValue("@lastname", m_lastname);
command.Parameters.AddWithValue("@bio", m_bio);
command.Parameters.AddWithValue("@email", m_email);
command.Parameters.AddWithValue("@emailverified", (m_emailIsVerified ? "yes" : "no"));
command.Parameters.AddWithValue("@hash", m_hash);
command.Parameters.AddWithValue("@companyid", m_companyID);
command.CommandType = CommandType.Text;
command.Connection = sqlConnection;
sqlConnection.Open();
command.ExecuteNonQuery();
sqlConnection.Close();
Run Code Online (Sandbox Code Playgroud)
使用上面的代码我得到"语法错误near ="错误.我做错了什么?
我有以下代码:
template <typename T>
class Node{
public:
Node<T>(T data){
this->data = data;
}
T data;
Node<T> left;
Node<T> right;
};
Run Code Online (Sandbox Code Playgroud)
但它不喜欢我如何拥有与它们所在类相同类型的成员变量,因为编译器不知道"Node"是什么.