弹出窗口对像真正的来电Android应用程序的Andr​​oid原生来电屏幕

问题描述:

更新 - 2013年5月9日 *我试图在广播接收器的onReceive方法来实现吐司,因为敬酒的是Android的原生成分,但它也没有得到显示的Andr​​oid 4.1(果冻豆)。

Update -- 09 May 2013 *I tried to implement Toast in the broadcast receiver's onReceive method because toast is a native component of Android, but it is also not getting displayed in Android 4.1 (Jelly Bean).

我的想法是在广播接收器的onReceive方法来实现吐司事后改变其根据我们的需要,调整显示其持续时间设计。但一个问题是, findViewById 在广播接收器不工作,所以我认为,我们必须作出的LinearLayout编程定制敬酒。*

My idea was to implement Toast in the broadcast receiver's onReceive method and afterwards changing its design according to our needs and tuning its duration of display. But one more problem is that findViewById doesn't work in the broadcast receiver, so I think we have to make a LinearLayout programmatically for customizing the toast.*

更新 - 赏金也我没有得到我在寻找的东西,但我会尽快给所有之后;我的工作上面。无论如何,这code适用于大多数的Andr​​oid手机。如果有人打算使用,赶上解决方案的话,请写在这里,让大家都能得到好处。 感谢所有的答案。

Update -- After bounty also I am not getting the exact thing I am looking for, but I will get back to all; I am working upon it. Anyway, this code works for most Android phones. If anybody is going to use and catch the solution for it, please write here so that everybody can get the benefit. Thanks for all your answers.

我在未来的Andr​​oid的电话和收到来电开发的广播接收器,因为我想一个充气弹出在本地来电屏幕。

I am developing a broadcast receiver for in coming calls in Android and on getting incoming calls I want to inflate an pop up over the native incoming call screen.

我完成了code。但是现在的问题是,在Android 4.1(果冻豆)API级别17 当电话铃声响起时, PHONE_STATE 即将为摘机 ,如果我调用一个活动,它被调用,但在它的code没有得到执行。我列出了code:

I completed that code. But now the problem is that in the Android 4.1 (Jelly Bean) API level 17 when a phone rings, the PHONE_STATE is coming as OFF HOOK, and if I am calling an activity, it gets called, but the code under it doesn't get executed. I am listing the code:

package com.example.popwindowonincomingcallscreen;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

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

public class IncomingBroadcastReceiver extends BroadcastReceiver {

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

        Log.d("IncomingBroadcastReceiver: onReceive: ", "flag1");

        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        Log.d("IncomingBroadcastReceiver: onReceive: ", state);
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)
                || state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {

            Log.d("Ringing", "Phone is ringing");

            Intent i = new Intent(context, IncomingCallActivity.class);
            i.putExtras(intent);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            Wait.oneSec();
            context.startActivity(i);
        }
    }
}

这是我正在呼叫的活动:

An the activity which I am calling:

import android.app.Activity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View.MeasureSpec;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class IncomingCallActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        try {
            Log.d("IncomingCallActivity: onCreate: ", "flag2");

            */ After this line, the code is not executed in Android 4.1 (Jelly Bean) only/*

            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);

            getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

            Log.d("IncomingCallActivity: onCreate: ", "flagy");

            setContentView(R.layout.main);

            Log.d("IncomingCallActivity: onCreate: ", "flagz");

            String number = getIntent().getStringExtra(
                    TelephonyManager.EXTRA_INCOMING_NUMBER);
            TextView text = (TextView) findViewById(R.id.text);
            text.setText("Incoming call from " + number);
        } 
        catch (Exception e) {
            Log.d("Exception", e.toString());
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

try {
    Log.d("IncomingCallActivity: onCreate: ", "flag2");
}

在code不是执行在安卓4.1(果冻豆),但在其他版本中,它是工作。

The code is not executing in Android 4.1 (Jelly Bean), but in other versions it is working.

我已经尝试了几乎所有的方法我能做到。这code被显示在本地呼叫屏幕的透光性的活动,它不会阻止后台控件,比如拿起电话。但我想它像真正的来电。我重视的是如何真正呼叫者来电屏幕上显示一个窗口中的快照。

I have tried almost all ways I can do. This code is displaying an translucent activity over the native call screen, and it doesn't block background controls, like picking up the phone. But I want it like true caller. I have attached an snapshot on how the true caller is displaying a window on the incoming call screen.

我怎样才能实现这一功能的Andr​​oid应用程序?

How can I achieve this functionality for an Android app?

这是怎样一个真正的来电作品:

This is how a true caller works:

我的present输出:

My present output:

我不知道您的自定义GUI将永远是默认的顶部,因为系统广播接收器和接收器都试图显示其GUI在屏幕的顶部。我们不知道哪一个是所谓的第一,而是一个棘手的工作,让你的GUI在屏幕的顶部是当手机铃声响起后使用处理程序,即1-2秒调用你的活动。

I am not sure that your custom GUI will always be on top of the default one, because the system broadcast receiver and your receiver are both trying to display its GUI on top of the screen. We are not sure which one is called first, but one tricky work to make your GUI on top of the screen is when the phone is ringing call your activity after 1-2 second(s) used handler for that.

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

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

我希望这可以帮助你。

I hope it may help you.