Apr 21, 2012

How to make a phone call from your application


To enable your application to initiate a phone call, you must set permissions in the manifest file:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.       package="com.bubudsadasdas"
  4.       android:versionCode="1"
  5.       android:versionName="1.0">
  6.     <application android:icon="@drawable/icon"android:label="@string/app_name">
  7.         <activity android:name=".phonecalls"
  8.                   android:label="@string/app_name">
  9.             <intent-filter>
  10.                 <action android:name="android.intent.action.MAIN" />
  11.                 <category android:name="android.intent.category.LAUNCHER" />
  12.             </intent-filter>
  13.         </activity>
  14.     </application>
  15.     <uses-sdk android:minSdkVersion="3" />
  16. <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
  17. </manifest>
Now create a new activity with a call method. It should look like this:
  1. private void call(String num) {
  2.     try {
  3.         Intent callIntent = new Intent(Intent.ACTION_CALL);
           num="tel:"+num;
  4.         callIntent.setData(Uri.parse(num));
  5.         startActivity(callIntent);
  6.     } catch (ActivityNotFoundException e) {
  7.         Log.e("helloandroid dialing example""Call failed", e);
  8.     }
  9. }
What happens when you start a phone call depends, in part, on the telephone network. The number may be incorrect. The network may be busy or otherwise unavailable. The call can be interrupted. Here, however, you see no error-handling logic, except for catching and logging exceptions that can be thrown if error encounters a problem when finding applications that can process Intent objects.
Now call the call :) method in an empty activity:

  1. import android.app.Activity;
    import android.content.ActivityNotFoundException;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;

    public class phonecalls extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    private EditText mEtNum;
    private Button mBtnCall;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mEtNum = (EditText) findViewById(R.id.xEtNumber);
    mBtnCall = (Button) findViewById(R.id.xBtnCall);
    mBtnCall.setOnClickListener(this);
    }

    public void onClick(View v) {
    String num = mEtNum.getText().toString();
    if (num.length() > 5) {
    call(num);
    } else {
    Toast.makeText(getApplicationContext(), " Wrong Number ", 1).show();
    }
    }

    private void call(String num) {
    try {
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    num = "tel:" + num;
    callIntent.setData(Uri.parse(num));
    startActivity(callIntent);
    } catch (ActivityNotFoundException activityException) {
    Log.e("dialing-example", "Call failed", activityException);
    }
    }

    }




Apr 19, 2012

Create custom or own content Provider

Hey everyone,
So the following tutorial will hopefully give you a good idea of how to implement your own ContentProvider. I know that there are a lot of pretty good sites out there with some good code snippets, but I’ve noticed that not many really help the developer understand what’s going on step by step so my goal is to not only provide an example of a fully implemented ContentProvider but also to step you through the process.
So I’ll start by just posting all of the code, and I’ll go through it slowly afterwards. We’ll start with the Custom Content Provider itself:

package com.bened;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

/*
* Creating Custom Content provider
* to create custom content provider
*
* create a class that class should be extends ContentProvider
* and override insert , oncreate , query , update methods ,
*/
public class MyProvider extends ContentProvider {
// CONTENT_URI : BASE URL FOR CONTENT PROVIDER

public static final Uri CONTENT_URI = Uri
.parse("content://com.bened/contenttable");
private MyDataBase mdb;
private SQLiteDatabase db;

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}

/*
*
* get URL type
*/
@Override
public String getType(Uri uri) {
return null;
}

/*
*
* inserting values to database
*/

@Override
public Uri insert(Uri uri, ContentValues values) {
db.insert("contenttable", null, values);
return null;
}

/*
* allocating memory to database and giving permissions to database
*/
@Override
public boolean onCreate() {
mdb = new MyDataBase(getContext(), "ContentData", null, 2);
db = mdb.getWritableDatabase();
return true;
}

/*
*
* TO fetch values from db
*/
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
String col[] = { "_id", "no", "name", "email" };
Cursor c = db.query("contenttable", col, null, null, null, null, null);
return c;
}

/*
*
* for updating values to database
*/
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}

}


Okay so let’s go through this step by step. First, when you extend ContentResolver, there are 6 methods you need to overwrite:
query()
insert()
update()
delete()
getType()
onCreate()

Normally these are just wrapper functions around the raw SQL queries. For instance, the method:

db.delete(tableName, where, whereArgs);

"delete from " + tableName + " where " + where + " ? " + whereArgs"


So for those who know SQL, if I wanted to delete the note with title “Hello World” then my queries would look like:

// wrapper query
db.delete(NOTES_TABLE_NAME, Notes.TITLE + "= ' " + "Hello World" + " ' ", null);

// real query when translated
String query = "delete from notes where title = 'Hello World' ";
And so as you look at how I overwrite the 6 methods, you’ll see that I’m simply taking in the parameters and inputting them appropriately into the wrapper methods. Of course, you can override them as you like depending on what you want your application to do. Perhaps your application is ONLY worried about retrieving the average of some numbers. Then in your query() method, maybe instead of querying for the numbers normally, and then always having to iterate through the numbers and find the average from the JAVA side, you could customize your query to automatically return the average BY DEFAULT

But in case you’re still confused, let’s look at an example:

create a table with specified 4 columns

@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
String col[] = { "_id", "no", "name", "email" };
Cursor c = db.query("contenttable", col, null, null, null, null, null);
return c;
}


One thing to note here is that Android requires that the unique id column have name “_id”

This is extremely important as otherwise your content provider will not get registered properly.
Now, one last thing before I get to how you register it in your Manifest is what this AUTHORITY String is all about. In my case it was:

public static final String CONTENT_URI = "path ";


And so this AUTHORITY basically just helps you define the CONTENT_URI of your ContentProvider (i.e. the path to your database), and you will register your provider in your Manifest like so:

android:exported="true"
android:name="MyProvider"
android:authorities="com.bened">

note : name indicates content provider name
authotities : mainl what uri you are using as a path


And so you see that I define my content providers in a way such that the project path is equal to the authorities path (again, not required, but probably recommended for simplicity and organizational issues).
And that’s it! Now you have a fully registered and created ContentProvider.








for source clik here :

ContentProvider Link1


Content provider Link2


Download both projects
1-> run first project content provider one demo  -> insert some values in that
2-> run content provider two demo we can view which is inserted first value .

Apr 12, 2012

7 Things You Should Never Do During An Interview

With the job market extremely tight, even the small stuff counts, especially when you’re on a job interview. That’s why it’s so important not to say or do the wrong things, since that first impression could end up being the last one.
With that in mind, here are seven deadly sins of job interviewing.

1. Don’t Be Late To the Interview
Even if you car broke down or the subway derailed, do everything you can to get to that job interview on time.
“If you have a legitimate excuse it’s still hard to bounce back,” says Pamela Skillings, co-founder of job coaching firm Skillful Communications. “People are suspicious because they hear the same excuses all the time.”
On the flip side, you don’t want to show up too early and risk appearing desperate, but you do want to be there at least five minutes early or at the very least on time.

2. Don’t Show Up Unprepared
It seems simple, but countless people go on job interviews knowing very little about the company they are interviewing with when all it would take is a simple Google search to find out. As a result, they end up asking obvious questions, which signal to the interviewer that they are too lazy to prepare.
“Don’t ask if the company is public or private, how long it’s been in business and where they do their manufacturing,” says Mark Jaffe, president of Wyatt & Jaffe, the executive search firm. “Sharpen your pencil before you go to school.”

3. Don’t Ask About Salary, Benefits, Perks
Your initial interview with a company shouldn’t be about what the company can do for you, but what you can do for the company. Which means the interview isn’t the time to ask about the severance package, vacation time or health plan. Instead you should be selling yourself as to why the company can’t live without you.
“Your interest should be about the job and what your responsibilities will be,” says Terry Pile, Principal Consultant of Career Advisors. “Asking about vacation, sick leave, 401K, salary and benefits should be avoided at all costs.”

4. Don’t Focus On Future Roles Instead Of The Job At Hand
The job interview is not the time or place to ask about advancement opportunities or how to become the CEO. You need to be interested in the job you are actually interviewing for. Sure, a company wants to see that you are ambitious, but they also want assurances you are committed to the job you’re being hired for.
“You can’t come with an agenda that this job is just a stepping stone to bigger and better things,” says Jaffe.

5. Don’t Turn The Weakness Question Into A Positive
To put it bluntly, interviewers are not idiots. So when they ask you about a weakness and you say you work too hard or you are too much of a perfectionist, chances are they are more apt to roll their eyes than be blown away. Instead, be honest and come up with a weakness that can be improved on and won’t ruin your chances of getting a job.
For instance, if you are interviewing for a project management position, it wouldn’t be wise to say you have poor organizational skills, but it’s ok to say you want to learn more shortcuts in Excel. “Talk about the skills you don’t have that will add value, but aren’t required for the job,” says Pile.

6. Don’t Lie
Many people think its ok to exaggerate their experience or fib about a firing on a job interview, but lying can be a surefire way not to get hired. Even if you get through the interview process with your half truths, chances are you won’t be equipped to handle the job you were hired to do. Not to mention the more you lie the more likely you are to slip up.
“Don’t exaggerate, don’t make things bigger than they are and don’t claim credit for accomplishments you didn’t do,” says Jaffe. “You leave so much room in your brain if you don’t have to fill it with which lie you told which person.”

7. Don’t Ask If There’s Any Reason You Shouldn’t Be Hired
Well meaning career experts will tell you to close your interview by asking if there is any reason you wouldn’t be hired. While that question can give you an idea of where you stand and afford you the opportunity to address any concerns, there’s no guarantee the interviewer is going to be truthful with you or has even processed your information enough to even think about that.
“All you are doing is prompting them to think about what’s wrong with you,” says Skillings.


Read more: http://www.glassdoor.com/blog/deadly-interview-sins/#ixzz1rtJ149nO

Apr 6, 2012

Android Application Security, How should we handle ?








Android platform fast becoming very popular between users and a target of malicious hackers as well. Therefore, Application security is very critical. Application security is how your context are secure. Many Apps have access to important information and data related to the user. Therefore, it's very important to protect these data from other malicious Apps.

Android system is a privilege-separated operating system, in which each application runs with a distinct system identity (Linux user ID and group ID). Parts of the system are also separated into distinct identities. A central design point of the Android security architecture is that no application, by default, has permission to perform any operations that would adversely impact other applications, the operating system, or the user. Well, that means everything is fine!!?? Wrong!

While each application runs in its own UNIX UID, sharing can occur through application-level interactions. Interaction based on components like Activity, service, content provider and Broadcast receiver, where an Activity represents a user interface or a screen, service represents the background processing, Content provider provides a standardized interface for sharing data, and Broadcast receivers are intents handler, where intents are objects used for inter-component communication.
Therefore, you need as a developer to be aware of how much data other Apps can access from your App.
Here are some important things in terms of security and permissions that you may need to consider when developing your App:

1) android:sharedUserId (in AndroidManifest.xml) :


The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID. Application with the same user ID can access each other's data and, if desired, run in the same process.

2) Determining the permission of a created file:

When you create a file using for example openFileoutput() method, the created file will be Private to your App by default, but you can change this permission as desired using:

- MODE_PRIVATE : the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).
- MODE_WORLD_READABLE: allow all other applications to have read access to the created file.
- MODE_WORLD_WRITEABLE: allow all other applications to have write access to the created file.


3) The same idea is applied when you create a new data base:

SQLiteDatabase myDB = openOrCreateDatabase("test",MODE_WORLD_READABLE, null);
Here, the data base is readable to any other App on the device. Be careful!

4) android:exported (in AndroidManifest.xml) :

Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID. Best Practice: Always set the “exported” attribute.