Showing posts with label ANDROID TRAINING KERALA. Show all posts
Showing posts with label ANDROID TRAINING KERALA. Show all posts

Crop Image in Android

Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", int_Width_crop);
intent.putExtra("outputY", int_Height_crop);
intent.putExtra("scale", false);
intent.putExtra("return-data", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri());
//  Uri imagePath = getImageUri();
startActivityForResult(intent, CHOOSE_PICTURE);
------------------------------------------------------------------------------------------

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST)
{
Uri imagePath = getImageUri();
// System.out.println("Activity result"+imagePath);
}
if (requestCode == CROP_FROM_CAMERA)
{
final Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
// mPhoto = photo;
// mPhotoChanged = true;
myImage.setImageBitmap(photo);
// setPhotoPresent(true);
}
}
if (requestCode == CHOOSE_PICTURE)
{
final Bundle extras = data.getExtras();
if (extras != null) {
Log.d("photo", "extras is not null");
Uri selectedImage = getImageUri();
getContentResolver().notifyChange(selectedImage, null);
ContentResolver cr = getContentResolver();
Bitmap bitmap;
try {
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
Log.d("photo",
"data.getAction() is not null. setting image.");
this.myImage.setImageBitmap(bitmap);
} catch (Exception e) {
Toast.makeText(this, "Failed to load",
Toast.LENGTH_SHORT).show();
Log.e("photo", e.toString());
}
}
}

Android Training in Kerala

How To start audio using Service in android

public class MyServices extends Service{
private static final String TAG = “MyService”;
MediaPlayer player;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
//Toast.makeText(this, “Back”, Toast.LENGTH_LONG).show();
Log.d(TAG, “onCreate”);
player = MediaPlayer.create(MyServices.this, R.raw.natural);
player.setLooping(true); // Set looping
}
@Override
public void onDestroy() {
Toast.makeText(this, “Background Sound Stopped”, Toast.LENGTH_LONG).show();
Log.d(TAG, “onDestroy”);
player.stop();
player.release();
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, “Background Sound Enabled”, Toast.LENGTH_LONG).show();
Log.d(TAG, “onStart”);
player.start();
}
}



// in manifest file
<service android:enabled=”true” android:name=”.class name” />


TO start audio
startService(new Intent(Settings.this, MyServices.class));

TO stop service
stopService(new Intent(Settings.this, MyServices.class));


Android Training in Kerala

How to get phone contacts

To get phone contacts ,we use

Cursor c = getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder)

We have to put an uri for getting contacts.

full code


protected void pickContact() {
//startActivityForResult(new Intent(Intent.ACTION_PICK, People.CONTENT_URI), 0);
Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
        startManagingCursor(cursor);
       
        // start mappings
        String[] columns = new String[] {People.NAME, People.NUMBER};
        int[] names = new int[] {R.id.phone1};
     
     
       myAdapter = new SimpleCursorAdapter(this, R.layout.phonecontacts, cursor, columns, names);
   
       list.setAdapter(myAdapter);
   
             
    }

WIDGETS AND LAYOUTS IN ANDROID APPLICATION

In Android ,we use various widgets for creating an activity.Before that lets come to"Activity".

WHAT IS AN ACTIVITY ?
Activities are the building blocks of the user interface.It is similar to form in html.Generally they are public classes inheriting from android.Activity base class.

When an activity is started, the onCreate() method is invoked. We will come to that point later.

Various Widgets in Android are:

1:TextView(simialr to label in HTML).
2:Button:(Same as in HTML).
3:Spinner(Similar to dropdown in HTML).
4:EditText(Similar to Textbox in  HTML).
5:RadioButton   etc.................................................................


XML BASED LAYOUTS IN ANDROID


Android uses xml based layouts for designing an activity.These layout files are reside inside res/layout directory.Each Xml file contains a tree of elements specifying a layout of widgets and containers.

sample 


<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />

Here layout_width,layout_height,text etc are the attributes.  android:layout_width="fill_parent"  tell android to have the textview's width fill the parent--means entire screen.

Check this in your emulator and find out the difference between "fill parent" and "wrap content".

Creating Your First Android Application

Requirements

1:Eclipse IDE
2:Android Sdk(Download from http://developer.android.com/sdk/index.html)
3:JDK 1.6

By using Eclipse IDE,you can create a project (select File > New >Project then choose Android >Android Project











Next step  is to give meaningful project name.
After giving a name,locate your workspace(*Workspace is the location where you actually save your project).
                        In order to develop an android application ,we requires Google API.That is  inside the Build Target block.So select an API.


After selecting all these,we should specify our package name.package name is used for distinguishing our current project from other projects(eg:"com.study.tutorial1").Then Select a version and after doing all these ,click "Finish".


NOW YOUR PROJECT IS READY..................
 

Popular Posts

About Me

Only For Sharing Android Related Things...

Facebook Fan Page