2013-04-05 29 views
7

私はIntent.Actionクラスを使用しようとしています。 ACTION_VIEWを使用してURLを表示する方法はわかっていますが、アプリケーション起動時にIntent.ACTION_DIALを使用して番号を呼び出したかったのです。Android Intent.ACTION_CALL、Uri

残念ながら、プロジェクトがあります。

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

これは私が言って、エラーメッセージが表示されます動作しません:ドキュメントでは、文字列にURIを解析して、私はこれを試してみましたテントに追加する必要があると述べています停止。私はコードをデバッグしようとしたが、それは私がちょうどこれを行う場合、何が間違っているのかわからないインテントラインに私を指し示すようだ、それは動作し、ダイヤラを持ち出す。

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

可能複製(http://stackoverflow.com/questions/10510395/call-intent-in- [Androidのインテントを呼び出します]アンドロイド) – amadib

答えて

22

tel

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

使用許可

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 
1

この

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

があなたのAndroidManifest.xmlファイル

にこれを追加してみてください
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 
13

ダイヤラーアプリを開くだけです(ダイヤラーアプリ内の通話ボタンを押す必要があります。必要に応じて追加の権限)は使用しない:

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

ダイヤラアプリを開くと、自動的に通話を行うには(android.permission.CALL_PHONEを必要とします)を使用します。

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

この

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

を試してみてくださいこれをAndroidManifest.xmlファイルに追加します

<uses-permission android:name="android.permission.CALL_PHONE" /> 
3

このお試しください

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

Androidのマニフェスト

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 
2

これを試してみてください:uは

<uses-permission android:name="android.permission.CALL_PHONE" /> 

を追加した場合は、電話での通話の許可を確認してください

String toCall = "tel:" + number.getText().toString(); 

      startActivity(new Intent(Intent.ACTION_DIAL, 

        Uri.parse(toCall))); 
0

をヨーヨーウルアプリケーション。

+1

これはコメントです – ketan

1

もう1つの方法は、PendingIntentを後で呼び出すことです。 これは、通知アクションからユーザを直接電話コールにリダイレクトする場合に特に便利です。

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); 

あなたは次のように通知して、それを使用することができますの

 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)); 
関連する問題