Quantcast
Channel: Android Programming Tutorials » free Android codes
Viewing all articles
Browse latest Browse all 7

Share Your Data in Android

$
0
0

This example shows how you can share your text and data with your friends.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it ShareYourData.

2.) Write following into activity_main.xml:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#C0C0C0"
    android:orientation="vertical" >
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Share Data" 
        android:onClick="shareData"
        />
</LinearLayout>

3.) Write following into res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="myText">
		<item name="android:textColor">#000000</item>
		<item name="android:textSize">22sp</item>
		<item name="android:padding">3dip</item>
	</style>
</resources>

4.) Run for output.

Steps:

1.) Create a project named ShareYourData and set the information as stated in the image.

Build Target: Android 4.0
Application Name: ShareYourData
Package Name: com. example. ShareYourData
Activity Name: MainActivity
Min SDK Version: 11

2.) Open MainActivity.java file and write following code there:

package com.example.shareyourdata;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		}
	public void shareData(View view) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("text/plain");
		intent.putExtra(Intent.EXTRA_TEXT, "This is my shared text");
		startActivity(Intent.createChooser(intent, "Share this text via"));
	}
}

3.) Compile and build the project.

Output


Viewing all articles
Browse latest Browse all 7

Trending Articles