Jump to content
  • 0

Achieving User Notification on Internet Access Denial in Code


MahmoudBasem
 Share

Question

In this code, when the user presses "Yes," it connects to the internet and downloads the file. However, when the user presses "No," it does not give an internet connection error. I want, when the user presses "No," to display a message informing them that the file is not allowed to connect to the internet to download the file and to open another file instead. How can I achieve this?

The code:

DownloadPath = gg.EXT_STORAGE .. "/Download/"

urls={'https://d.apkpure.com/b/APK/com.king.candycrushsaga?version=latest', 'https://d.apkpure.com/b/APK/com.google.android.gm?version=latest', 'https://d.apkpure.com/b/APK/com.alphainventor.filemanager?version=latest', 'https://d.apkpure.com/b/APK/com.facebook.lite?version=latest'}

names={'candy crush.apk','gmail.apk','file manager.apk','facebook lite.apk'}

Urls_name = {'كاندي كراش','جيميل','مدير ملفات','فبسبوك لايت'}

table.insert(Urls_name, 'رجوع')

 

selectedOption = #Urls_name -- رقم الموقع لاختيار "رجوع"

 

codes = gg.choice(Urls_name, nil)

if codes1==nil then -- القايمة المراد فتحها مرة اخري

 end

if codes1 == selectedOption then

   -- استدعاء الوظيفة للرجوع إلى القائمة السابقة

else

  -- استمرار تنفيذ الخيار المحدد

  local selectedUrl = urls[codes]

  local selectedName = names[codes]

  

  Time = os.clock()

  getalldata = (gg.makeRequest(selectedUrl).content)

  file = io.open(DownloadPath .. selectedName, "w")

  file:write(getalldata)

  io.close(file)

  gg.toast("Dᴏᴡɴʟᴏᴀᴅ Sᴜᴄᴄᴇss✔️")

  gg.sleep(2500)

  gg.toast("Dᴏᴡɴʟᴏᴀᴅ Pᴀᴛʜ :" .. DownloadPath)

  gg.sleep(2500)

  gg.toast("Fɪʟᴇ Dᴏᴡɴʟᴏᴀᴅ Tɪᴍᴇ :" .. string.format("%.2f", os.clock() - Time) .. " Sᴇᴄᴏɴᴅs")

  gg.sleep(2500)

  gg.alert("✨"..DownloadPath.."✨\n✨"..selectedName.."✨")

end

IMG_20230921_220327.jpg

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

[ @MahmoudBasem ]
---
Please use "<>" to bracket the codes. And your script have some problem that I would mention here. "codes1" is not exist, change them to "codes"

--Before
if codes1==nil then
--After
if codes == nil then

---

Quote

How can I achieve this?

Just check if "getalldata" is empty:

if getalldata == nil then
    gg.alert('No Internet Connection to download the file. Allow Internet Access to continue')
    os.exit()
else
	...
end

---

sc.lua

Link to comment
Share on other sites

  • 0
On 9/22/2023 at 5:01 AM, kiynox said:

[ @MahmoudBasem ]
---
Please use "<>" to bracket the codes. And your script have some problem that I would mention here. "codes1" is not exist, change them to "codes"

--Before
if codes1==nil then
--After
if codes == nil then

---

Just check if "getalldata" is empty:

if getalldata == nil then
    gg.alert('No Internet Connection to download the file. Allow Internet Access to continue')
    os.exit()
else
	...
end

---

sc.lua 1.55 kB · 2 downloads

function help_menu_1()



   selectedOption = #Urls_name -- رقم الموقع لاختيار "رجوع"



codes1 = gg.choice(Urls_name, nil)

if codes1==nil then ex(11)

 end

if codes1 == selectedOption then

  HOME9() -- استدعاء الوظيفة للرجوع إلى القائمة السابقة

else

  -- استمرار تنفيذ الخيار المحدد

  local selectedUrl = urls1[codes1]

  local selectedName = names[codes1]

  

  Time = os.clock()

  getalldata = (gg.makeRequest(selectedUrl).content)

  if getalldata == nil then

  gg.toast("No Internet Connection to download the file. Allow Internet Access to continue")

  ex(11)

  else

  file = io.open(DownloadPath .. selectedName, "w")

  file:write(getalldata)

  io.close(file)

  gg.toast("Dᴏᴡɴʟᴏᴀᴅ Sᴜᴄᴄᴇss")

  gg.sleep(2500)

  gg.toast("Dᴏᴡɴʟᴏᴀᴅ Pᴀᴛʜ :" .. DownloadPath)

  gg.sleep(2500)

  gg.toast("Fɪʟᴇ Dᴏᴡɴʟᴏᴀᴅ Tɪᴍᴇ :" .. string.format("%.2f", os.clock() - Time) .. " Sᴇᴄᴏɴᴅs")

  gg.sleep(2500)

  gg.alert(""..DownloadPath.."\n"..selectedName.."")

end

end

 ex(11)

end

 

It didn't work the way I wanted. When I go back and choose another option, a message appears about the lack of internet connection. Please watch the attached video to see what I mean. Thanks in advance, my friend.

Edited by MahmoudBasem
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.