0

how to call ShareActionProvider on image button click in android ? i want to share my application's link (PlayStore) if it's not possible, how to use image btton as share button? i don't want to implement actionbar.. below is my code

 <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/share" />
import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

public class MainMenu
extends Activity{

//code for displaying random images     *****************************************************************
final Random rnd = new Random();

@Override

protected void onCreate(
    final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main_menu);

    final ImageView img = (ImageView) findViewById(R.id.imgRandom);

    final String str = "img_" + rnd.nextInt(9);
    img.setImageDrawable
    (
        getResources().getDrawable(getResourceID(str, "drawable",
            getApplicationContext()))
        );
}

protected final static int getResourceID
(final String resName, final String resType, final Context ctx)
{
    final int ResourceID =
        ctx.getResources().getIdentifier(resName, resType,
            ctx.getApplicationInfo().packageName);
    if (ResourceID == 0)
    {
        throw new IllegalArgumentException
        (
            "No resource string found with name " + resName
            );
    }
    else
    {
        return ResourceID;
    }
}
       //*****************************************************************************************    ****************

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.main_menu, menu);
  return true;


ImageButton btn=(ImageButton)findViewById(R.id.imgbutton1);
    btn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            try {
                startActivity(new Intent(Intent.ACTION_VIEW,     Uri.parse("market://details?id="+com.nullsoft.prostub")));"
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW,     Uri.parse("http://play.google.com/store/apps/details?id="+com.nullsoft.prostub")));
            }// TODO Auto-generated method stub

        }

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

        }
    });
}
public void openNewActivity(View view) { 
        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);//button to open main
    }
        public void browser(View view) { 
            Intent intent = new Intent(this,Browser.class);
            startActivity(intent);//button to open browser
    }
        public void OpenBrowser(View view) { 
            Intent intent = new Intent(this,Browser.class);
            startActivity(intent);//button to open browser
    }




        {
}
}
Anonymous
  • 1,389
  • 3
  • 11
  • 16

1 Answers1

0
import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

public class First extends Activity {

    // code for displaying random images
    // *****************************************************************
    final Random rnd = new Random();

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main_menu);


 ImageButton btn = (ImageButton) findViewById(R.id.button1);
            btn.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri
                                .parse("market://details?id="
                                        + "com.nullsoft.prostub")));
                    } catch (android.content.ActivityNotFoundException anfe) {
                        startActivity(new Intent(
                                Intent.ACTION_VIEW,
                                Uri.parse("http://play.google.com/store/apps/details?id="
                                        + "com.nullsoft.prostub")));
                    }// TODO Auto-generated method stub

                }
            });
        final ImageView img = (ImageView) findViewById(R.id.imgRandom);

        final String str = "img_" + rnd.nextInt(9);
        img.setImageDrawable(getResources().getDrawable(
                getResourceID(str, "drawable", getApplicationContext())));
    }

    protected final static int getResourceID(final String resName,
            final String resType, final Context ctx) {
        final int ResourceID = ctx.getResources().getIdentifier(resName,
                resType, ctx.getApplicationInfo().packageName);
        if (ResourceID == 0) {
            throw new IllegalArgumentException(
                    "No resource string found with name " + resName);
        } else {
            return ResourceID;
        }
    }

    // *****************************************************************************************
    // ****************

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;


    }
public void openNewActivity(View view) { 
        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);//button to open main
    }
        public void browser(View view) { 
            Intent intent = new Intent(this,Browser.class);
            startActivity(intent);//button to open browser
    }
        public void OpenBrowser(View view) { 
            Intent intent = new Intent(this,Browser.class);
            startActivity(intent);//button to open browser
    }
}
Naddy
  • 2,664
  • 6
  • 25
  • 38
  • Let's not discuss all that here. It's a professional site. You may want to continue in chat. – Naddy Dec 16 '13 at 18:22
  • http://chat.stackoverflow.com/rooms/43281/discussion-between-naddy-and-anonymous Follow this link. – Naddy Dec 16 '13 at 18:35