Android在其它应用上弹窗,在Android本机来电屏幕上弹出窗口,例如真正的来电者Android应用...

d6fcfe491d941c224d49fb273179e080.png

慕莱坞森

我也在努力(在这里理解你可能是错误的)。您想要实现的是在Android 4.2(Jelly Bean)中显示该活动。我只是延迟显示活动。我在其他类中使用过PhoneStateListener。我可以在呼叫者屏幕上显示新活动。这是我的完整代码:文件MyBroadcastReceiver.javapublic class MyBroadcastReceiver extends BroadcastReceiver {    static CustomPhoneStateListener phoneStateListener;    Context context;    Intent intent;    @Override    public void onReceive(Context context, Intent intent) {        this.context = context;        this.intent = intent;        // TODO Auto-generated method stub            TelephonyManager telephonyManager = (TelephonyManager) context                    .getSystemService(Context.TELEPHONY_SERVICE);                       phoneStateListener = new CustomPhoneStateListener(context);            telephonyManager.listen(phoneStateListener,                    PhoneStateListener.LISTEN_CALL_STATE);    }}文件CustomPhoneStateListener.javapublic class CustomPhoneStateListener extends PhoneStateListener {    // private static final String TAG = "PhoneStateChanged";    Context context; // Context to make Toast if required    private AudioManager amanager;    Intent i1;    public CustomPhoneStateListener(Context context) {        super();        this.context = context;        i1 = new Intent(context, YourActivity.class);               i1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        i1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);    }    @Override    public void onCallStateChanged(int state, String incomingNumber) {        super.onCallStateChanged(state, incomingNumber);        switch (state) {        case TelephonyManager.CALL_STATE_IDLE:            Toast.makeText(context, "Phone state Idle", Toast.LENGTH_LONG)                    .show();            break;        case TelephonyManager.CALL_STATE_OFFHOOK:            Toast.makeText(context, "Phone state Off hook", Toast.LENGTH_LONG)                    .show();            break;        case TelephonyManager.CALL_STATE_RINGING:                       try {                Thread.sleep(3000);                context.startActivity(i1);                          } catch (Exception e) {                e.getLocalizedMessage();            }        default:            break;        }    }和YourActivity将保留为您创建的样子。注意:在此代码中,我也遇到了一些问题,它们位于此处。当关闭的呼叫关闭(未接呼叫或拒绝)时,活动未关闭。我无法点击“活动”(我想为我的应用添加一个按钮)它只能在第一次使用。当我第二次打电话时,我的应用程序停止了(我认为这是因为通话被拒时,Activity没有关闭)(接受了这些问题的帮助。谢谢。可能会帮助一些人)更新这是小演示如何实现此目标的链接。当关闭的呼叫关闭(未接呼叫或拒绝)时,活动未关闭。- 解决了我无法点击“活动”(我想为我的应用添加一个按钮)-已解决它只能在第一次使用。当我第二次打电话时,我的应用程序停止了(我认为这是因为通话被拒时,Activity没有关闭)-已解决

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
功能 1. 查询来电号码并显示悬浮窗,显示位置和其他号码信息。 2. 主界面显示最近来电列表(不会导入已有的系统通讯录)。 3. 在主界面可以查询任意电话号码信息。 4. 自定义设置卡片及悬浮窗的颜色。 5. 自定义悬浮窗, 如文字大小、透明度、位置。可以自定义显示与隐藏,如忽略已存在的联系人、去电时显示、接听后隐藏。 6. 离线查询。优先从本地的离线归属地及历史记录中查询数据并显示,没有查询到标记数据且有网络(有 WIFI 或手机未掉网)时会联网查询。 隐藏功能 (点击七次版本后现) 1. 自定义数据源。可以自定义百度、聚合数据(360)的 API 密钥,可以自定义 API (用于适配客户信息系统)。可以设置忽略号码段来忽略查询,可以强制使用本地离线数据。 插件功能(安装插件后现) 1. 自动挂断。可以自动挂断匹配的标记关键字(诈骗、广告等)、归属地、起始号码(400*)。归属地可逆向匹配,如 "!西安 !咸阳" 将挂断所有除 "西安" "咸阳" 的来电。起始号码关键字添加完整号码并以空格分隔可以实现 "黑名单" 的功能。 2. 添加号码信息到系统通话记录。会添加诈骗、骚扰、广告、响一声、自动挂断等信息到系统通话记录。 说明 1. “来电信息” 的不断改进和完善离不开社区的反馈,非常感谢所有在 Play 市场、V站、酷市场留言及发送邮件反馈的朋友。 2. 应用开源免费无广告,请放心使用。APK 文件通过 Travis CI 自动生成并上传,用户可在每个 GitHub 版本发行 中找到编译日志来校验文件 sha1 及 md5。 3. 请避免限制主应用及插件请求的权限。如来电时不显示悬浮窗,请先检查权限设置、权限管理类型应用的设置。如果安装了插件,请确保插件和主应用没有进入管理类软件的黑名单或优化项目。 4. 如果对此开源应用有任何不满、问题或建议,请在 GitHub 提交问题单或发送问题到作者邮件。非常欢迎大家反馈,来和作者一起完善这个应用。 5. 如果您觉得这个应用做的不错,欢迎在 GitHub star、在 Play 市场 及 酷市场 五星好评,欢迎您将此应用通过推特、微博、朋友圈等社交网络推广给更多的人。
您可以使用Android系统提供的弹窗口或者Dialog来实现推送通知中显示活动/弹窗口。 在您的应用程序中,您可以使用NotificationCompat.Builder来创建通知,并使用setFullScreenIntent方法将Intent设置为显示全屏通知。这将在用户单击通知时显示全屏通知。示例代码如下: ``` // Create an Intent for the activity you want to display Intent intent = new Intent(this, YourActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Build the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My notification") .setContentText("Hello World!") .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(pendingIntent) .setAutoCancel(true) .setFullScreenIntent(pendingIntent, true); // Show the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notificationId, builder.build()); ``` 您也可以使用Dialog来实现弹窗效果。在您的应用程序中,您可以使用AlertDialog.Builder来创建对话框,并使用setView方法将您的布局设置为对话框的视图。示例代码如下: ``` // Create a builder for the dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); // Set the title and message for the dialog builder.setTitle("My Dialog"); builder.setMessage("Hello World!"); // Inflate your custom layout into the dialog's view LayoutInflater inflater = getLayoutInflater(); View dialogView = inflater.inflate(R.layout.my_dialog_layout, null); builder.setView(dialogView); // Add buttons to the dialog builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do something when the user clicks OK } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do something when the user clicks Cancel } }); // Show the dialog AlertDialog dialog = builder.create(); dialog.show(); ``` 希望这可以帮到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值