简体   繁体   English

仅当设备具有txt文件时,我才能使apk起作用吗?

[英]How can I make my apk to function only if my device has a txt file?

How can I make my apk to function only if my device has a txt file? 仅当设备具有txt文件时,我才能使apk起作用吗? I have an apk that I have made. 我有一个APK。

Is there a way to make it work only if the device its installed on has a specific text file which I can input anything in and it won't work if the device doesn't have the file. 只有安装了该设备的设备具有特定的文本文件(我可以在其中输入任何内容)时,才可以使它工作,如果该设备没有该文件,该文件将无法工作。

You can check for your file in onCreate method of your launcher activity. 您可以在启动器活动的onCreate方法中检查文件。 If the file exists, you can do whatever you want like creating an intent to MainActivity and if it does not exist, you can finish your app : 如果该文件存在,则可以执行任何操作,例如为MainActivity创建意图;如果该文件不存在,则可以完成您的应用程序:

File file = new File(filePath);
if(file.exists()) {
    // Do Something 
}
else {
    // Close the app
    finish();
}

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

相关问题 p5.j​​s:如何根据HTML页面使草图加载不同的.txt文件? - p5.js: How can I make my sketch load a different .txt file depending on the HTML page? 如何将函数的结果保存到txt文件中? - How do I save the results of my function to a txt file? 如何在我的 js 代码中使用此 local.txt 文件? - How can I use this local .txt file in my js code? 如何使用我的 runTime 函数更新我的时钟? - How can i make my clock update with my runTime function? 每次我的 JavaScript 文件从其中提取代码时,如何使变量“刷新”自身? - How can I make a variable “refresh” itself every time my JavaScript file has code pulled from it? 如何使此回调函数仅被调用一次? 在我的For循环之后 - How can I make this callback function only be called once? after my For loop 如何确保我的click函数只用Jquery执行一次? - How can I make sure that my click function executes one time only with Jquery? 我如何在Weather App中仅使用一项功能 - How can I Make Use of Only One Function with My Weather App 我如何才能仅通过键盘使用测验? - How can I make my quiz usable by only a keyboard? 如何让我的页面只刷新一次? - how can i make my page refresh only once?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM