Android Intent.ACTION_CALL, Uri

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I am trying to use the Intent.Action class. I know how to use the ACTION_VIEW to display a URL but I wanted to use the Intent.ACTION_DIAL to call number when the application is launched. The documentation says you need to parse a URI into a string and then add it to the Intent I tried this:

Uri call = Uri.parse("7777777777");              Intent surf = new Intent(Intent.ACTION_DIAL, call);  startActivity(surf); 

This doesn't work I get an error message saying:

Unfortunately, Project has stopped. I tried to debug the code and it seems to point me to the intent line not sure what I doing wrong if I just do this it works and brings up the dialer.

//Uri call = Uri.parse("7777777777");                Intent surf = new Intent(Intent.ACTION_DIAL);    startActivity(surf); 

回答1:

tel

String number = "23454568678";     Intent intent = new Intent(Intent.ACTION_CALL);     intent.setData(Uri.parse("tel:" +number));     startActivity(intent); 

Use Permission



回答2:

To just open the dialer app (the user has to press the call button inside the dialer app; no additional permissions needed) use:

String number = "7777777777"; Uri call = Uri.parse("tel:" + number);              Intent surf = new Intent(Intent.ACTION_DIAL, call);  startActivity(surf); 

To open the dialer app and do the call automatically (needs android.permission.CALL_PHONE) use:

String number = "7777777777"; Uri call = Uri.parse("tel:" + number);              Intent surf = new Intent(Intent.ACTION_CALL, call);  startActivity(surf); 


回答3:

try this

String url="tel:777777777" if (url.startsWith("tel:"))  {  Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));  startActivity(intent); } 

add this to your AndroidManifest.xml file



回答4:

Try this also

Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phno); startActivity(intent); 

Android Manifest



回答5:

try this

String no = "536171839"; Intent callintent = new Intent(android.intent.action.CALL); callintent.setData(Uri.parse("tel:" +no)); startActivity(callintent); 

add this to your AndroidManifest.xml file

 


回答6:

Try this :

 String toCall = "tel:" + number.getText().toString();              startActivity(new Intent(Intent.ACTION_DIAL,                      Uri.parse(toCall))); 


回答7:

Another approach is to make an PendingIntent to be called later. This is specially util when you want to redirect the user directly to phone call from a notification Action.

String number = "551191111113"; Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" +number)); PendingIntent pendingIntentForCall = PendingIntent.getActivity(mContext, 0 /* Request code */, intent,PendingIntent.FLAG_ONE_SHOT); 

You can use it in notification as follow:

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);         NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext)                 .setContentTitle(title)                 .setContentText(message)                 .setStyle(new NotificationCompat.BigTextStyle().bigText(message))                 .setTicker(tickerText)                 .setColor(Color.BLACK)                 .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_directions_bus_white_48dp))                 .setSmallIcon(R.mipmap.ic_directions_bus_white_24dp)                 .setAutoCancel(true)                 .setSound(defaultSoundUri)                 .addAction(new NotificationCompat.Action(R.mipmap.ic_directions_bus_white_24dp,"Call to " + number,pendingIntentForCall)); 


回答8:

If u have added

 

Check the permission of call on the phone for your application.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!