Dialing a phone call on click of textview in android

后端 未结 6 914
醉话见心
醉话见心 2020-12-03 01:05

I have a question that I want to dial a phone call when I click on a text view which also contain a phone number. But when I click on a Text view it returns an error as:

6条回答
  •  没有蜡笔的小新
    2020-12-03 01:43

     import android.app.Activity;
        import android.content.Intent;
        import android.net.Uri;
        import android.os.Bundle;
        import android.view.View;
        import android.widget.Button;
    
         public class CustomCellActivity extends Activity {
              
    
         /** Called when the activity is first created. */
                         
    
          @Override
              
    
         public void onCreate(Bundle savedInstanceState) {
                                
    
         super.onCreate(savedInstanceState);
            
    
         setContentView(R.layout.main);
    
    
               Button Phone = (Button) findViewById(R.id.button1);
               
    
         Phone.setOnClickListener(new View.OnClickListener() {
           @Override
          
    
         public void onClick(View v) {
       
    
         Intent sIntent = new Intent(Intent.ACTION_CALL, Uri
         
    
         .parse("tel:12345"));
       
    
         sIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       
        
    
         startActivity(sIntent);
      
    
        }
      
    
        });
    

    This code works for me. try it urself.

提交回复
热议问题