如何在后台弹出自定义布局/对话框片段或使用服务绘制其他应用程序?

时间:2018-11-12 07:31:23

标签: android android-layout android-intent android-service

enter image description here,我是该领域的新手。如果clipdata COME,我正在使用剪贴板事件列表器。然后,我想在任何应用程序上方显示对话框或自定义布局。 enter image description here我是如何实现的1https://i.stack.imgur.com/M9rUo.png我的服务代码

   public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("onsTart command", Thread.currentThread().getName());
    clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);


    clipboardManager.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
        @Override
        public void onPrimaryClipChanged() {
            final ClipData primaryClip = clipboardManager.getPrimaryClip();
            ClipData.Item item = primaryClip.getItemAt(0);
            final String text = item.getText().toString();
            Toast.makeText(getApplicationContext(), "heloaddb wifi" + text,Toast.LENGTH_LONG).show();dd();}});

public void dd() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Test dialog");
    builder.setIcon(R.drawable.ic_launcher_background);
    builder.setMessage("Content");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            //Do something
            dialog.dismiss();
        }
    });
    builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alert.show();
}

吐司工作正常,但是我无法在onstartcommand内创建对话框

0 个答案:

没有答案