ToughtWorks’ Technology Radar – new edition

15 02 2014

Is this new technology worth learning or maybe it is yet ready to use in production? ToughtWorks is a consulting company working, among others, on assesments of emerging technologies maturity.

Here is the new edition of its Technology Radar – January 2014. I am sure that everybody will find out what interests him in this document.

For me worth noting is JavaScript expansion – nowadays it is widely used, not only on client side in web browsers but also on the server side.

Another thing is SMS and USSD API growth. It did surprise me – I was really up to the HTTP APIs usage. Such situation may be good for telcos, but not very much convenient for developers.

Do you like my blog?
I manage this blog and share my knowledge for free, sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

Advertisements




Android tutorial: mark SMS as read / unread

7 09 2013

When your app uses SMS inbox, you may want to be able to mark particular message as read or unread. SMS inbox has a property assigned to each message that indicates whether message is read or unread. You can access this property by ContentProvider. Here is how to do it:

1. Require WRITE and READ SMS permission

First of all to read and change inbox messages properties you must declare permission in AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />

2. Having SMS sender and body, mark SMS as read

You simply need to search for the message in inbox and update it. Do it by using ContentResolver, providing proper projection and selection arguments:

public void markSmsAsRead(final String from, final String body) {

	Uri uri = Uri.parse("content://sms/inbox");
	String selection = "address = ? AND body = ? AND read = ?";
	String[] selectionArgs = {from, body, "0"};

	ContentValues values = new ContentValues();
	values.put("read", true);

	context.getContentResolver().update(uri, values, selection, selectionArgs);
}

The code above accesses the SMS Inbox content and finds messages received from sender (address = from), with specified content (body = body) and unread (read = 0). Then it updates their status to read = 1 (read = true). That’s all. It’s optimal and efficient.

Note

If you want to mark SMS as read right after it was received then you have to wait few seconds until it gets stored in SMS database. I do it by sleeping a thread for 3 seconds before searching Inbox. This is how it looks like:

public void markSmsAsRead(final String from, final String body) {

	Thread waiter = new Thread(new Runnable() {

		@Override
		public void run() {
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				Log.w(TAG, "Exception while sleeping markSmsAsReadThread: " + e.getMessage());
			}

			Uri uri = Uri.parse("content://sms/inbox");
			String selection = "address = ? AND body = ? AND read = ?";
			String[] selectionArgs = {from, body, "0"};

			ContentValues values = new ContentValues();
			values.put("read", true);

			int rowsUpdated = context.getContentResolver().update(uri, values, selection, selectionArgs);
			Log.i("TAGGG", "rows updated: " + rowsUpdated);
		}
	});
	waiter.start();
}

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS tutorial: Send SMS programmatically

31 08 2013

iOS is very strict when it comes to using phone capabilities in applications. It limits usage because of security reasons, so in fact, as an iPhone application developer you can’t send SMS in background or listen for incoming SMS messages. The only solution to send SMS is to initiate the built in SMS application where user can click to send message (however application can preset the SMS receiver and body). This is what I show in this tutorial:

1. Import MessageUI

Add import statement in header file:

#import <MessageUI/MessageUI.h>

2. Use delegate in header

in your header file, declare the delegate as:

<MFMessageComposeViewControllerDelegate>

3. Initiate the send SMS request

Depending on your application logic, you can use this method in various places. In my case this is initiated on button click. ‘body‘ param is message content.

- (void) sendSMS:(NSString*)body{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewControlleralloc] init];
    if([MFMessageComposeViewControllercanSendText])
    {
        NSString *num = [[NSUserDefaultsstandardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];

        controller.body = body;
        controller.recipients = [NSArray arrayWithObjects:@"1(234)567-8910", num, nil];
        controller.messageComposeDelegate = self;
        [selfpresentViewController:controller animated:YEScompletion:nil];
    }
}

4. React on user’s confirmation

Code from sendSMS method will open SMS application with prepared SMS message and confirmation and cancellation button. To react on these button clicks, you have to implement delegate method:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
    NSString *num = [[NSUserDefaultsstandardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
    NSLog(@"Some result received: %u, %@", result, num);
    [controller dismissViewControllerAnimated:YEScompletion:nil];
}

Is that really not possible?

More advanced phone actions are possible on Jailbroken devices and by using undocumented APIs, but Apple will not approve such application on AppStore.

And on Android?

In Android the situation is different. Developer is free to use all phone features including sending SMS in background, listening for incoming SMS, calls, initiating calls etc. It trusts user that if he install app he agrees that it may use such features on his device.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Android tutorial: Send SMS programatically

4 05 2013

SmsManager has a method that is sending SMS message completely without user’s interaction needed. If You need to send SMS from your code:

1. Use SmsManager

Add these lines to your app

import android.telephony.SmsManager;

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("123456789", null, "sms message", null, null);

You can replace these nulls with Intents (according to documentation) that will be fired up when SMS is delivered / sent / failed to send. In basic case it is optional and can be null.

2. request permissions in AndroidManifest.xml

Add these lines to Manifest:

<uses-permission android:name="android.permission.SEND_SMS" />

Remember

Remember to have active SIM card in your device when you want to send SMS :)

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!








%d bloggers like this: