Open external links (Whatsapp - tel) in andriod webview - android

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();
}
}```

Related

<a> tag link from asset folder html file

In webview html file which is in asset folder, i use just username of facebook id. here is in MainActivity included fixed URL for facebook app and browser. the problem is that when i click someone's profile link Showing ::::URL like this
https://www.facebook.com/file///{FBuserID}
fb://profile/file///{FBuserID}
But I need like this....
https://www.facebook.com/{FBuserID}
fb://profile/{FBuserID}
Its from MainActivity.java (here is in last ELSE included two fixed url
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
Toast.makeText(getActivity(),(getString(R.string.call_toast)),
Toast.LENGTH_LONG).show();
return true;
} else if (url.startsWith("mailto:")) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(url));
startActivity(intent);
Toast.makeText(getActivity(),(getString(R.string.email_toast)),
Toast.LENGTH_LONG).show();
return true;
} else {
if (isAppInstalled(liContext, "com.facebook.orca") || isAppInstalled(liContext, "com.facebook.katana")
|| isAppInstalled(liContext, "com.example.facebook") || isAppInstalled(liContext, "com.facebook.android")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+url)));
Toast.makeText(getActivity(),(getString(R.string.facebook_view)),
Toast.LENGTH_LONG).show();
}else{
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"+url)));
Toast.makeText(getActivity(),(getString(R.string.not_fb)),
Toast.LENGTH_LONG).show();
}
return true;
}
}
});

How to use correct intents for a WebView on vulnerable intent scheme hijacking

I have this WebView in which I open a page that has links to open whatsapp, messenger and phone call which would not open if it was not in a browser.
Google obviously did not like it and says I have to skip this part.
Is there any way to get rid of this?
The original code is the commented, on that my app is opened on a web navigator and I don't want it. so I used the intent scheme to open any link on the page.
public class MainActivity extends AppCompatActivity {
WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = findViewById(R.id.web);
wv.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
/* if (url.startsWith("tel:") || url.startsWith("whatsapp:") || url.startsWith("intent")){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
//view.reload();
return true;
}
view.loadUrl(url);
return true;*/
/* if (url.startsWith("http:") || url.startsWith("https:")) {
return false;
}
//agregar validacion para email, telefono y whatsapp
if(url.startsWith("tel://")|| url.startsWith("mailto://")|| url.startsWith("whatsapp://")){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}*/
if (url.startsWith("http")) return false;//open web links as usual
//try to find browse activity to handle uri
Uri parsedUri = Uri.parse(url);
PackageManager packageManager = getApplicationContext().getPackageManager();
Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
if (browseIntent.resolveActivity(packageManager) != null) {
getApplicationContext().startActivity(browseIntent);
return true;
}
//if not activity found, try to parse intent://
if (url.startsWith("intent:")) {
try {
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
if (intent.resolveActivity(getApplicationContext().getPackageManager()) != null) {
getApplicationContext().startActivity(intent);
return true;
}
//try to find fallback url
String fallbackUrl = intent.getStringExtra("browser_fallback_url");
if (fallbackUrl != null) {
wv.loadUrl(fallbackUrl);
return true;
}
//invite to install
Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(
Uri.parse("market://details?id=" + intent.getPackage()));
if (marketIntent.resolveActivity(packageManager) != null) {
getApplicationContext().startActivity(marketIntent);
return true;
}
} catch (URISyntaxException e) {
//not an intent uri
}
}
return true;
}
});
wv.getSettings().setJavaScriptEnabled(true);
// wv.getSettings().setLoadWithOverviewMode(true);
wv.loadUrl("http://www.saborasonoyta.com");
}
protected void showAppExitDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("POR FAVOR, CONFIRME");
builder.setMessage("desea salir de la aplicaciĆ³n?");
builder.setCancelable(true);
builder.setPositiveButton("Si", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
// Do something when user want to exit the app
// Let allow the system to handle the event, such as exit the app
MainActivity.super.onBackPressed();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
// Do something when want to stay in the app
Toast.makeText(getApplicationContext(),"Gracias",Toast.LENGTH_LONG).show();
}
});
// Create the alert dialog using alert dialog builder
AlertDialog dialog = builder.create();
// Finally, display the dialog when user press back button
dialog.show();
}
#Override
public void onBackPressed(){
if(wv.canGoBack()){
// If web view have back history, then go to the web view back history
wv.goBack();
}else {
// Ask the user to exit the app or stay in here
showAppExitDialog();
}
}
}
try to add this.
Apps can constrain Intents constructed with Intent.parseUri to only be sent as Implicit Intents to components with BROWSABLE Intent Filters using the following code:
// convert Intent scheme URL to Intent object
Intent intent = Intent.parseUri(url);
// forbid launching activities without BROWSABLE category
intent.addCategory("android.intent.category.BROWSABLE");
// forbid explicit call
intent.setComponent(null);
// forbid Intent with selector Intent
intent.setSelector(null);
// start the activity by the Intent
view.getContext().startActivity(intent, -1);

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)
{
}

Android activity open facebook

I am using the following code to open facebook page of the application. The code works fine but the facebook page opens blank until i swipe it down to refresh then it shows the content
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("ccccccccccccc");
String facebookUrl = "https://facebook.com/appsaraai";
try {
int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850)
{
Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
else
{
// open the Facebook app using the old method (fb://profile/id or fb://page/id)
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/395215577269747")));
}
} catch (PackageManager.NameNotFoundException e) {
// Facebook is not installed. Open the browser
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}
}
});
any idea!
Remember have a similar issue.
Try the mobile url :
instead of
String facebookUrl = "https://facebook.com/appsaraai";
use
String facebookUrl = "https://m.facebook.com/appsaraai";

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

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) {
}
}

Categories

Resources