GVKun编程网logo

Android中的自定义传入/传出呼叫屏幕(android呼叫转移设置)

6

对于Android中的自定义传入/传出呼叫屏幕感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍android呼叫转移设置,并为您提供关于android–Airbnb探索屏幕等工具栏中的自定义视图

对于Android中的自定义传入/传出呼叫屏幕感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍android呼叫转移设置,并为您提供关于android – Airbnb探索屏幕等工具栏中的自定义视图、android – XML中的自定义按钮、android – 从侦听传出呼叫的广播接收器启动活动、android – 操作栏中的自定义视图的有用信息。

本文目录一览:

Android中的自定义传入/传出呼叫屏幕(android呼叫转移设置)

Android中的自定义传入/传出呼叫屏幕(android呼叫转移设置)

我正在尝试实现自定义传入/传出呼叫屏幕.以下是我的尝试.你提出了两个问题

>有时它会调用手机上的默认传入屏幕,或者有时会调用自定义屏幕.我会打电话总是打电话给定制的屏幕.
>我无法发出传出电话.自定义屏幕刚出现但没有拨打任何电话.

如何解决这个问题,我不确定这里有什么问题.如果有人能帮我解决这个问题会很棒.

这是我正在尝试的:

表现:

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >
    <activity
        android:name="com.honey.ringer.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.honey.ringer.AcceptCall"
        android:screenorientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.ANSWER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <receiver
        android:name="com.honey.ringer.PhoneListenerbroad">
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>
</application>

broadCastReciever:这有传入和传出

public class PhoneListenerbroad extends broadcastReceiver
{

Context c;
private String outgoing;

@Override
public void onReceive(Context context, Intent intent) 
{
    c = context;

    if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) 
    {
        outgoing = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 
        int state = 2;
        Intent intentPhoneCall = new Intent(c, AcceptCall.class);
        intentPhoneCall.putExtra("incomingnumber", outgoing);
        intentPhoneCall.putExtra("state", state);
        intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        c.startActivity(intentPhoneCall);
    }

    try
    {
        TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        MyPhonestateListener PhoneListener = new MyPhonestateListener();
        tmgr.listen(PhoneListener, PhonestateListener.LISTEN_CALL_STATE);
    }
    catch (Exception e) 
    {
        Log.e("Phone Receive Error", " " + e);
    }

}

private class MyPhonestateListener extends PhonestateListener
{
    public void onCallStateChanged(final int state, final String incomingNumber) 
    {
        Handler callActionHandler = new Handler();
        Runnable runRingingActivity = new Runnable() 
        {
            @Override
            public void run() 
            {
                if (state == 1)
                {
                    Intent intentPhoneCall = new Intent(c, AcceptCall.class);
                    intentPhoneCall.putExtra("incomingnumber", incomingNumber);
                    intentPhoneCall.putExtra("state", state);
                    intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    c.startActivity(intentPhoneCall);
                }
            }
        };

        if (state == 1)
        {   
            callActionHandler.postDelayed(runRingingActivity, 100);
        }

        if (state == 0) 
        {
            callActionHandler.removeCallbacks(runRingingActivity);
        }
    }
}

}

AcceptCall.java(用于UI目的 – 传入和传出):

 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
 public class AcceptCall extends Activity implements OnClickListener 
 {
LinearLayout answerButton;
LinearLayout rejectButton;
LinearLayout timerLayout;

TextView contactName;
TextView contactNumber;
ImageView profile;

private String incomingnumber;
private int state;

String name = null;
String contactId = null;

InputStream photo_stream;

TextView callType;



@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.testactivity);

    answerButton = (LinearLayout) findViewById(R.id.callReceive);
    answerButton.setonClickListener(this);

    rejectButton = (LinearLayout) findViewById(R.id.callReject);
    rejectButton.setonClickListener(this);

    timerLayout = (LinearLayout) findViewById(R.id.timerLayout);

    contactName = (TextView) findViewById(R.id.contactName);
    contactNumber = (TextView) findViewById(R.id.contactNumber);

    callType = (TextView) findViewById(R.id.callType);

    timerValue = (TextView) findViewById(R.id.timerValue);

    profile  = (ImageView)findViewById(R.id.contactPhoto);     

    Bundle bundle =  getIntent().getExtras();
    if(bundle != null)
    {
        incomingnumber = bundle.getString("incomingnumber");
        state = bundle.getInt("state");
    }

    contactslookup(incomingnumber);

    contactName.setText(name);
    contactNumber.setText(incomingnumber);


    if (state == 2)
    {
        /*String uri = "tel:" + incomingnumber.trim();
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse(uri));
        startActivity(intent);*/
    }

    PhonestateListener phonestateListener = new PhonestateListener() 
    {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) 
        {
            //wen ringing
            if (state == TelephonyManager.CALL_STATE_RINGING)
            {
                Log.e("CALL_STATE_RINGING","CALL_STATE_RINGING");
            } 

            //after call cut
            else if(state == TelephonyManager.CALL_STATE_IDLE)
            {
                RejectCall();
            } 

            //wen speaking / outgoing call
            else if(state == TelephonyManager.CALL_STATE_OFFHOOK)
            {
                Log.e("CALL_STATE_OFFHOOK","CALL_STATE_OFFHOOK");
            }
            super.onCallStateChanged(state, incomingNumber);
        }
    };
    TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if(mgr != null) 
    {
        mgr.listen(phonestateListener, PhonestateListener.LISTEN_CALL_STATE);
    }
}


private void contactslookup(String number) 
{

    Log.v("ffnet", "Started uploadcontactphoto...");

    //InputStream input = null;

    // define the columns I want the query to return
    String[] projection = new String[] {ContactsContract.PhoneLookup.disPLAY_NAME,ContactsContract.PhoneLookup._ID};

    // encode the phone number and build the filter URI
    Uri contactUri = Uri.withAppendedpath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

    // query time
    Cursor cursor = getContentResolver().query(contactUri, projection, null, null, null);

    if (cursor.movetoFirst()) 
    {
        // Get values from contacts database:
        contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID));
        name =      cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.disPLAY_NAME));
    } 

    else 
    {
        return; // contact not found
    }


    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= 14)
    {
        Uri my_contact_Uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(contactId));
        photo_stream = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), my_contact_Uri, true);
    }
    else
    {
        Uri my_contact_Uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(contactId));
        photo_stream = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), my_contact_Uri);
    }

    if(photo_stream != null) 
    {
        BufferedInputStream buf =new BufferedInputStream(photo_stream);
        Bitmap my_btmp = BitmapFactory.decodeStream(buf);
        profile.setimageBitmap(my_btmp);
    }
    else
    {
        profile.setimageResource(R.drawable.contactpic);
    }

    cursor.close();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onClick(View v) 
{
    // Todo Auto-generated method stub
    if(v.getId() == answerButton.getId())
    {
        timerLayout.setVisibility(0);

        startTime = SystemClock.uptimeMillis();
        customHandler.postDelayed(updateTimerThread, 0);

        callType.clearanimation();

        // Simulate a press of the headset button to pick up the call
        Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);     
        buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
        this.sendOrderedbroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

        // froyo and beyond trigger on buttonUp instead of buttonDown
        Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);       
        buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
        this.sendOrderedbroadcast(buttonUp, "android.permission.CALL_PRIVILEGED"); 
    }

    if(v.getId() == rejectButton.getId())
    {
        RejectCall();
    }

}

private void RejectCall() 
{
    TelephonyManager telephony = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

    try {
        // Java reflection to gain access to TelephonyManager's
        // ITelephony getter
        Class c = Class.forName(telephony.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(telephony);
        telephonyService.endCall();
        finish();

        timeSwapBuff += timeInMilliseconds;
        customHandler.removeCallbacks(updateTimerThread);
    }
    catch (Exception e) 
    {
        e.printstacktrace();
        Log.e("Error", "Fatal error: Could not connect to telephony subsystem");
        Log.e("Error", "Exception object: " + e);
    }
}

private Runnable updateTimerThread = new Runnable() 
{

    public void run() 
    {
        timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
        updatedTime = timeSwapBuff + timeInMilliseconds;
        int secs = (int) (updatedTime / 1000);
        int mins = secs / 60;
        int hours = mins / 60;
        secs = secs % 60;
        int milliseconds = (int) (updatedTime % 1000);
        timerValue.setText(""+ hours + ":" + String.format("%02d", mins) + ":"
                + String.format("%02d", secs));
        customHandler.postDelayed(this, 0);
    }

};

  }

解决方法:

对于拨打电话:我做了以下工作,它工作正常.我创建了一个具有清单所需权限的传出接收器.

通过使用处理程序在延迟后调用Activity.

像这样:

@Override
public void onReceive(Context context, Intent intent) 
{
    c = context;
    setResultData(null);
    phonenumber = getResultData();
    if (phonenumber == null)
    {
        phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    }
    setResultData(phonenumber);
    callActionHandler.postDelayed(runRingingActivity, 1000);
}


Handler callActionHandler = new Handler();
Runnable runRingingActivity = new Runnable() 
{
    @Override
    public void run() 
    {

        Intent intentPhoneCall = new Intent(c, OutgoingCallActivity.class);
        intentPhoneCall.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        c.startActivity(intentPhoneCall);
    }
};

您可以使用电话号码将其发送到新活动.

如果您有任何疑问,请告诉我!

android – Airbnb探索屏幕等工具栏中的自定义视图

android – Airbnb探索屏幕等工具栏中的自定义视图

我想在应用程序(工具栏)的顶部栏区域添加多个输入字段,以便我的应用程序进行搜索.我看到Airbnb做到了最好!我在CoordinatorLayout中尝试了使用AppBarLayout的各种场景,但都失败了.是否有可能获得相同或类似的效果?如果是的话,我们该怎么做?

这是我向上滑动顶部栏时的屏幕截图:



解决方法

Yes it is possible to create using appbar layout,I have tried same task,Finally i have figured-out in this way,I guess below code is helpful for you

<?xml version="1.0" encoding="utf-8"?>
   <layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!--your toolbar-->
        <include
            android:id="@+id/toolbar_wrapper"
            layout="@layout/common_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/color_fafafa"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/color_ffffff"
                    android:orientation="vertical"
                    app:layout_scrollFlags="scroll">

                    <!--your scrolling layout,in your case it will be edit texts and search fields-->
                </LinearLayout>
            </android.support.design.widget.AppBarLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <android.support.design.widget.TabLayout
                    android:id="@+id/tab_layout"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dp_49"
                    android:background="@color/color_ffffff"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:tabIndicatorColor="@color/colorAccent"
                    app:tabSelectedTextColor="@color/color_727272"
                    app:tabTextColor="@color/color_b6b6b6" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dp_1"
                    android:background="@color/color_d9d9d9" />
                <!--your main layout-->
                <android.support.v4.view.ViewPager
                    android:id="@+id/detail_pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:nestedScrollingEnabled="true" />
            </LinearLayout>

        </android.support.design.widget.CoordinatorLayout>
    </LinearLayout>
</layout>

android – XML中的自定义按钮

android – XML中的自定义按钮

我制作了这个XML文件来自定义一个按钮

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<corners android:radius="10dip" />

<gradient
    android:angle="90"
    android:centerColor="#0043E1"
    android:centerY="0.4"
    android:endColor="#6495ED"
    android:startColor="#6495ED"
    android:type="linear" />

</shape>

我应该添加什么来使状态集中并按下?按下状态的渐变颜色,以及聚焦状态的另一种颜色?

解决方法:

请参阅本教程,了解如何创建适当的drawable-xml文件以允许按钮的不同状态:

http://undertowsam.wordpress.com/2012/04/23/design-custom-background-and-button-for-android-using-xml/

android – 从侦听传出呼叫的广播接收器启动活动

android – 从侦听传出呼叫的广播接收器启动活动

我试图从收听5556的传出呼叫的广播接收器发起一个活动.问题是,活动没有启动但是正在调用拨号内置活动,我已将意图的优先级更改为100但是无济于事.如何让活动在拨号时启动而不是内置的呼叫活动?
这是代码:
package com.messageHider;

import android.content.broadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class launchReceiver extends broadcastReceiver {
    @Override
    public void onReceive(Context context,Intent intent) {
        String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        String compare_num="5556";
        if(number.equals(compare_num))
        {
            Intent myintent=new Intent(context,messageHider.class);
            myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(myintent);
            abortbroadcast();
        }
    }

}

清单文件:

<receiver android:name=".launchReceiver">
    <intent-filter android:priority="0">
        <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
    </intent-filter>
</receiver>

解决方法

在您的清单中,您需要一个权限(根据文档):

You must hold the PROCESS_OUTGOING_CALLS permission to receive this
Intent.

那就是

"android.permission.PROCESS_OUTGOING_CALLS"

也直接来自文档:

Any broadcastReceiver receiving this Intent must not abort the broadcast.

以下是我获取信息页面的链接:

http://developer.android.com/reference/android/content/Intent.html

android – 操作栏中的自定义视图

android – 操作栏中的自定义视图

我有一个动作栏.操作栏中的一个项目用于通知.我想在操作栏项的右上角添加一个小图标,表示用户当前有多少通知.

我继续为动作栏项目制作了自定义布局.去添加它,令我惊讶的是,我无法在操作栏上添加自定义视图作为按钮.

我使用Actionbar-Sherlock来兼容旧设备.

这就是我想要的:

解决方法

您正在寻找 ActionProvider.在这里您可以提供自己的观点和听众.

查看ABS演示,https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock-samples/demos/src/com/actionbarsherlock/sample/demos/ActionProviders.java

今天关于Android中的自定义传入/传出呼叫屏幕android呼叫转移设置的分享就到这里,希望大家有所收获,若想了解更多关于android – Airbnb探索屏幕等工具栏中的自定义视图、android – XML中的自定义按钮、android – 从侦听传出呼叫的广播接收器启动活动、android – 操作栏中的自定义视图等相关知识,可以在本站进行查询。

本文标签: