send image to whatsapp xamarin android - xamarin.android

How to send an image from the phone's memory to WhatsApp ?
code send string
private void Button1_Click(object sender, System.EventArgs e)
{
string phoneNumberWithCountryCode = "88167xxxxxxx";
string message = "Hallo";
StartActivity(new Intent(Intent.ActionView,
Uri.Parse("https://api.whatsapp.com/send?phone=" + phoneNumberWithCountryCode + "&text=" + message)));
}

Related

Smack 4.1 connection to gtalk

I updated to smack 4.1, but now cannot connect to gtalk. This is my code I am using:
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setHost("talk.google.com");
configBuilder.setPort(5222);
configBuilder.setServiceName("gmail.com");
configBuilder.setSecurityMode(SecurityMode.required);
configBuilder.setDebuggerEnabled(true);
configBuilder.setSendPresence(true);
configBuilder.setUsernameAndPassword(pref.getString(Constants.KEY_USER, ""), pref.getString(Constants.KEY_TOKEN, ""));
SASLAuthentication.blacklistSASLMechanism(SASLMechanism.PLAIN);
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
try
{
connection.connect();
connection.login();//.login(pref.getString(Constants.KEY_USER, ""), pref.getString(Constants.KEY_TOKEN, ""));
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
This is the error i get:
D/SMACK(12807): SENT (3): <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='X-OAUTH2'>REMOVED_THIS=</auth>
D/SMACK(12807): RECV (3): <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><incorrect-encoding/></failure>
The problem is the line in SASLXOauth2Mechanism:
Base64.encode(toBytes('\u0000' + authenticationId + '\u0000' + password));
As a quick test replace in your code
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
with this
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build())
{
#Override
public void send(PlainStreamElement auth) throws NotConnectedException
{
if(auth instanceof AuthMechanism)
{
final XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(AuthMechanism.ELEMENT)
.xmlnsAttribute(SaslStreamElements.NAMESPACE)
.attribute("mechanism", "X-OAUTH2")
.attribute("auth:service", "oauth2")
.attribute("xmlns:auth", "http://www.google.com/talk/protocol/auth")
.rightAngleBracket()
.optAppend(Base64.encodeToString(StringUtils.toBytes("\0" + authenticationId + "\0" + password)))
.closeElement(AuthMechanism.ELEMENT);
super.send(new PlainStreamElement()
{
#Override
public String toXML()
{
return xml.toString();
}
});
}
else super.send(auth);
}
};
I didn't test it, but I hope it works. authenticationId and token are your credentials.

org.apache.commons.net.ftp hangs timeout

I am in trouble with org.apache.commons.net.ftp.
My client need to detect timeout when uploading (Timeout for downloads works like a charm)
if i unplugged the network cable or switch off the adsl, upload hangs and timeouts are not working. I have made several test but nothing works, it's going to make me crazy
this is my code :
public boolean uploadFile2(String localFile, String serverFile) {
try {
InputStream stO = new FileInputStream(localFile);
OutputStream stD = storeFileStream(serverFile);
setDataTimeout(dataTimeOut);
Util.copyStream(stO, stD, getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE, new CopyStreamAdapter() {
public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) {
System.out.println("On transfert " + "/" + totalBytesTransferred + "/" + bytesTransferred + "/" + streamSize);
}
});
completePendingCommand();
} catch (Exception e) {
}
return false;
}
public boolean connectAndLogin(String host, String userName, String password) throws IOException, UnknownHostException,
FTPConnectionClosedException {
boolean success = false;
setDefaultTimeout(this.defaultTimeOut);
setConnectTimeout(this.connectionTimeOut);
addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
setPassiveMode(true);
connect(host);
int reply = getReplyCode();
if (FTPReply.isPositiveCompletion(reply)) {
success = login(userName, password);
setKeepAlive(true);
setControlKeepAliveTimeout(keepAliveTimeout);
setControlKeepAliveReplyTimeout(keepAliveResponseTimeout);
setSoTimeout(soTimeOut);
setDataTimeout(dataTimeOut);
setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
setFileType(FTP.BINARY_FILE_TYPE);
}
if (!success) {
disconnect();
}
return success;
}
Any help would be appreciated, thanks
and this does not work either:
FileInputStream in = new FileInputStream(localFile);
boolean result = storeFile(serverFile, in);
in.close();
return result;

Incoming sms listener on blackberry

i've used below code for notify the sms .
Its working on two blackberry simulator.
I've install the app on my device and send sms from android device.
The sms listener not working on device.
Incoming message received on device. but my app not notify the listener .
What is the problem how to resolve it.
What port number need to give for device?
class BackgroundApplication extends Application implements MessageListener
{
int i=0;
static String suffix;
MessageConnection _mc ;
public BackgroundApplication()
{
try {
_mc = (MessageConnection)Connector.open("sms://:0");
_mc.setMessageListener(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void notifyIncomingMessage(MessageConnection conn) {
try {
Message m = _mc.receive();
String address = m.getAddress();
String msg = null;
if ( m instanceof TextMessage )
{
TextMessage tm = (TextMessage)m;
msg = tm.getPayloadText();
}
else if (m instanceof BinaryMessage) {
StringBuffer buf = new StringBuffer();
byte[] data = ((BinaryMessage) m).getPayloadData();
// convert Binary Data to Text
msg = new String(data, "UTF-8");
}
else
System.out.println("Invalid Message Format");
System.out.println("Received SMS text from " + address + " : " + msg);
showDialog("Msg: "+msg);
} catch (Exception e) {
// TODO: handle exception
}
}
private void showDialog(String string) {
synchronized (UiApplication.getEventLock())
{
Status.show(""+string,Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 5000,
Status.GLOBAL_STATUS, true, false, 1);
}
}
}
Check this
http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-listen-for-SMS-messages/ta-p/445062
DatagramConnection _dc =
(DatagramConnection)Connector.open("sms://");
for(;;)
{
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
byte[] bytes = d.getData();
String address = d.getAddress();
String msg = new String(bytes);
System.out.println( "Received SMS text from " + address + " : " + msg);
}

Display HTTP Request Information - BlackBerry

How can I get the all HTTP request headers, method, the suffix of the connection, and all parameters that I added to the request?
Try something like this (I ran this code on a background thread, which I why I use UiApplication.invokeLater() to display results):
try {
ConnectionFactory factory = new ConnectionFactory(); // for OS 5.0+
factory.setPreferredTransportTypes(new int[] {
TransportInfo.TRANSPORT_TCP_WIFI,
TransportInfo.TRANSPORT_TCP_CELLULAR
});
// For OS < 5.0
//HttpConnection conn = (HttpConnection) Connector.open("http://www.google.com;interface=wifi");
HttpConnection conn = (HttpConnection) factory.getConnection("http://www.google.com").getConnection();
conn.setRequestProperty("sessionId", "ABCDEF0123456789");
final StringBuffer results = new StringBuffer();
String key = "";
int index = 0;
// loop over all the header fields, and record their values
while (key != null) {
key = conn.getHeaderFieldKey(index);
if (key != null) {
String value = conn.getHeaderField(key);
results.append(key + " = " + value + "\n\n");
}
index++;
}
results.append("method = " + conn.getRequestMethod() + "\n\n");
// we (should) know which request properties we've set, so we ask
// for them by name here
String sessionId = conn.getRequestProperty("sessionId");
results.append("sessionId = " + sessionId + "\n\n");
String url = conn.getURL();
results.append("URL = " + url);
// show the result on screen (UI thread)
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
textField.setText(results.toString());
}
});
} catch (IOException e) {
e.printStackTrace();
}

SMSLib example for interactive USSD session

I have a USSD application that provides an interactive session for users, for example:
User> Dial USSD Shortcode
Serv> Return Main Menu
User> Select Option 1, e.g. "View Movie Times"
Serv> Return List of Cities
User> Select Option 3, e.g. Mumbai
Serv> Return List of Cinemas
User> etc ...
I would like to test the USSD Server by using SMSLib to simulate the user.
Are there any example SMSLib code snippets that show how to perform an interactive USSD session with a USSD server?
The code at this link gives an example of sending and receiving USSD data using smslib:
// SendUSSD.java - Sample application.
//
// This application shows you the basic procedure for sending messages.
// You will find how to send synchronous and asynchronous messages.
//
// For asynchronous dispatch, the example application sets a callback
// notification, to see what's happened with messages.
package examples.modem;
import org.smslib.AGateway;
import org.smslib.AGateway.Protocols;
import org.smslib.IUSSDNotification;
import org.smslib.Library;
import org.smslib.Service;
import org.smslib.USSDResponse;
import org.smslib.modem.SerialModemGateway;
public class SendUSSD
{
public void doIt() throws Exception
{
Service srv;
USSDNotification ussdNotification = new USSDNotification();
System.out.println("Example: Send USSD Command from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
srv = new Service();
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM4", 19200, "Huawei", "E220");
gateway.setProtocol(Protocols.PDU);
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
srv.setUSSDNotification(ussdNotification);
srv.addGateway(gateway);
srv.startService();
System.out.println();
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel() + "%");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
String resp = gateway.sendUSSDCommand("*888#"); // not working
// String resp = gateway.sendCustomATCommand("AT+CUSD=1,\"*888#\",15\r"); // working
System.out.println(resp);
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
srv.stopService();
}
public class USSDNotification implements IUSSDNotification
{
public void process(AGateway gateway, USSDResponse response) {
System.out.println("USSD handler called from Gateway: " + gateway.getGatewayId());
System.out.println(response);
}
}
public static void main(String args[])
{
SendUSSD app = new SendUSSD();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Resources