Android Intent - Open Browser, Copy Text, Share Text, Share App, More App All in one solution
How to open browser using intent android java ?
Code: // open browser
public static void openBrowser(Context context,String websiteUrl){
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(websiteUrl)));
}
Call this method in button click ?
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openBrowser(getApplicationContext(),"https://www.bdtopcoder.xyz/");
}
});
// open browser
public static void openBrowser(Context context,String websiteUrl){
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(websiteUrl)));
}
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openBrowser(getApplicationContext(),"https://www.bdtopcoder.xyz/");
}
});
How to Copy Text using intent android java ?
Code:
// copy text
public static void copyText(Context context, String text){
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Copied Text", text);
clipboard.setPrimaryClip(clip);
}
Call this method in button click ?
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String MyText = "Hello this is text";
copyText(getApplicationContext(),MyText);
}
});
// copy text
public static void copyText(Context context, String text){
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Copied Text", text);
clipboard.setPrimaryClip(clip);
}
Call this method in button click ? Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String MyText = "Hello this is text";
copyText(getApplicationContext(),MyText);
}
});
How to Share Text using intent android java ?
Code: // text share
public static void shareText(Context context, String text){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject Here");
intent.putExtra(Intent.EXTRA_TEXT, text);
context.startActivity(Intent.createChooser(intent, "Share Via"));
}
// text share
public static void shareText(Context context, String text){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject Here");
intent.putExtra(Intent.EXTRA_TEXT, text);
context.startActivity(Intent.createChooser(intent, "Share Via"));
}
Call this method in button click ?
Code: button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String MyText = "Hello this is text";
shareText(getApplicationContext(),MyText);
}
});
Call this method in button click ?
Code:
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String MyText = "Hello this is text";
shareText(getApplicationContext(),MyText);
}
});
How to Share App using intent android java ?
Code:
// share App
public static void ShareApp(Context context){
// code here
final String appPakageName = context.getPackageName();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject Here");
intent.putExtra(Intent.EXTRA_TEXT, "Download Now : https://play.google.com/store/apps/details?id="+appPakageName);
context.startActivity(Intent.createChooser(intent, "Share Via"));
} // ShareApp End Here ===========================
// share App
public static void ShareApp(Context context){
// code here
final String appPakageName = context.getPackageName();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject Here");
intent.putExtra(Intent.EXTRA_TEXT, "Download Now : https://play.google.com/store/apps/details?id="+appPakageName);
context.startActivity(Intent.createChooser(intent, "Share Via"));
} // ShareApp End Here ===========================
Call this method in button click ?
Code: button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShareApp(getApplicationContext());
}
});
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShareApp(getApplicationContext());
}
});
How to Add More App Button using intent android java ?
Code: // more App
public static void moreApp(Context context, String DeveloperName){
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:"+ DeveloperName)));
}catch (ActivityNotFoundException e){
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id="+ DeveloperName)));
}
}
// more App
public static void moreApp(Context context, String DeveloperName){
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:"+ DeveloperName)));
}catch (ActivityNotFoundException e){
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id="+ DeveloperName)));
}
}
Call this method in button click ?
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
moreApp(getApplicationContext(),"Meta Platforms, Inc.");
}
});
Thank You 🥰
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
moreApp(getApplicationContext(),"Meta Platforms, Inc.");
}
});
Thank You 🥰