我正在使用php服务器发送FCM推送通知.我想知道如何同时向多个主题发送推送通知.
这是我的代码.
function sendPush($topic,$msg){
$API_ACCESS_KEY = '...';
$msg = array
(
'msg' => $msg
);
$fields = array('to' => '/topics/' . $topic, 'priority' => 'high', 'data' => $msg);
$headers = array
(
'Authorization: key=' . $API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$pushResult = curl_exec($ch);
curl_close($ch);
}
Run Code Online (Sandbox Code Playgroud) 我刚刚从更新的Android支持库com.android.support:appcompat-v7:25.3.1来com.android.support:appcompat-v7:26.0.1.它改变了动作模式图标的外观.现在它们是半可见/按下,如图所示.
它是支持库中的错误还是我做错了什么?
这是我如何设置动作模式的图标.
@Override
public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
menu.add("Delete").setIcon(R.drawable.ic_action_discard);
menu.add("Copy").setIcon(R.drawable.ic_action_copy);
return true;
}
Run Code Online (Sandbox Code Playgroud)
更新
我已经验证这是android支持库中的一个错误.
这是一个链接 https://issuetracker.google.com/issues/64207386
更新
谷歌更新了新版本.从Recent Support Library Revisions页面.
Bug修复
支持库26.0.0上的菜单图标展平
我在这里找到了一个很好的教程,用于android上的服务器客户端通信 奇迹般有效.但这只是一种沟通方式.我试图在客户端听服务器响应,但不知道我在哪里错了.这是我试图进行更改的服务器代码.
服务器
public class Server extends Activity {
private ServerSocket serverSocket;
Handler updateConversationHandler;
Thread serverThread = null;
private TextView text;
public static final int SERVERPORT = 8080;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView) findViewById(R.id.text2);
updateConversationHandler = new Handler();
this.serverThread = new Thread(new ServerThread());
this.serverThread.start();
}
@Override
protected void onStop() {
super.onStop();
try {
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class ServerThread implements Runnable {
public void run() …Run Code Online (Sandbox Code Playgroud) 我是 android 编程的新手。我添加了一个上下文菜单来编辑文本。我希望我可以在长按光标下找到单词。请帮忙。我可以通过以下代码获取选定的文本。
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
EditText edittext = (EditText)findViewById(R.id.editText1);
menu.setHeaderTitle(edittext.getText().toString().substring(edittext.getSelectionStart(), edittext.getSelectionEnd()));
menu.add("Copy");
}
Run Code Online (Sandbox Code Playgroud)
edittext 有一些文本,例如“一些文本。一些更多的文本”。用户单击“更多”,因此光标将位于“更多”一词中的某个位置。我希望当用户长按这个词时,我可以在光标下得到“更多”等词。
我在自定义适配器列表视图中添加了两个微调器.一切都很好但是当我将新项目添加到列表视图时,前一项目的微调器的值将转换为新项目.在滚动列表中,微调器的视图值也会旋转.请帮忙.
public class CustomAdapter extends BaseAdapter {
private ArrayList<MyMessageDetails> _data;
Context _c;
ProductsItemViewHolder holder;
CustomAdapter (ArrayList<MyMessageDetails> data, Context c){
_data = data;
_c = c;
}
public int getCount() {
// TODO Auto-generated method stub
return _data.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return _data.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// …Run Code Online (Sandbox Code Playgroud) 我正在使用以下脚本通过 PHP 发送电子邮件。但是,我收到错误"PHP Warning: mail(): Found numeric header (4) in /home/....public_html/.../sendemail.php on line 16"任何帮助。
PHP脚本
<?php
$name = @trim(stripslashes($_POST['name']));
$from = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$to = 'xxxxx@xmail.com';
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=UTF-8";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
die;
Run Code Online (Sandbox Code Playgroud)