Php android的通知代码
我想在android中创建通知和警报。我知道我的PHP正在工作,但我是android编程的初学者 { //数据团队id”; $query.=”,s.dt\u开始时间然后是'30'; $query.=“当'01:00:00'时,然后是'1'; $query.=“s.c\U用户\U id=ms.c\U用户\U id”; $query.=“和s.c_团队id=ms.c_团队id”; $query.=”和ms.c_user_id=”。“$userID.”; $query.=“其中s.c_user_id=””。“$userID。””; $query.=“和s.c_条目=1”; $query.=“和s.t_警报>=当前_时间戳()”; $query.=“和(日期添加(CURDATE(),间隔7天))”; $query.=“s.t_警报下的订单”; $query.=“限制64”; $result=mysql\u query($query) }试试这个:Php android的通知代码,php,android,Php,Android,我想在android中创建通知和警报。我知道我的PHP正在工作,但我是android编程的初学者 { //数据团队id”; $query.=”,s.dt\u开始时间然后是'30'; $query.=“当'01:00:00'时,然后是'1'; $query.=“s.c\U用户\U id=ms.c\U用户\U id”; $query.=“和s.c_团队id=ms.c_团队id”; $query.=”和ms.c_user_id=”。“$userID.”; $query.=“其中s.c_user_id=
private void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
String appname = context.getResources().getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, myactivity.class), 0);
// To support 2.3 os, we use "Notification" class and 3.0+ os will use
// "NotificationCompat.Builder" class.
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
notification = new Notification(icon, message, 0);
notification.setLatestEventInfo(context, appname, message,
contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(appname).setWhen(0)
.setAutoCancel(true).setContentTitle(appname)
.setContentText(message).build();
notificationManager.notify(0 , notification);
}
}
private void generateNotification(上下文、字符串消息){
int icon=R.drawable.ic_启动器;
长时间=System.currentTimeMillis();
String appname=context.getResources().getString(R.String.app_name);
NotificationManager NotificationManager=(NotificationManager)上下文
.getSystemService(上下文通知服务);
int currentapiVersion=android.os.Build.VERSION.SDK\u int;
通知;
PendingEvent contentIntent=PendingEvent.getActivity(上下文,0,
新意图(上下文,myactivity.class),0);
//为了支持2.3操作系统,我们使用“通知”类,3.0+操作系统将使用
//“NotificationCompat.Builder”类。
if(currentapiVersion
希望这有帮助。你需要通知或GCM Android的示例?我需要Android java代码来通知!:)你需要解释你想做什么。你想在Android上运行PHP来进行查询,或者你想在某些服务器上运行PHP脚本并在手机上显示通知?你想怎么做。这将是推送(GCM)或者用户将在其手机上打开应用程序并向服务器发出请求?对于姜饼和更低版本使用
通知
是绝对没有意义的。NotificationCompat.Builder
适用于所有版本,只需确保在姜饼和更低版本上设置contentIntent
。我需要使用php连接数据库,并且将数据显示为通知
private void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
String appname = context.getResources().getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, myactivity.class), 0);
// To support 2.3 os, we use "Notification" class and 3.0+ os will use
// "NotificationCompat.Builder" class.
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
notification = new Notification(icon, message, 0);
notification.setLatestEventInfo(context, appname, message,
contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(appname).setWhen(0)
.setAutoCancel(true).setContentTitle(appname)
.setContentText(message).build();
notificationManager.notify(0 , notification);
}
}