[英]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.