簡體   English   中英

如何將浮動氣泡作為后台服務運行,將所有氣泡代碼放入OnStart方法中

[英]How to run a floating bubble as a background service , put all the bubble code inside OnStart method

這是Background Service.java代碼,其中包含onStart()方法-

@Override
public void onStart(Intent intent, int startid) {
    //Toast.makeText(this, "Service started by user.", Toast.LENGTH_LONG).show();

    private void addNewBubble () // Error here , says missing token ';' and Expression Expected

    {
        windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        //here is all the science of params
        final WindowManager.LayoutParams myParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                PixelFormat.TRANSLUCENT
        );
        BubbleLayout bubbleView = (BubbleLayout) LayoutInflater.from(BackgroundService.this).inflate(R.layout.bubble_layout, null);
        bubbleView.setLayoutParams(myParams);

        bubbleView.setOnBubbleRemoveListener(new BubbleLayout.OnBubbleRemoveListener() {
            @Override
            public void onBubbleRemoved(BubbleLayout bubble) {
            }
        });
        bubbleView.setOnBubbleClickListener(new BubbleLayout.OnBubbleClickListener() {

            @Override
            public void onBubbleClick(BubbleLayout bubble) {


                Bitmap b = Screenshot.takescreenshotOfRootView(imageView);
                imageView.setImageBitmap(b);
                main.setBackgroundColor(Color.parseColor("#999999"));

                //Toast.makeText(getApplicationContext(), "Clicked !",
                //   Toast.LENGTH_SHORT).show();
            }
        });
        bubbleView.setShouldStickToWall(true);
        bubblesManager.addBubble(bubbleView, 60, 20);
    }
}

private void initializeBubblesManager() {
    bubblesManager = new BubblesManager.Builder(this)
            .setTrashLayout(R.layout.bubble_trash_layout)
            .setInitializationCallback(new OnInitializedCallback() {
                @Override
                public void onInitialized() {
                    addNewBubble(); // Cannot resolve this method
                }
            })
            .build();
    bubblesManager.initialize();
}

MainActivity僅包含使用checkDrawOverlay()方法和startService(new Intent(this,BackgroundService.class))運行浮動氣泡的權限代碼。 在其他部分...

您的代碼格式無效,這就是IDE抱怨缺少分號( ; )的原因。 與句子

“仔細查看方法的開始和結束位置”

我的意思是您需要注意聲明方法的位置,因為它們只能在Class聲明的范圍內聲明。 當前,您正在另一方法范圍內聲明一個方法(無效)。 例如

public void methodOne()
{
    // this nested method declaration is considerd invalid
    private void methodTwo()
    {
        // method content
    }
}

修復它只是做

public void methodOne()
{
    // call other method if you need it to be executed here
    methodTwo();
}

private void methodTwo()
{
    // method content
}

這將同時解決missing semicolon errorcannot resolve method error

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM