Blog purpose for android basic example for android app developer. any query please my contact

Friday 1 May 2020

android share button example

In this an article today learn android share button. Share button using you can share an ap link or other link share follow the  share button code:

for the following site refer:button share

btnshare.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

 

                Intent shareIntent = new Intent(Intent.ACTION_SEND);

                shareIntent.setType("text/plain");

                shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Insert Subject here");

                String app_url = " https://play.google.com/store/apps/details?id=com.sql.commands.app";

                shareIntent.putExtra(Intent.EXTRA_TEXT, app_url);

                startActivity(Intent.createChooser(shareIntent, "Share via"));

            }

        });

 

Follow the full source code share button:

 

 1.MainActivity.java:

import android.content.ActivityNotFoundException;

import android.content.DialogInterface;

import android.content.Intent;

import android.net.Uri;

import android.support.v7.app.AlertDialog;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.widget.ImageButton;

import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {

    private ImageView btntutorial,btncommands,btninterview,btnrate,btnshare,btnpolicy;

    final Intent[] intent = new Intent[1];

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

       

        btnshare=(ImageView)findViewById(R.id.btnshare);

 btnshare.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {


                Intent shareIntent = new Intent(Intent.ACTION_SEND);

                shareIntent.setType("text/plain");

                shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Insert Subject here");

                String app_url = " https://play.google.com/store/apps/details?id=com.sql.commands.app";

                shareIntent.putExtra(Intent.EXTRA_TEXT, app_url);

                startActivity(Intent.createChooser(shareIntent, "Share via"));

            }

        });

 }

 }



2.activity_main.xml:


<?xml version="1.0" encoding="utf-8"?>

<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"

    android:padding="22dp"

    android:background="#FCFCFC">

    <ScrollView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content">

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:orientation="vertical">


            <TextView

                android:layout_width="329dp"

                android:layout_height="wrap_content"

                android:text="Sql Command and Tutorial"

                android:textAlignment="center"

                android:textSize="20dp"

                android:textStyle="bold" />

            <LinearLayout

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:clipToPadding="false"

                android:gravity="center"

                android:orientation="horizontal"

                android:paddingTop="25dp">



               

                    <LinearLayout

                        android:layout_width="match_parent"

                        android:layout_height="match_parent"

                        android:gravity="center"

                        android:orientation="vertical">

                        <LinearLayout

                            android:layout_width="match_parent"

                            android:layout_height="130dp"

                            android:gravity="center"

                            android:background="@color/yellow">


                            <ImageView


                                android:id="@+id/btnshare"

                                android:layout_width="64dp"

                                android:layout_height="64dp"

                                android:padding="10dp"

                                android:src="@drawable/ic_launcher" />

                        </LinearLayout>


                        <TextView

                            android:layout_width="wrap_content"

                            android:layout_height="wrap_content"

                            android:text="Share"

                            android:textColor="#000"

                            android:textSize="18dp" />

                      

                        <TextView

                            android:layout_width="wrap_content"

                            android:layout_height="wrap_content"

                            android:text="Share App"

                            android:textColor="@android:color/darker_gray" />

                    </LinearLayout>

            </LinearLayout>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

No comments:

Post a Comment