Opening a URL in Android's web browser from my application? - android

Opening a URL in Android's web browser from my application?
I tried this:
try {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link));
startActivity(myIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No application can handle this request."
+ " Please install a webbrowser", Toast.LENGTH_LONG).show();
e.printStackTrace();
}

Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(playStoreLink));
startActivity(browserIntent);
you should check your link otherwise you have to show your logcate.

You can try the following:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onOpenWebBrowser(View v)
{
Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
webPageIntent.setData(Uri.parse("https://www.google.co.in/"));
try {
startActivity(webPageIntent);
} catch (ActivityNotFoundException ex) {
}
}

Related

Open external links (Whatsapp - tel) in andriod webview

Dears
I have Webview app and I can't open any WhatsApp links or telephone
I use the following code
#Override
public void menuItemClicked(Action action, MenuItem item) {
if (WebToAppWebClient.urlShouldOpenExternally(action.url)){
//Load url outside WebView
try {
startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(action.url)));
} catch(ActivityNotFoundException e) {
if (action.url.startsWith("intent://") || (action.url.startsWith("whatsapp:")
|| (action.url.startsWith("tel:")))){
startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(action.url.replace("intent://", "http://"))));
new Intent(Intent.ACTION_VIEW, Uri.parse(action.url.replace("whatsapp:", "http://")));
new Intent(Intent.ACTION_VIEW, Uri.parse(action.url.replace("tel:", "http://")));
} else {
Toast.makeText(this, getResources().getString(R.string.no_app_message), Toast.LENGTH_LONG).show();
}
}```

Open User Page in Tiktok app on Android with Intent

Is there something similar to the Soundcloud Uri ("soundcloud://users:" + "soundcloud_username") that allows an app user to open the Tiktok app and go to another user's page, like the Soundcloud code below?
Soundcloud code reference: Force a Soundcloud track to open in Soundcloud app on Android
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("soundcloud://users:" + "soundcloud_username"));
startActivity(intent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://soundcloud.com/"+string_soundcloudLink_profile)));
}
private fun openTikTokProfile() {
val uri: Uri = Uri.parse("https://www.tiktok.com/#${username}")
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.setPackage("com.zhiliaoapp.musically")
if (intent.resolveActivity(requireActivity().packageManager) != null) {
startActivity(intent)
}
}
Hey I found the solution But its in xamarin.android
private void urlclick(object sender, EventArgs e)
{
PackageManager manager = PackageManager;
var U =Android.Net.Uri.Parse("http://vm.tiktok.com/tiktokulr");///Add URL of you tiktok account
Intent i;
Intent icheck;
try
{
i = new Intent(Intent.ActionView, U);
icheck = manager.GetLaunchIntentForPackage("com.zhiliaoapp.musically");
if (icheck == null)
{
Toast.MakeText(this, "please install tiktok in your phone", ToastLength.Short).Show();
throw new PackageManager.NameNotFoundException();
}
else
{
StartActivity(i);
}
}
catch (PackageManager.NameNotFoundException exp)
{
}

How do I launch an app programatically?

My code should check- if a particular app is installed:
yes - launch it
no - launch play store and search for the app
public void checkXposedInstaller() {
String packageName = "de.robv.android.xposed.installer";
//check if app is installed
try {
PackageManager manager = getPackageManager();
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
checkXposedFramework();
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(this, "app not found", Toast.LENGTH_LONG).show(); //*** download and root install apk
// search on browser/market
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (android.content.ActivityNotFoundException e1) {
Toast.makeText(this, "no app found to handle request", Toast.LENGTH_LONG).show();
}
}
}
But it is doing none of those. However, the strange thing is, when I swap the package name with something else like com.google.app, it works like a charm! what am I doing wrong here?
PS: the try block does nothing, no crashes, no logs caught
Try this:
public static void launchPackageOrGotoStore(Context context, String packageName) {
try {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
context.startActivity(intent);
} catch (ActivityNotFoundException | NullPointerException ex) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + packageName))
);
} catch (ActivityNotFoundException e) {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + packageName)));
}
}
}
Usage:
launchPackageOrGotoStore(context, "com.facebook.katana");
Just try to start the Intent for the package name and catch ActivityNotFoundException. Then launch the Play store app first, the last try is to launch the play store web if both the app and the play store app don't exist.
Check below code and you are able to check that app is install or not if not then you are able to redirect to playstore:
boolean isAppInstalled = appInstalledOrNot("de.robv.android.xposed.installer");
if (isAppInstalled) {
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("de.robv.android.xposed.installer");
startActivity(LaunchIntent);
} else {
// Do whatever we want to do if application not installed
// For example, Redirect to play store
final String appPackageName = "de.robv.android.xposed.installer"; // getPackageName() from Context or Activity object
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
Function Check that application is install or not:
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}

How can I launch Instagram app on button click Android Studio

I just want to open Instagram application on button click (if installed) on minimum API 16.
What I am trying is:
Intent likeIng = new Intent(Intent.ACTION_VIEW);
likeIng.setPackage("com.instagram.android");
try {
startActivity(likeIng);
} catch (ActivityNotFoundException e) {
Toast.makeText(this,"Instagram Not Installed!",Toast.LENGTH_LONG).show();
}
But when running on a phone where Instagram is installed, it's not launching it.
pass this this Uri to your intent.
Uri uri = Uri.parse("http://instagram.com/_u/YOUR_USERNAME");
Intent i= new Intent(Intent.ACTION_VIEW,uri);
i.setPackage("com.instagram.android");
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/xxx")));
}
Use PackageManager.getLaunchIntentForPackage(String packageName)
use this. I already used this.
Intent i = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
startActivity(i);
Try this method:
private void callInstagram() {
String apppackage = "com.instagram.android";
Context cx=this;
try {
Intent i = cx.getPackageManager().getLaunchIntentForPackage(apppackage);
cx.startActivity(i);
} catch (Exception e) {
Toast.makeText(this, "Sorry, Instagram Apps Not Found", Toast.LENGTH_LONG).show();
}
}

Redirect User to Play store From Android App

Hello Friends i am developing an app , i had an requirement to redirect user to play store from my app , i searched a lot but no success .. code is below
Button1.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v_arg) {
try {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/"));
startActivity(viewIntent);
}catch(Exception e) {
Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
Button2.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v_arg) {
try {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("market://details?id=com.adeebhat.rabbitsvilla/"));
startActivity(viewIntent);
}catch(Exception e) {
Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
More sophisticated way:
final String appPackageName = getPackageName(); // package name of the app
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
You just need to remove character "/" from the url
So will be
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/
to
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla
So finally
Button1.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v_arg) {
try {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla"));
startActivity(viewIntent);
}catch(Exception e) {
Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
Remove slash from url. You have added extra slash after package name.
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/
It should be
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla
Both uri should be
Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla")); // Removed slash
and
Uri.parse("market://details?id=com.adeebhat.rabbitsvilla")); // Removed slash

Categories

Resources