i want to know how can we send data to web server , am using get method to send data , also i would ask that what is best way to send data to web sever , get or post or any other way
my code
Code:
String and = "&";
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("10.0.2.2/login.php?tx=mydata"+and+"androidflavour="+af);
httpclient.execute(httppost);
Log.d("test", "Data sent!");
} catch (Exception e){
Log.d("test", "Data not sent!");
}
result : data not send
so please help
Have a look at this guide: http://forum.xda-developers.com/showthread.php?t=2325799
post has no limits a while get has
devalex from Bolt A67
---------- Post added at 09:09 AM ---------- Previous post was at 09:04 AM ----------
I have used a easiest way made a webview and called loadurl method and accesed those variables using $_request in php its easiest way.
devalex from Bolt A67
Related
Hello together,
I am trying to access a webservice with ksoap. I am able to get data from the webservice but only in the case I don't have to provide parameters.
I get always the error message "Server was unable to process request. ---> Sequence contains no elements" from the webservice. For me it looks like that the given properties are not provided to or not processed by the webservice.
I searched in the web for a couple of hours and could find out that some others have the same problem but couldn't find any solution
May anybody from the forum can help me....
My code is following
final String NAME_SPACE = "XXX";
final String URL = "XXX";
final String SOAP_ACTION = "XXX/GetMatchdataByLeagueSaison";
final String METHOD_NAME = "GetMatchdataByLeagueSaison";
SoapObject Request = new SoapObject(NAME_SPACE, METHOD_NAME);
Request.addProperty("leagueShortcut", "bl1");
Request.addProperty("leagueSaison", 2010);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE tns = new HttpTransportSE(URL);
try
{
tns.call(SOAP_ACTION, soapEnvelope);
SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
String PropertyCount = String.valueOf(resultString.getPropertyCount()); // Anzahl Records
Log.i("GetMatchdataByLeagueSaison", "Anzahl Properties = " + PropertyCount);
result = "GetMatchdataByLeagueSaison " + PropertyCount;
}
catch(Exception e)
{
result = "GetMatchdataByLeagueSaison " + e.getMessage();
}
return result;
}
Hi!
I am loading a text to TextView from a file on a webpage with my Android app but the problem is that the text is full of ASCII characters, so when the text is loaded to the TextView, I can't see any of these ASCII characters or it shows me a "?" within a black square.
My question is, how can I convert an ASCII character to string?
Thanks for helping.
adamhala007 said:
Hi!
I am loading a text to TextView from a file on a webpage with my Android app but the problem is that the text is full of ASCII characters, so when the text is loaded to the TextView, I can't see any of these ASCII characters or it shows me a "?" within a black square.
My question is, how can I convert an ASCII character to string?
Thanks for helping.
Click to expand...
Click to collapse
Code:
char c = 'e';
String s = String.valueOf(c);
Are you sure that there's no other problem with your code? It doesn't sound like a conversion error.
nikwen said:
Code:
char c = 'e';
String s = String.valueOf(c);
Are you sure that there's no other problem with your code? It doesn't sound like a conversion error.
Click to expand...
Click to collapse
I don't know, but here is my code:
Code:
TextView textMsg;
final String textSource = "PATH/TO/MY/.CRL/FILE";
BufferedReader reader;
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
I have forgotten to mention that my file where I load the text from has .crl extension. I have tried the code you posted, but the problem still remains. So it shows me still the "?" within the black squares.
adamhala007 said:
I don't know, but here is my code:
Code:
TextView textMsg;
final String textSource = "PATH/TO/MY/.CRL/FILE";
BufferedReader reader;
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
I have forgotten to mention that my file where I load the text from has .crl extension. I have tried the code you posted, but the problem still remains. So it shows me still the "?" within the black squares.
Click to expand...
Click to collapse
Could you please post an example file?
Can CRL files really be read using a Buffered reader? Aren't the encrypted?
nikwen said:
Could you please post an example file?
Can CRL files really be read using a Buffered reader? Aren't the encrypted?
Click to expand...
Click to collapse
OK. I know why you cannot do it that way:
*.crl files are no text files. When you open them in a browser that supports it, you might see the entries. However, it is no plain text. (You might be able to read some parts, but it is not completely text.)
Proof:
I downloaded a CRL file on my Linux machine.
The way to get its content if it is a textfile is to use the cat command:
Code:
cat <path>
That way I am able to read parts of the file, but most characters aren't real characters. (Things like your ?s.)
So we need another way to do that.
---------- Post added at 09:34 AM ---------- Previous post was at 09:30 AM ----------
You can find classes for reading CRLs in the java.security.cert package: http://developer.android.com/reference/java/security/cert/package-summary.html
EDIT: This seems to be the best tutorial I found so far: http://www.javaworld.com/javaworld/jw-03-2001/jw-0316-howto.html
I found that tutorial with some code snippets: http://jce.iaik.tugraz.at/sic/Support/Technical-Articles/Parsing-Large-CRLs-in-Java
Another tutorial related to CRLs: http://www.nakov.com/blog/2009/12/0...rify-chain-and-verify-clr-with-bouncy-castle/
Hello,
I am student in my final year doing a project based on android development. I am thinking of creating an application that scans all the installed application in the device and recover all the list of permission associated with the app.. I will then manually use the data to check the manifest files manually, so that I can flag up any app that has more permission than it should.
I am learning and just starting creating it in eclipse. But, any advice would greatly be appreciated as am new to this development world.
I am thinking of creating a GUI for the layout but how can I make it list all the installed application on the device before I can proceed into getting the permission.
Thank you.
You need to use the PackageManager
The solution is on stackoverflow (love that site), but since I can't post links yet, I'll simply give you the code (should work):
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}
Good luck!!
Edwin Bos said:
You need to use the PackageManager
The solution is on stackoverflow (love that site), but since I can't post links yet, I'll simply give you the code (should work):
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}
Good luck!!
Click to expand...
Click to collapse
Is it possible I can create it within a searchView so that it can search it and display the installed application. But, displayed the app in a scroll view as well.
Hello!
Sorry for my bad english.
I'm trying to develop an app that send a push notification from device A (android) to device B (android).
How can I make this app?
I can't use GCM/Parse server, 'cause a push notification is sent ONLY from server to device!
I must use a DB that save MY contacts? And then, with a query (?), sent a push notif. to user B (B have downloaded the app, of course!)?
Thanks!
Venus88 said:
I can't use GCM/Parse server,
Click to expand...
Click to collapse
Yes you can, you would just need to create an API that would capture a message sent to the server from device A then send it to device B.
Jonny said:
Yes you can, you would just need to create an API that would capture a message sent to the server from device A then send it to device B.
Click to expand...
Click to collapse
Thanks a lot!
And how I can do that? The code for GCM server, i.e. gcm.php:
PHP:
<?php
class GCM {
//put your code here
// constructor
function __construct() {
}
/**
* Sending Push Notification
*/
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
}
?>
and
PHP:
<?php
// response json
$json = array();
/**
* Registering a user device
* Store reg id in users table
*/
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["regId"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$gcm_regid = $_POST["regId"]; // GCM Registration ID
// Store user details in db
include_once './db_functions.php';
include_once './GCM.php';
$db = new DB_Functions();
$gcm = new GCM();
$res = $db->storeUser($name, $email, $gcm_regid);
$registatoin_ids = array($gcm_regid);
$message = array("product" => "shirt");
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
} else {
// user details missing
}
?>
allows send notification from server page to one/a group of devices.
Can i "reverse" the direction? from Device A to server (and then from server to device B) automatically?
Up :\
I'm trying to send data via Http but I keep getting this error: No encoding found. Expected encoding 'utf-8' to be present in message header. I tried adding:
connection.setRequestProperty("charset","utf-8"); but it still didn't work.
The full code is:
Java:
HttpURLConnection connection;
try {
//Open a new URL connection
connection = (HttpURLConnection) new URL(params[0])
.openConnection();
//Defines a HTTP request type
connection.setRequestMethod("POST");
//Sets headers: Content-Type
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("charset","utf-8");
//Add POST data in JSON format
JSONObject jsonParam = new JSONObject();
try {
jsonParam.put("Count", Integer.parseInt(Data));
} catch (JSONException e) {
e.printStackTrace();
}
//Create a writer object and make the request
OutputStreamWriter outputStream = new OutputStreamWriter(connection.getOutputStream());
outputStream.write(jsonParam.toString());
outputStream.flush();
outputStream.close();
Thanks so much!
Stack overflow is a better place for programming questions than here I suspect...
This looks like the same question. There's a good-looking answer there.
Java send http POST with UTF-8
I need to send HTTP POST with Google FCM. With code below, it's OK to send English message but Chinese characters. I did many trials by adding UTF-8 here and there... Need help. The payload of my
stackoverflow.com