Thursday 25 September 2014

Download android apk files from play store

Wednesday 24 September 2014

ContextMenu with Header in Android


Download project here : ContextMenuwithHeader.zip

for context menu options create menu.xml file under menu folder under res folder
 menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/item_option1"
        android:title="Option1">
    </item>
    <item
        android:id="@+id/item_option2"
        android:title="Option2">
    </item>
    <item
        android:id="@+id/item_option3"
        android:title="Option3">
    </item>
    <item
        android:id="@+id/item_option4"
        android:title="Option4">
    </item>
    <item
        android:id="@+id/item_option5"
        android:title="Option5">
    </item>

</menu>


activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${packageName}.${activityClass}" >

    <Button
        android:id="@+id/button_longPress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="144dp"
        android:text="Long press here" />

</RelativeLayout>


MainActivity.java:
package com.ram.customcontextmenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Calling button reference from xml layout
        Button contextMenu_button = (Button) findViewById(R.id.button_longPress);

        // registering button for the context menu
        registerForContextMenu(contextMenu_button);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
    {
        super.onCreateContextMenu(menu, v, menuInfo);
        // setting header title for the context menu
        menu.setHeaderTitle("Select an Option");
        // Setting header icon
        menu.setHeaderIcon(R.drawable.ic_launcher);
        // Inflating menu.xml file from menu folder
        getMenuInflater().inflate(R.menu.menu, menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item)
    {
        // To listen action for the context menu options
        switch (item.getItemId())
        {
        case R.id.item_option1:
            Toast.makeText(getApplicationContext(), "option1 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option2:
            Toast.makeText(getApplicationContext(), "option2 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option3:
            Toast.makeText(getApplicationContext(), "option3 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option4:
            Toast.makeText(getApplicationContext(), "option4 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option5:
            Toast.makeText(getApplicationContext(), "option5 selected",
                    Toast.LENGTH_SHORT).show();
            break;
        }
        return super.onContextItemSelected(item);

    }
}
 

Sunday 21 September 2014

Android Fresher Openings

Android Fresher Openings

Number of openings : 5

Location : Hyderabad

Candidate should have strong knowledge in Android.

Send you resumes to : rambabu.mareedu@gmail.com

visit : http://ramsandroid4all.blogspot.in/

Thursday 18 September 2014

Loading Image from Gallery example in Android

First of all create some string values in strings.xml as follows
strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Loading Images From Gallery</string>
    <string name="hello_world">Hello world!</string>
    <string name="load_image_button_text">Load Image From Gallery</string>
    <string name="image">image</string>


</resources>


Next create one button and image as follows
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="loadImageFromGallery"
        android:text="@string/load_image_button_text" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/image"
        android:src="@drawable/ic_launcher" />

</LinearLayout>


MainActivity.java:
package com.ram.loadingimagesfromgallery;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity
{
    // ImgeView to display image from gallery
    ImageView imageView;
    // variable to hold request code value
    private final int REQ_CODE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initializing user interface from activity_main.xml file
        imageView = (ImageView) findViewById(R.id.imageView);
    }

    // Method to listen action for the button
    public void loadImageFromGallery(View view)
    {
        // Intent to mention which kind of action to be performed
        Intent intent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        // To launch intent
        startActivityForResult(intent, REQ_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQ_CODE && resultCode == RESULT_OK && data != null)
        {
            // Retrieve data this intent is operating on
            Uri selectedImage = data.getData();
            // The Media provider contains meta data for all available media on
            // both internal and external storage devices.

            String[] filePathColumn =
            { MediaStore.Images.Media.DATA };
            // Query the given URI, returning a Cursor over the result set.
            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn,
                    null, null, null);
            // Move the cursor to the first row.
            cursor.moveToFirst();
            // To get given column index number
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            // Returns the value of the requested column as a String.
            String picturePath = cursor.getString(columnIndex);
            // Closes the Cursor, releasing all of its resources and making it
            // completely invalid. Unlike deactivate() a call to requery() will
            // not make the Cursor valid again.

            cursor.close();
            // Sets a Bitmap as the content of this ImageView.
            imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

        }

    }
}

Wednesday 17 September 2014

Converting Bitmap to Byte Array in Android

public byte[] convertBitmapToByteArray(Bitmap bitmap)
    {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

        byte[] bitmapData = stream.toByteArray();

        return bitmapData;
    }

Converting Byte Array to Bitmap in Android

public Bitmap ByteArrayToBitmap(byte[] byteArray)
    {
        ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(byteArray);
        Bitmap bitmap = BitmapFactory.decodeStream(arrayInputStream);
        return bitmap;
    }

Tuesday 2 September 2014

Transparent Live Wallpaper Application

Hi viewers ,

I have developed Transparent Live Wallpaper application. You can give a try to this app and give your valuable Rating and Feedback .

Yours,
ramsandroid4all.

you can download this app by clicking the link below
 https://play.google.com/store/apps/details?id=com.ram.transparentlivewallpaper

Mirror Live Wallpaper Android Application

Hi viewers ,

I have developed Mirror Live Wallpaper application. You can give a try to this app and give your valuable Rating and Feedback .

Yours,
ramsandroid4all.

you can download this app by clicking the link below
https://play.google.com/store/apps/details?id=com.ram.w