Wednesday, February 23, 2011

Heather Brooke Talking

Android: Give your applications to the authorities


Introduction :
Often it happens to some crazy developer like me to develop application to send SMS or to call, or write notes only. But weird
always requires that the user can get my application in the menu to type a sms.

Problem: Declaring the capabilities of your application OS Android. That my application is able to send sms therefore report to Android that if someone wants to send sms, it also has the option to choose your application.

Objective: Make your implementing a default application, showing his ability to Android OS.


Process: We will use the intent more particularly the intent filter. Meaning
the intentions filters: http://developer.android.com/guide/topics/intents/intents-filters.html # ifs

Intent: An intent is somehow a messenger, an emissary who carries an intention, a necessary action, information (data). A
intent alone does nothing, he cons contains sub-elements Intent-Filter in the activity and the receiver to interpret.

Intent-Filter:

An intent filter deposes

1. One or more categories: how the activity should be launched? Default? Hand?
2. One or more actions: An action can be performed by the intentions implied that our activity or application is capable of. For example my application can send an SMS, call ( action android: name = "android.intent.action.DIAL") and many more.


3. Datas: The datas are made t

In the following we will develop an application that is theoretically capable of sending sms. To do this when the user clicks on one of his contacts send an SMS, our application will show and tell him that you can choose me, I am also able to send sms.

In fact there is nothing to add the following code in your manifest:





   




   



With these lines, we are currently tell OS that our application can also send SMS or call.

Priority: The higher the number, the greater will be our application above.


Development We will develop a small application to test this:



SMS sender application :


package org.sidibe.tutorial.intentfilter.home;

import android.app . Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 *
 * @author JBromo
 *
 */
public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
   super.onCreate (saved instance state);
setContentView (R.layout.main)

final numEditText = edit text (alt text) findViewById (R.id.num)

Button text = (Button) findViewById (R.id.sms )
sms.setOnClickListener (new View.OnClickListener () {

public void onClick (View v) {final String
numEditText.getText num = (). ToString ();
launchCall (v.getContext (), a false );


}});

Button = call (Button) findViewById (R.id.call);
call.setOnClickListener (new View.OnClickListener () {

public void onClick (View v) {
numEditText.getText final String num = (). ToString ();
launch call (v.getContext () , num, true);


}});}



/ *
* * This method allow to send or call in number arguments.
     * @param contex Application context
     * @param num  the num to call or send sms
     * @param isCall if true method will launch the call else will send sms
     */
    public static void launchCall(Context contex,String num,boolean isCall)
    {
    
     if(isCall)

{Intent intent = new Intent (Intent.ACTION_DIAL, Uri.parse ("tel:" + num));
intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
contex.startActivity (intent);}

else
; {
Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse ("tel:" + num));
intent.putExtra ("sms_body", "Sms example") ;
intent.setType ("vnd.android-dir/mms-sms");
/ / Just to avoid leave our application
intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK)
      contex.startActivity(intent);
     }
    }
}


  Source complete :








0 comments:

Post a Comment