简体   繁体   English

我可以将参数从属性文件传递给 Android Apk 吗?

[英]Can I pass a parameter to an Android Apk from a properties file?

I need to pass a string to an Android apk externally.我需要从外部将字符串传递给 Android apk。 Currently my app is in development, so I haven't deployed it on Google Market.目前我的应用程序正在开发中,所以我还没有在谷歌市场上部署它。 Is there any way to pass a parameter to apk from an external file like properties file?有什么方法可以将参数从外部文件(如属性文件)传递给 apk? If yes, please explain the procedure.如果是,请说明程序。

If you need it for development only, just place a file on the SD card.如果您只需要用于开发,只需在 SD 卡上放置一个文件即可。

final File tmpFile = new File("/sdcard/myparam.txt");
try {
    FileInputStream s = new FileInputStream(tmpFile);
    ...

use adb push myparam.txt /sdcard/ and adb pull /sdcard/myparam.txt to transfer it between the desktop and the device.使用adb push myparam.txt /sdcard/adb pull /sdcard/myparam.txt在桌面和设备之间传输。

It is of course incorrect to assume that the SD card is mounted, as well as to use a hard-coded file name, but it is for development only.假设挂载了 SD 卡以及使用硬编码的文件名当然是不正确的,但它仅用于开发。

If you need to pass a parameter from another application, store in the Intent (assuming that you are the author of both applications).如果您需要从另一个应用程序传递参数,请存储在 Intent 中(假设您是两个应用程序的作者)。

Actually android uses Intent instead of cmd args.实际上android使用Intent而不是cmd args。 To pass a string from your app to another, for example, you do...例如,要将字符串从您的应用程序传递给另一个应用程序,您需要...

String str = "Test";
Intent intent = new Intent(this,externalApp);
intent.putExtra("str",str);
startActivity(intent);

The app on the other side would go...另一边的应用程序会...

Intent intent = getIntent();
String str = getStringExtra("str");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android中将视图作为参数传递? - How can I pass view as parameter in android? 我无法从我的 android 工作室生成签名的 apk/abb 文件 - I can't generate a signed apk / abb file from my android studio 我可以使用Jar签名保护Android APK文件免于反编译吗? - Can I use Jar signing to protect android APK file from decompilation? 如何在Android中使用我的apk文件导出图像? - How can I export images with my apk file in android? 如何从外部属性文件中填充Liquibase参数值? - How can I populate Liquibase parameter values from an external properties file? 如何使用@WithMockUser并从我的属性文件中传递我的用户名和密码? - How can I use @WithMockUser and pass my username and password from my properties file? 如何将属性占位符传递给YAML配置文件中的注释? - How can I pass properties placeholder to annotations from YAML config file? 如何从Android市场加载apk依赖项? - How can I load an apk dependency from the android market? 如何将属性文件中的数字参数传递给 Spring 注释编号(long、或 int、或 Integer 等)参数 - How to pass a number parameter from a properties file to a Spring annotation number (long, or int, or Integer, etc) parameter 如何将系统属性文件传递给GWT? - How can I pass a system properties file to GWT?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM