3 回答
![?](http://img1.sycdn.imooc.com/545863e80001889e02200220-100-100.jpg)
TA贡献1874条经验 获得超12个赞
我不确定您的自定义GUI是否将始终位于默认GUI的顶部,因为系统广播接收器和您的接收器都试图将其GUI显示在屏幕顶部。我们不确定哪个首先被调用,但是要使您的GUI出现在屏幕顶部的一项棘手的工作是在电话响起1-2秒后,使用您的活动处理程序来调用您的活动。
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);
希望对您有帮助。
![?](http://img1.sycdn.imooc.com/5333a0350001692e02200220-100-100.jpg)
TA贡献2012条经验 获得超12个赞
我刚刚在Android 4.2(Jelly Bean)模拟器上进行了测试,它可以像truecaller一样阻塞整个来电屏幕,从而完美地发挥了作用:
public void onReceive(Context context, Intent intent) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = 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);
params.height = LayoutParams.MATCH_PARENT;
params.width = LayoutParams.MATCH_PARENT;
params.format = PixelFormat.TRANSLUCENT;
params.gravity = Gravity.TOP;
LinearLayout ly = new LinearLayout(context);
ly.setBackgroundColor(Color.RED);
ly.setOrientation(LinearLayout.VERTICAL);
wm.addView(ly, params);
}
在清单中:
<receiver android:name="" android:enabled="true" >
<intent-filter android:priority="-1">
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
- 3 回答
- 0 关注
- 1459 浏览
添加回答
举报