Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.content.Intent;

import android.net.Uri;
import android.support.annotation.NonNull;

public class Main {
    public static void callPhoneNumber(@NonNull Context context, @NonNull String resource) {
        //First of all, the number needs to be extracted from the resource
        String number = "";
        for (int i = 0; i < resource.length(); i++) {
            char digit = resource.charAt(i);
            if (digit >= '0' && digit <= '9') {
                number += digit;
            }
        }
        context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number)));
    }
}