Showing posts with label Mobile. Show all posts
Showing posts with label Mobile. Show all posts

Friday, April 27, 2012

Android (Contacts): How to lookup and add contacts

This is how you can look-up for a specific contact in Android and do whatever you want if the contact is available or not.

The following code segment shows how the contact is programmatically added to contacts.

Check for an existing number in the Android contacts

Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                                                                   Uri.encode(CommonVariables.merchantPhone));
String[] mPhoneNumberProjection = {
   ContactsContract.PhoneLookup._ID,
   ContactsContract.PhoneLookup.NUMBER,                  
   ContactsContract.PhoneLookup.DISPLAY_NAME
};

Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);

if (cur != null && cur.moveToFirst()) {
   // The code to be executed if the phone number is available
}
else {
   // The code to be executed if the number is not available
}

Add a new number to the Android contacts

ArrayList op_list = new ArrayList();
op_list.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
 
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,  ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, CommonVariables.merchantName)
.build());

op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)  .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, CommonVariables.merchantPhone)
.build());
 
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
 .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
 .withValue(ContactsContract.CommonDataKinds.Email.DATA, getResources().getString(R.string.merchant_email))
    .build());

try {
  ContentProviderResult[] results = getContentResolver().applyBatch(ContactsContract.AUTHORITY, op_list);
  Toast.makeText(AmountSet.this, getResources().getString(R.string.msg_contact_added), Toast.LENGTH_LONG).show();
} catch(Exception e){
  Toast.makeText(AmountSet.this, getResources().getString(R.string.msg_contact_error_adding), Toast.LENGTH_LONG).show();
  e.printStackTrace();
}

Monday, April 23, 2012

Android: how to draw a horizontal ruler.

<View
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />

You can just enter the above code segment in the interested layout xml file and in the place where you want the horizontal ruler and change the android parameters according to your needs of the Android application.

Have fun.

Friday, January 29, 2010

Playing High Quality Video on Nokia 5800

I think that the most of the owners of Nokia 5800 XpressMusic struggle to convert videos for their nice stunning mobile device, yet end up with failures. I have also struggled and researched a lot through the internet along with my own experiments. At last I was able to find the optimized conversion settings for the Nokia 5800 XpressMusic. Now I can convert videos to quality nHD (640x360) videos which can be played by 5800.


Don't cross your fingers.. :) It's easy to do this conversion without any difficulties. First thing is that finding a converter for this task. Super is a pretty good converter as an all-rounder. You can download the software for free with all the integrated codecs. Therefore, the one click installer will save the day.

Conversion Settings:
 
The above picture show the settings I used on Super converter. The video bit rate can be decreased even down to 1152 (may be lower) without noticeable loss in my Nokia 5800. But higher the bitrate it's higher the quality of the video. "High Quality", "Top Quality", "44K Audio" settings will also enhance the quality according to the converter's manual but I didn't try without them. You are welcome to do it and comment here. :)

Saturday, September 26, 2009

Surf Internet In Your Own Language Through Opera Mini 5

I suppose that everyone of you have already seen my earlier post about Opera Mini 5 Beta version. There I have posted that Opera can be configured to see the blogs or sites, in sinhala language. It will also show any  language since the content is rendered as images. So if you configure it as I did, then you will also see your blog on your mobile in you own language (If it's written in a language other than English. Sites written in English will render as usual)

Before configuration:


How it is done is simply like this:

Open up Opera Mini 5 and type "config:" in the address bar (without quotes) and then press "Go" button.


Now go to the bottom of the screen that you get after "config:". There you will see a parameter named "Use bitmap fonts for complex scripts".


Now click it and from the menu select "Yes" instead of "No"

Now press "Save" buttom at the bottom to confirm your selection.


After configuration:

So, now it's done. Now you can surf your own blog or website through your mobile phone and check whether it works for your language. Belowing is for my blog for the same post which was shown as squares as I showed you in the very first picture of this post.

 
Well, now it's your turn... :) Good Luck!

Wednesday, September 16, 2009

Opera Mini 5 on Nokia 5800 XpressMusic

Opera is not a newbie to the browser world. It has been with mobile users for a long time. It has become one of mostly used web browsers in the world of mobile users. There are various factly for this.
  1. Based on Java - So that it can run on many platforms.
  2. User-friendly interface.
But there was a lack during last few months in Opera since they didn't have a good version of their browser to newest symbian system 9.4v5, which is becoming one of the most popular mobile platforms.

However Opera innovative teams has been able to give the users a new version with so many new features including tab browsing. It is one of the expected items that I have been looking from a mobile browser for some time. At last, Opera has done it. There are so many other features too.
  1. Speed Dial.
  2. Power Scrolling.
  3. Password Manager.
  4. Google search box.
So I thought of showing you some of screenshots I took running Opera on Nokia 5800 XpressMusic.

Tab Browsing
 
Speed Dial

Google
 
Onscreen Keyboard 
Google Web Search
Google Image Search

Read Sinhala

Read Sinhala
Main Menu

Get Opera from here