簡體   English   中英

帶有Google Maps Navigation和文本疊加層的Android應用

[英]Android app with Google Maps Navigation and a text overlay

我已經搜索了這個問題幾個小時...是否可以在我的應用程序中啟動Google Maps導航並顯示帶有某些信息的textview? 我必須創建一個將目標地址傳遞給Maps Navigation的應用,並且在Navigation工作時,在應用底部顯示一個文本視圖,並帶有汽車型號名稱。 這可行嗎?

是否可以在我的應用程序中啟動Google Maps導航並顯示帶有某些信息的textview?

您不能在自己的應用程序中嵌入其他應用程序,也不能將自己的窗口小部件添加到其他應用程序的UI中。

嘗試這個。

public class FloatingOverNewBooking extends Service {

    private WindowManager windowManager;
    private FrameLayout frameLayout;
    private String str_ride_id;
    public static final String BROADCAST_ACTION = "com.yourpackage.YourActivity";

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        timerLocation = new Timer();
        createFloatingBackButton();
    }

    Timer timerLocation;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // to receive any data from activity
        str_ride_id = intent.getStringExtra("RIDE_ID");
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (frameLayout != null) {
            //((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(frameLayout);

            windowManager.removeView(frameLayout);
            frameLayout = null;
        }

        timerLocation.cancel();
    }

    private void createFloatingBackButton() {
        ClientLocatedActivity.isFloatingIconServiceAlive = true;
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);
        WindowManager.LayoutParams windowManagerParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY ,
                WindowManager.LayoutParams. FLAG_DIM_BEHIND, PixelFormat.TRANSLUCENT);

        params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
        windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        frameLayout = new FrameLayout(this);

        LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        // Here is the place where you can inject whatever layout you want in the frame layout
        layoutInflater.inflate(R.layout.share_new_booking_alert, frameLayout);

        final TextView txtName = (TextView) frameLayout.findViewById(R.id.txtName);
        Button backOnMap = (Button) frameLayout.findViewById(R.id.dialog_button);

        if(!ObjectUtility.isNullOrEmpty(Config.Share.newPassenger)){
            txtName.setText(Config.Share.newPassenger.getUsername());
        }


        backOnMap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {

                    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
                    am.killBackgroundProcesses("com.google.android.apps.maps");
                    //MainActivity.getInstance().getShareRideDataById("go");
                    FloatingOverNewBooking.this.stopSelf();
                    ClientLocatedActivity.isFloatingIconServiceAlive = false;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        windowManager.addView(frameLayout, windowManagerParams);
    }
}

暫無
暫無

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

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