我正在我的 Android 应用程序中实现自定义的逐向导航。为实现这一点,我使用 Intent.ACTION_VIEW 作为 Action 并使用“google.navigation:q”作为 uri 字符串从我的 MainActivity 开始 Activity 。谷歌地图导航页面已成功加载到我的应用程序中。
但是,我不知道如何优雅地退出这个页面。如果我使用后退按钮按下,则需要点击 4 次后退按钮才能显示我的主 Activity 屏幕。是否有可能在此页面中放置“退出”按钮。
我已经尝试使用“onActivityForResult”和“onBackPressed”来破坏谷歌地图屏幕。这些都不起作用。请提供一些进一步的建议。
最佳答案
我知道我回答这个问题已经很晚了,但也许它可以帮助别人。
您无法通过单次返回从谷歌地图返回到您的 Activity/应用程序,为此您需要创建一个 float View /小部件,如 ola/uber,它将在正确实现后为您完成此操作。这是我的实现。
首先,用户将从 YourActivity 转到 map 应用。在此 Activity 中,我们将在单击某个 View 时请求 SYSTEM_ALERT_WINDOW 的权限(DRAW OVER,对于 SDK > MarshMallow)。然后我们将启动谷歌地图以及我们创建的服务来创建一个 float 图标。
class YourActivity extends AppCompatActivity{
private GetFloatingIconClick mGetServiceClick;
public static boolean isFloatingIconServiceAlive = false;
onCreate(){
mGetServiceClick = new GetFloatingIconClick();
somebtn.onclick(){
askDrawOverPermission();
}
}
private class GetFloatingIconClick extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent selfIntent = new Intent(YourActivity.this, YourActivity.class);
selfIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(selfIntent);
}
}
private void askDrawOverPermission() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
// if OS is pre-marshmallow then create the floating icon, no permission is needed
createFloatingBackButton();
} else {
if (!Settings.canDrawOverlays(this)) {
// asking for DRAW_OVER permission in settings
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getApplicationContext().getPackageName()));
startActivityForResult(intent, REQ_CODE_DRAW_OVER);
} else {
createFloatingBackButton();
}
}
}
// starting service for creating a floating icon over map
private void createFloatingBackButton() {
Intent iconServiceIntent = new Intent(YourActivity.this, FloatingOverMapIconService.class);
iconServiceIntent.putExtra("RIDE_ID", str_rideId);
Intent navigation = new Intent(Intent.ACTION_VIEW, Uri
.parse("google.navigation:q=" + lat_DEST + "," + lng_DEST + "&mode=d"));
navigation.setPackage("com.google.android.apps.maps");
startActivityForResult(navigation, 1234);
startService(iconServiceIntent);
}
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQ_CODE_DRAW_OVER) {
// as permissions from Settings don't provide any callbacks, hence checking again for the permission
// so that we can draw our floating without asking user to click on the previously clicked view
// again
if (Settings.canDrawOverlays(this)) {
createFloatingBackButton();
} else {
//permission is not provided by user, do your task
//GlobalVariables.alert(mContext, "This permission is necessary for this application's functioning");
}
} else if (requestCode == 1234) {
// no result is returned by google map, as google don't provide any apis or documentation
// for it.
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
服务等级:-
public class FloatingOverMapIconService 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();
createFloatingBackButton();
}
@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();
windowManager.removeView(frameLayout);
}
private void createFloatingBackButton() {
CurrentJobDetail.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);
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.custom_start_ride_back_button_over_map, frameLayout);
ImageView backOnMap = (ImageView) frameLayout.findViewById(R.id.custom_drawover_back_button);
backOnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(BROADCAST_ACTION);
intent.putExtra("RIDE_ID", str_ride_id);
sendBroadcast(intent);
//stopping the service
FloatingOverMapIconService.this.stopSelf();
CurrentJobDetail.isFloatingIconServiceAlive = false;
}
});
windowManager.addView(frameLayout, params);
}
}
float 图标 Xml:-
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/custom_drawover_back_button"
android:layout_width="70dp"
android:layout_height="100dp"
android:src="@drawable/common_full_open_on_phone"
android:scaleType="center"
android:background="@color/colorAccent"/>
</LinearLayout>
list 文件:-
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<activity
android:name=".Activities.YourActivity"
android:launchMode="singleTop" />
<service
android:name=".Utils.FloatingOverMapIconService"
android:exported="false" />
关于android - 退出谷歌地图 Intent 在android中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30838812/
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我想从rubyrake脚本运行一个可执行文件,比如foo.exe我希望将foo.exe的STDOUT和STDERR输出直接写入我正在运行rake任务的控制台.当进程完成时,我想将退出代码捕获到一个变量中。我如何实现这一目标?我一直在玩backticks、process.spawn、system但我无法获得我想要的所有行为,只有部分更新:我在Windows上,在标准命令提示符下,而不是cygwin 最佳答案 system获取您想要的STDOUT行为。它还返回true作为零退出代码,这可能很有用。$?填充了有关最后一次system调
如何只加载map边界内的标记gmaps4rails?当然,在平移和/或缩放后加载新的。与此直接相关的是,如何获取map的当前边界和缩放级别? 最佳答案 我是这样做的,我只在用户完成平移或缩放后替换标记,如果您需要不同的行为,请使用不同的事件监听器:在你看来(index.html.erb):{"zoom"=>15,"auto_adjust"=>false,"detect_location"=>true,"center_on_user"=>true}},false,true)%>在View的底部添加:functiongmaps4rail
技术选型1,前端小程序原生MINA框架cssJavaScriptWxml2,管理后台云开发Cms内容管理系统web网页3,数据后台小程序云开发云函数云开发数据库(基于MongoDB)云存储4,人脸识别算法基于百度智能云实现人脸识别一,用户端效果图预览老规矩我们先来看效果图,如果效果图符合你的需求,就继续往下看,如果不符合你的需求,可以跳过。1-1,登录注册页可以看到登录页有注册入口,注册页如下我们的注册,需要管理员审核,审核通过后才可以正常登录使用小程序1-2,个人中心页登录成功以后,我们会进入个人中心页我们在个人中心页可以注册人脸,因为我们做人脸识别签到,需要先注册人脸才可以进行人脸比对,进
这是一个长期存在的挫败感来源,但也许我遗漏了什么。如果我正在调试,并且我想退出调试器并返回到IRB或Rails控制台,“退出”将不起作用,因为它将退出IRB。“完成”似乎也与继续具有相同的效果。使用“删除”删除断点然后尝试“继续”或“完成”不起作用。有什么想法吗? 最佳答案 至少在byebug中,你可以这样做:evalreturn它具有计算当前函数的return语句的净效果。这有时会奏效,具体取决于调用堆栈的外观。现在虽然这不会删除当前断点....如果您只是想收回控制权,在大多数情况下这会做到这一点,具体取决于您的代码结构。在您的代
我试图制作一个可执行文件,它通过Thin作为守护进程启动Sinatra应用程序。我正在使用此代码通过Sinatra应用程序调用Thin:#!/usr/bin/envrubyrequire'thin'require'app.rb'server=::Thin::Server.new('127.0.0.1',9999,App)server.log_file='tmp/thin.log'server.pid_file='tmp/thin.pid'server.daemonize这是我执行脚本时得到的日志输出:>>WritingPIDtotmp/thin.pid>>Exiting!服务器正常启动
我正在尝试从googleAPI下载client_secret.json。我正在执行https://developers.google.com/gmail/api/quickstart/ruby中列出的步骤.使用此向导在GoogleDevelopersConsole中创建或选择项目并自动启用API。在左侧边栏中,选择同意屏幕。选择电子邮件地址并输入产品名称(如果尚未设置),然后单击“保存”按钮。在左侧边栏中,选择凭据并点击创建新客户端ID。选择应用程序类型已安装应用程序,已安装应用程序类型为其他,然后单击“创建客户端ID”按钮。点击新客户端ID下的下载JSON按钮。将此文件移动到您的工作
在Ruby脚本中,有variousways调用系统命令/命令行反引号:`commandarg1arg2`分隔形式,例如%x(commandarg1arg2)(可用其他分隔符)Kernel#system方法:system('commandarg1arg2')Kernel#exec方法:exec('commandarg1arg2')如果我希望Ruby脚本在调用的命令失败时失败(有异常)(具有非零退出代码),我可以检查特殊变量中的退出代码$?对于前两个变体:`commandarg1arg2`failunless$?==0或%x,commandarg1arg2,failunless$?==0如
我有这段代码:puts"Start"loopdoThread.startdoputs"Hellofromthread"exitendtext=getsputs"#{text}"endputs"Done"我希望看到“Start”后跟“Hellofromthread”,然后我可以输入会得到回显的输入。相反,我得到“Start”和“Hellofromthread”,然后程序退出。来自关于exit的文档:Terminatesthrandschedulesanotherthreadtoberun.Ifthisthreadisalreadymarkedtobekilled,exitreturnst
我有一个操作需要在我的Rails应用程序终止之前在我的Rails应用程序中执行。我可以在Rails中为此使用一个钩子(Hook)吗?我猜类似于at_exit的东西。 最佳答案 Ruby本身支持两个钩子(Hook),BEGIN和END,它们在脚本开始时运行,并在解释器停止运行时运行。有关详细信息,请参阅“WhatdoesRuby'sBEGINdo?”。BEGIN文档说:Designates,viacodeblock,codetobeexecutedunconditionallybeforesequentialexecutionofth