ACRA does not send report crash using HttpSender - android

I installed the Acre extension as written in the acre documentation.
And added the #AcraHttpSender anatomy indicated the site and the sending method in it.
But when I throw an exception or use the following command ACRA.getErrorReporter().handleException(new Exception("123"));, nothing happens to the server.
Although I have a permission to access the network in the manifest and the Internet is always on.
Why is not sending?
And is there a way to manually send accumulated reports using the service after a certain period of time?

I was wrong, I checked the data in the $_POST array, which produced a negative result and the logs were not written, you should use the input stream reading directly like this file_get_contents('php://input');
The question can be considered closed, thank you all, the ACRA logs helped to see that the data is not written to the server.

I had exactly the same issue. If it helps anyone else out, here is my MyApplication.java:
#AcraCore(
buildConfigClass = BuildConfig.class,
reportFormat = StringFormat.JSON
)
#AcraHttpSender(
uri = "https://example.org/my_acra_script.php",
httpMethod = HttpSender.Method.POST
)
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
}
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
...just change the uri value.
And here is my_acra_script.php:
<?php
$NEW_LINE = "\r\n";
$from = "server#example.org";
$to = "you#example.org";
$subject = "Android Crash Report";
$headers = "From: $from" . $NEW_LINE;
$headers .= 'MIME-Version: 1.0' . $NEW_LINE;
$headers .= 'Content-type: text/html; charset=utf-8' . $NEW_LINE;
$message = "<html>";
$message .= " <head>";
$message .= " <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
$message .= " <title>$subject</title>";
$message .= " </head>";
$message .= " <body>";
$message .= " <p>";
$post_data = file_get_contents('php://input');
if (empty($post_data)) {
$message .= "No data received.";
}
else {
$error_data = json_decode($post_data, true);
foreach ($error_data as $key => $value) {
$message .= "<br /><b>" . nl2br(htmlspecialchars($key)) . ":</b><br />" . nl2br(htmlspecialchars($value)) . "<br />" . $NEW_LINE;
}
}
$message .= " </p>";
$message .= " </body>";
$message .= "</html>";
$result = mail($to, $subject, $message, $headers);
if ($result === TRUE) {
echo "OK";
}
else {
error_log("ACRA email not sent.");
}
?>
...just change the $from and $to values.

Related

Activate A Device's Third-Party Video-Camera Software With HTML Form-File-Picker

I have an html form on my website which allows users to submit a short video file.
The code I am presently using effectively allows the user to either select a Pre-Recorded video file, or record a new video.
accept="video/*;capture=camcorder"
If I had my preference, I would opt to have the picker 'disable' the 'select-file' option, and only allow it to activate the device's video camera software. So the user could only record and submit a new video. But I'm not even sure that's possible, and that's not my immediate issue.
The immediate issue is, my present code will only activate the 'generic' Video Camera software on devices. It will not activate any 'third-party' or 'advanced' video camera software options.
Is there a working code available, or an adjustment to my existing code which would allow a fix for either or both of these issues?
Any suggestions would be greatly appreciated.
Below is my current code...
THE FORM
<!DOCTYPE html>
<head>
<title>Video Form</title>
</head>
<body>
<form action="/videoformHandler.php" method="post"
enctype="multipart/form-data">
<h1>VIDEO FORM</h1>
<input type="text" id="userName" name="userName" placeholder=" User
Name"
onfocus="this.placeholder = ''" onblur="this.placeholder = ' Name'"
required=""><br><br>
<input type="email" id="userEmail" name="userEmail" placeholder="
user#email.com"
onfocus="this.placeholder = ''" onblur="this.placeholder = '
your#email.com'" required=""><br>
<br>
<input type="file" id="file" name="userImages"
accept="video/*;capture=camcorder" required=""/><br><br>
<input type="submit" id="submitButton" name="submitButton"
class="submit__button"
value="Submit">
</form>
</body>
</html>
FORM HANDLER
<?php
/////
$filenameee = $_FILES['userImages']['name'];
$fileName = $_FILES['userImages']['tmp_name'];
$name = $_POST['userName'];
$email = $_POST['userEmail'];
/////
$composition =
"\r\n\n\nName: " . $name .
"\r\nEmail Address: " . $email;
/////
$subject ="Video Message";
$fromname ="$name";
$fromemail = "$email";
$mailto = 'receiving#email.com'; //recipient email
//The Content Action
$content = file_get_contents($fileName);
$content = chunk_split(base64_encode($content));
// A random hash will be necessary to send mixed content
$separator = md5(time());
// Carriage return type (RFC)
$eol = "\r\n";
/////
$headers = "From: ".$fromname." <".$fromemail.">" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator .
"\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;
/////
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol;
$body .= $composition . $eol;
/////
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filenameee
. "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";
/////
//Mail send action
#mail($mailto, $subject, $body, $headers);
//Page Re-direct after form submission
header('location: /videoformsent.php');
?>
SENT CONFIRMATION
<!DOCTYPE html>
<head>
<title>Sent Confirmation</title>
</head>
<body>
Your Video Has Been Successfully Sent!
</body>
</html>

I am not getting push notification on android Oreo, but on lower versions I am getting

I am sending push notification from laravel which I am using as a backend for my app.
I am not getting the push notification on android Oreo, but on lower versions, I am getting it.
What changes should I have to do for getting the notification in android oreo?
Here is the code of fcm.php
<?php
class Fcm {
//Define SendNotification function
function sendNotification($dataArr) {
$fcmApiKey = 'SERVER_KEY';//App API Key(This is google cloud messaging api key not web api key)
$url = 'https://fcm.googleapis.com/fcm/send';//Google URL
$registrationIds = $dataArr['device_id'];//Fcm Device ids array
$message = $dataArr['message'];//Message which you want to send
$title = $dataArr['title'];
$image=$dataArr['image'];
$news_id=$dataArr['news_id'];
$random=$dataArr['random_id'];
// prepare the bundle
$msg = array('message' => $message,'title' => $title,"image"=>$image,"news_id"=>$news_id,"random_id"=>$random);
$fields = array('registration_ids' => $registrationIds,'data' => $msg);
$headers = array(
'Authorization: key=' . $fcmApiKey,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, $url );
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 ) );
$result = curl_exec($ch );
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
$_SESSION['result']=$result;
return $result;
}
}
Here is the code of send.php
<html><head><script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script></head><body>
<?php
include 'config.php';
//echo '<pre>';
$title=$_POST['title'];
$msg=$_POST['msg'];
$news_id=$_POST['news'];
//echo $news_id;
//echo msg;
//echo $image;
$sql="SELECT image FROM `app_news` where id='".$news_id."' ";
$check= mysqli_query($con, $sql);
$resultcheck= mysqli_fetch_array($check,MYSQLI_ASSOC);
$random=rand(0,999);
$image=$resultcheck['image'];
$data=array("title"=>$title,"message"=>$msg,"image"=>$image,"news_id"=>$news_id,"random_id"=>$random,"priority" => 10);
///echo'<pre><h1> Data sent through request:<br>';var_dump($data); echo '</h1><br>';
////////////////////////////////GETTING DEVICE DATA///////////////////////////////////
$sql="SELECT * FROM `devices`";
$checkdevices= mysqli_query($con, $sql);
$DeviceIdsArr= array();
//Prepare device ids array
while($rowData = mysqli_fetch_array($checkdevices,MYSQLI_ASSOC)) {
$DeviceIdsArr[] = $rowData['token'];
}
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////SENDING NOTIFICATION//////////////////////////////////////////
require("fcm.php");
$fcm = new Fcm();//Create Fcm class object
$dataArr = array();
$dataArr['device_id'] = $DeviceIdsArr;//fcm device ids array which is created previously
$dataArr['message'] = $data['message'];//Message which you want to send
$dataArr['image'] = $data['image'];
$dataArr['title'] = $data['title'];
$dataArr['news_id'] = $data['news_id'];
$dataArr['random_id'] = $data['random_id'];
$dataArr[ 'priority'] = $data['priority'];
//Send Notification
$fcm->sendNotification($dataArr);
//var_dump($_SESSION['result']);//
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
$results[]=json_decode($_SESSION['result']);
///////////////showing results//////////////
$multicast_id=$results[0]->multicast_id;
$success=$results[0]->success;
$fail=$results[0]->failure;
$message_id=$results[0]->results[0]->message_id;
///////////////////////////////////////////////////
if($success!=''){?>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">
swal({
title: "Notification sent",
text: "successfully ",
icon: "success",button: "close"
}).then(function() {
//Redirect the user
window.location.href = "notification.php";
//console.log('The Ok Button was clicked.');
});
</script>
<?php } ?>

Creating new plugin for webservice

I wrote this code to connect to a database, make some queries and send them by json like web api.
I want to create plugin that will work like a WEB API. Then upload it on WP modules on internet and people may install them on their sites to connect my android App. Anywhere.
This is my php code (include db_connect and sending json and respond to my Android App)
<?php
if(!isset($_REQUEST ['id']))
echo "id is not set";
if (isset ( $_REQUEST ['id'] )) {
$id = $_REQUEST ['id'];
$response = array ();
mysql_connect('localhost','db_admin','password') or die(mysql_error());
mysql_select_db('db_name') or die(mysql_error());
$sql= "select * from employee";
$run=mysql_query($sql);
if (mysql_num_rows ($run) > 0) {
while ($row= mysql_fetch_array($run)){
$product = array ();
$product ["id"] = $row [0];
$product ["name"] = $row [1];
$product ["salary"] = $row [2];
$response [] = $product;
}
echo json_encode ( $response );
}
}
?>
My manager wants me not to use the default Woocommerse WORDPRESS API,so I have to create new plugin. and want to know how can I convert it to standard module?
Is it possible at all ?
If I was you I will created like this:
First off would create handler for the request, either via ajax (im not sure if this way is supported in android ) like this;
function get_some_information(){
$user_id = $_REQUEST['id'];
if(!isset($user_id) || empty($user_id)){
return json_encode([
'success' => false,
'message' => 'Empty Request'
]);
}
$data = get_info_from_data($user_id);
if(!empty($data)){
echo json_encode($data);
exit;
}else{
echo json_encode([
'success' => false,
'message' => 'Error while processing data'
]);
exit;
}
}
add_action('wp_ajax_get_some_information', 'get_some_information'); //for auth users
add_action( 'wp_ajax_nopriv_get_some_information', '_get_some_information' ); //for the rest
Note: there is an exit; you always need to terminate the application to be able to get the json, otherwise the output it will be 0
With this now we have an access point to data and validation; and it looks a bit more clean.
function get_some_information($id){
$result = [];
// do all things and added to the array
return $result;
}

Titanium Alloy Android Login

I am having an issue with a Titanium App, the issue is only with Android, iOS is fine.
So I have a login form that queries the database, pretty straightforward. But for some reason it is not passing the params to the login script.
My JS function in app, have set the alert on the else statement to print out the $.email.value and password values which read fine. But with the current $response which is just a json it shows the values as being blank? The php form is also below. As I have said this is working fine on iOS
function login(e) {
//function to use HTTP to connect to a web server and transfer the data.
var sendit = Ti.Network.createHTTPClient({
onerror : function(e) {
Ti.API.debug(e.error);
alert('There was an error during the connection');
},
timeout : 100000,
});
//Here you have to change it for your local ip
sendit.open('GET', 'http://soyo.taylorhoganit.co.uk/post_auth.php');
var params = {
email : $.email.value,
password : $.password.value,
};
sendit.send(params);
//Function to be called upon a successful response
sendit.onload = function() {
var json = this.responseText;
var response = JSON.parse(json);
if (response.logged == true)
{
var landing = Alloy.createController("landing").getView();
$.index.close();
landing.open();
// Ti.App.Properties.setString('email', $.email.value);
// Ti.App.Properties.setString('password', $.password.value);
//alert("Username: " + response.username);
}
else
{
alert($response);
}
};
};
PHP Script
<?php
// Connect to the database(host, username, password)
$con = mysql_connect('replaced values');
if (!$con)
{
echo "Failed to make connection.";
exit;
}
$db = mysql_select_db('soyo');
if (!$db)
{
echo "Failed to select db.";
exit;
}
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email = '" . $email . "' AND password = '" . $password . "'";
$query = mysql_query($sql);
// If we find a match, create an array of data, json_encode it and echo it out
if (mysql_num_rows($query) > 0)
{
$row = mysql_fetch_array($query);
$response = array(
'logged' => true,
'email' => $row['email']
);
echo json_encode($response);
}
else
{
// Else the username and/or password was invalid! Create an array, json_encode it and echo it out
$response = array(
'logged' => false,
'message' => $email + $password
);
echo json_encode($response);
}
?>
You did a mistake by using $response in the alert. It is a PHP variable not JS.
var response = JSON.parse(json);
// ...
alert($response); // Here should be just `response`
Edit: The another problem is that you are sending GET request while in PHP you accept POST ,so you can't get any params...
There is a mistake when you want to show alert.
You are using now is alert($response);
Remove $ from $response and use alert(response);, it will work properly.

Using C2DM get 401 problem?

HI~everyone!
I have gotten the registration_id for the phone and an auth token from google for my gmail account that is performing a push.
But When I send my auth token and registration id to Ubuntu and try to post it by php , php's curl and only curl to request to C2DM to get a message. And I always get the 401 Unauthorized.
And this is my php code ....
$post_params = array ( "Email" => $MY_GOOGLE_ACC, "Passwd" =>
$MY_GOOGLE_PWD, "accountType"=>"GOOGLE", "source=" . $MY_GOOGLE_SRC, "service=ac2dm" );
$first = true;
$data_msg = "";
foreach ($post_params as $key => $value) {
if ($first)
$first = false;
else
$data_msg .= "&";
$data_msg .= urlencode($key) ."=". urlencode($value);
}
$x = curl_init("https://www.google.com/accounts/ClientLogin");
curl_setopt($x, CURLOPT_HEADER, 1);
curl_setopt($x, CURLOPT_POST, 1);
curl_setopt($x, CURLOPT_POSTFIELDS, $data_msg);
curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($x);
curl_close($x);
$response = $data;
$authKey = trim(substr($response, 4+strpos($response, "SID=")));
echo $authKey; $collapse_key = 'something';
$post_params = array ( "registration_id" => $DEVICE_TOKEN, "collapse_key" =>
$collapse_key, "data.payload"=>"cakephp" );
$first = true;
$data_msg = "";
foreach ($post_params as $key => $value) {
if ($first)
$first = false;
else
$data_msg .= "&";
$data_msg .= urlencode($key) ."=". urlencode($value);
}
$size=strlen($data_msg);
$x = curl_init("https://android.apis.google.com/c2dm/send");
curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Content-Length:'. $size, 'Authorization: GoogleLogin auth=' . $authKey));
curl_setopt($x, CURLOPT_HEADER, 1);
curl_setopt($x, CURLOPT_POST, 1);
curl_setopt($x, CURLOPT_POSTFIELDS, $data_msg);
curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($x);
curl_close($x);
$response = $data;
Am I miss somthing or do something wrong?
AND any help would be much appreciated,thanks!!
It seems you are extracting the SID from the response, not the Auth field.
$authKey = trim(substr($response, 4+strpos($response, "SID=")));
should be
$authKey = trim(substr($response, 5+strpos($response, "Auth=")));
Try printing the whole response, you'll see something like:
SID=DQAAAGgA...7Zg8CTN
LSID=DQAAAGsA...lk8BBbG
Auth=DQAAAGgA...dk3fA5N
It's this last field that you're searching for!

Categories

Resources