首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓TelephonyManager和PhoneStateListener

安卓TelephonyManager和PhoneStateListener
EN

Stack Overflow用户
提问于 2012-05-19 17:08:45
回答 1查看 4.4K关注 0票数 0

我想在顶部弹出一个新视图,当收到呼叫并且处于振铃状态时,我无法执行此操作。我正在发布我的代码,但也考虑在评论中的代码。

代码语言:javascript
复制
package com.android.CallIntent;

import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

public class Listener extends PhoneStateListener {
    Context Context;
    public Listener(Context context)
    {
        this.Context = context;
    }

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        // TODO Auto-generated method stub
        super.onCallStateChanged(state, incomingNumber);

        switch(state)
        {
            case TelephonyManager.CALL_STATE_OFFHOOK:

                break;
            case TelephonyManager.CALL_STATE_RINGING:

                Log.d("message","Ringing");
                Intent intent = new Intent(Context, CallOptions.class);
                // I want to start my new Activity From here please Help me.

                //I am unable to access StartActivity
                break;

        }
    }

}

// My BroadcastReceiver class is here
public class Receiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        Listener phoneStateListener= new Listener();
        manager.listen(phoneStateListener, Listener.LISTEN_CALL_STATE);


    }

求求你们谁来帮帮我求求你们。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-07-05 18:47:05

看这里..。它一定能帮到你。

代码语言:javascript
复制
   case TelephonyManager.CALL_STATE_RINGING:
            Toast.makeText( context, "incoming call", Toast.LENGTH_LONG).show();
            IntentService = new Intent(context, PlayService.class).setAction("incoming_call");
            IntentService.putExtra("phone_number",intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER) );
            if (SmsReceiver.bool)
            context.startService(IntentService);
            break;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10663860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档