使Android的通话 [英] Make a call in android

查看:267
本文介绍了使Android的通话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使在android系统调用,不使用意图

I want to know how to make a call in android, without using Intents.

我知道它可以使用意图做,但我通过 developer.android.com 搜查,没有什么关于这个话题。

I know it can be done using intents, but I searched through developer.android.com and there is nothing about this topic.

让我们说,我想要写为Android一个新的拨号器。我怎么可以这样做呢?

Let's say that I want to write a new dialer for android. How may I do this?

在此先感谢

推荐答案

要拨打电话,

private void performDial(String numberString) {
if (!numberString.equals("")) {
   Uri number = Uri.parse("tel:" + numberString);
   Intent dial = new Intent(Intent.ACTION_CALL, number);
   startActivity(dial);
}

}

添加此权限为明显。

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

要显示一个定制的拨号画面,写出呼出的接收器

public class OutgoingCallReceiver extends BroadcastReceiver {
 @Override
public void onReceive(final Context context, final Intent intent) {
  //this will receive the outgoing call

}
 }

添加这些的体现

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

 <receiver android:name=.OutgoingCallReceiver" >
  <intent-filter>
  <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
 </intent-filter>

要显示在拨号器应用的顶视图时它启动,
 使用code广播接收机内部

 private WindowManager wm;
    private static LinearLayout ly1;
    private WindowManager.LayoutParams params1;

    // onReceive function of the Broadcast Receiver
    public void onReceive(Context arg0, Intent arg1) {
            String state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE);

            // Adds a view on top of the dialer app when it launches.
            if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                params1 = new WindowManager.LayoutParams(
                        LayoutParams.MATCH_PARENT,
                        LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
                        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                        PixelFormat.TRANSPARENT);

                params1.height = 75;
                params1.width = 512;
                params1.x = 265; 
                params1.y = 400;
                params1.format = PixelFormat.TRANSLUCENT;

                ly1 = new LinearLayout(context);
                ly1.setBackgroundColor(Color.BLACK);
                ly1.setOrientation(LinearLayout.VERTICAL);

                wm.addView(ly1, params1);
            }

            // To remove the view once the dialer app is closed.
            if(arg1.getAction().equals("android.intent.action.PHONE_STATE")){
                String state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE);
                if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
                    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                    if(ly1!=null)
                    {
                        wm.removeView(ly1);
                        ly1 = null;
                    }
                }
            }
        }

注意:
上述实施例产生具有黑色背景的布局的视图,如上所示具有维度。
你有自由的这一观点中添加任何布局。
例如,包括布局视图中可以修改上面的code,包括以下code。

Note: The above example generated a view having a layout with black background,having dimension as shown above. You have the liberty to add any layout within this view. For example, to include a layout within the view you can modify the above code to include the following code.

 ly1 = new LinearLayout(getApplicationContext());
    ly1.setOrientation(LinearLayout.HORIZONTAL);


    View hiddenInfo = getLayoutInflater().inflate(R.layout.layout1, ly1, false);
    ly1.addView(hiddenInfo);

    wm.addView(ly1, params1);

在你的清单,你需要包括以下权限。

 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<action android:name="android.intent.action.PHONE_STATE" /

注意:您也可以拨打从广播接收器的活动而不是膨胀的窗口使用以下code表示。目的。

Note: You can also call an activity from the BroadcastReceiver instead of inflating a window. Use the following code for that purpose.

    new Handler().postDelayed(new Runnable() {

     @Override
     public void run() {
         // TODO Auto-generated method stub
         Intent intent = new Intent(context, CustomDialerActivity.class);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
     }
 }, 2000);

我不知道您的自定义GUI将永远是默认的顶部,因为系统广播接收器和接收器都试图在屏幕上方显示其GUI。我们不知道哪一个先叫,而是一个棘手的工作,使屏幕顶部的GUI是当电话响起来电后1-2秒。我使用的处理程序为

这篇关于使Android的通话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆