onTouchEvent Example in Android
Definition : Create an application to draw line on the screen as user drag his finger.
File Name : E20.java
package bsr.exa;
import android.app.Activity;
import android.os.Bundle;
public class E20 extends Activity {
/** @author Bipin S Rupadiya , www.bipinrupadiya.blogspot.com
*
*
* 20) Create an application to draw line on the screen as user drag his finger.
*
* */
import android.app.Activity;
import android.os.Bundle;
public class E20 extends Activity {
/** @author Bipin S Rupadiya , www.bipinrupadiya.blogspot.com
*
*
* 20) Create an application to draw line on the screen as user drag his finger.
*
* */
Labels:
Android,
Mobile Computing
Android Sending SMS Example
Definition : Create an application to send message between two emulators
File Name : E21Activity.java
Camera Example in Android
Definition: Create an application to take picture using native application
File Name :
package bsr.exa;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class E22Activity extends Activity {
/** Called when the activity is first created. */
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv=(ImageView)findViewById(R.id.imageView1);
Button b =(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, 0);
}
});
}
protected void OnActivityResult(int requestCode,int resultcode,Intent data)
{
Bitmap bm=(Bitmap)data.getExtras().get("data");
iv.setImageBitmap(bm);
}
}
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class E22Activity extends Activity {
/** Called when the activity is first created. */
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv=(ImageView)findViewById(R.id.imageView1);
Button b =(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, 0);
}
});
}
protected void OnActivityResult(int requestCode,int resultcode,Intent data)
{
Bitmap bm=(Bitmap)data.getExtras().get("data");
iv.setImageBitmap(bm);
}
}
File Name : AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bsr.exa"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".E22Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bsr.exa"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".E22Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MediaStore.Images Content Provider example in android
Definition: 23) Create an application to pick up any image from the native application gallery and display it on the screen
File Name : EX23.java
package bsr.exa;
import java.io.File;
import java.io.FileInputStream;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore.Images.Media;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class E23 extends Activity {
/**
*
* @author Bipin S Rupadiya , www.bipinrupadiya.com
*
* 23) Create an application to pick up any image from the native application gallery and display it on the screen.
*
* Note : First add a file to sdcard and check with media scanner (from dev tools)
**/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
String[] projection={Media.DISPLAY_NAME, Media.DATA, Media.SIZE};
Cursor c=managedQuery(Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
ImageView ivImage=(ImageView)findViewById(R.id.myImg);
File file = null;
String imgName = null ;
if(c.getCount()>0)
{
while(c.moveToNext())
{
file=new File(c.getString(1)); //after completing loop, it take last image from native Gallery to display.
imgName=c.getString(0);
}
c.close();
FileInputStream fis=new FileInputStream(file);
byte[] buffer=new byte[fis.available()];
fis.read(buffer);
Bitmap bm=BitmapFactory.decodeByteArray(buffer, 0, buffer.length);
TextView txtTitle=(TextView)findViewById(R.id.txtTitle);
txtTitle.setText(imgName.toString());
ivImage.setImageBitmap(bm);
}
}
catch(Exception e)
{
Toast.makeText(E23.this, "Error: "+e, Toast.LENGTH_LONG).show();
}
}
}
import java.io.File;
import java.io.FileInputStream;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore.Images.Media;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class E23 extends Activity {
/**
*
* @author Bipin S Rupadiya , www.bipinrupadiya.com
*
* 23) Create an application to pick up any image from the native application gallery and display it on the screen.
*
* Note : First add a file to sdcard and check with media scanner (from dev tools)
**/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
String[] projection={Media.DISPLAY_NAME, Media.DATA, Media.SIZE};
Cursor c=managedQuery(Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
ImageView ivImage=(ImageView)findViewById(R.id.myImg);
File file = null;
String imgName = null ;
if(c.getCount()>0)
{
while(c.moveToNext())
{
file=new File(c.getString(1)); //after completing loop, it take last image from native Gallery to display.
imgName=c.getString(0);
}
c.close();
FileInputStream fis=new FileInputStream(file);
byte[] buffer=new byte[fis.available()];
fis.read(buffer);
Bitmap bm=BitmapFactory.decodeByteArray(buffer, 0, buffer.length);
TextView txtTitle=(TextView)findViewById(R.id.txtTitle);
txtTitle.setText(imgName.toString());
ivImage.setImageBitmap(bm);
}
}
catch(Exception e)
{
Toast.makeText(E23.this, "Error: "+e, Toast.LENGTH_LONG).show();
}
}
}
File Name :AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="bsr.exa">
<uses-sdk android:minSdkVersion="8" />
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:label="@string/app_name" android:name="E23">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="bsr.exa">
<uses-sdk android:minSdkVersion="8" />
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:label="@string/app_name" android:name="E23">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step by Step Android Examples for Beginners
This Post “Step by step Android Examples for Beginners” is the result of many request I got through the web. Here, I would like to provide, the step by step example on Android which can be helpful to the one who have just started the journey of Mobile Application Development using Android as Beginners.
Subscribe to:
Posts (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- CSS (3)
- Configure Tomcat7 (2)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- WTAD (34)
- c (11)
- install Tomcat (2)
- linux (8)
- shell script (33)
- unix (22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.