开发者

Android app with Google Maps Navigation and a text overlay

I have searched this issue for hours... Is it possible to launch googl开发者_高级运维e maps navigation within my app and display a textview with some information on it? I have to create an app which passes the destination address to Maps Navigation and while Navigation is working show a textview with the cars model name on the bottom of the app. Is this doable?


Is it possible to launch google maps navigation within my app and display a textview with some information on it?

You cannot embed other applications in yours, and you cannot add your own widgets to some other application's UI.


Try this.

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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜