Algorithm:
1.) Create a new project by File-> New -> Android Project name it ShareYourData.
2.) Write following into activity_main.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 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:
1 2 3 4 5 6 7 8 | <?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
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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





0 comments:
Post a Comment