为什么在WallpaperService中启动意图不起作用?

时间:2018-04-05 21:55:09

标签: android events android-intent ontouchevent wallpaper

我正在寻找动态壁纸的帮助。我想点击多边形时打开网址并打开计算器。 我在Manifest中有权限:android:permission =“android.permission.BIND_WALLPAPER” 和this.setTouchEventsEnabled(true);在onCreate。 为什么不起作用?

有我的代码:

 public void onTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_MOVE){
            mTouchX = event.getX();
            mTouchY = event.getY();
        }else {
            mTouchX=-1;
            mTouchY=-1;
        }

        com.snatik.polygon.Point point  = new com.snatik.polygon.Point(mTouchX,mTouchY);
        if(polygon1.contains(point)){
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.wp.pl"));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

        }

        if(polygon2.contains(point)){
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_APP_CALCULATOR);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        super.onTouchEvent(event);
    }

0 个答案:

没有答案