Intent Problem

pfillion

Member
Licensed User
Longtime User
Hi,

I needed to make the device go to sleep in 15 seconds and wanted to save the current user timeout value and set it to 15 seconds when the user ran my application and restore the initial value when he closed my application.

I did not find any library to do it so I wrote my first library to change system settings and it works great with SETTING_SCREEN_OFF_TIMEOUT = "screen_off_timeout".

Then I tried to test my library and change the ACTION_AIRPLANE_MODE_CHANGED As String = "android.intent.action.AIRPLANE_MODE". I can toggle the airplane mode but need to intent the OS to let it know that air plane mode has changed.

When I do the following code in my library it works fine;

B4X:
Intent intent = new Intent("android.intent.action.AIRPLANE_MODE");
intent.putExtra("state", 1);
pBA.context.sendBroadcast(intent);

but I did not find a way to do it with the intent function of A4B.

B4X:
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_CALL, "android.intent.action.AIRPLANE_MODE")
Intent1.PutExtra("state",1)
StartActivity(Intent1)

or

B4X:
Dim Intent1 As Intent
Intent1.Initialize("android.intent.action.AIRPLANE_MODE","")
Intent1.PutExtra("state",1)
StartActivity(Intent1)

or any other alternative I tried I get the error

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.AIRPLANE_MODE flg=0x20000 (has extras) }


Anyone has a clue what I'm doing wrong ?

Note: Maybe there is another way to change the airplane mode but I just wanted to test my library and know how to make it work for all the other system settings that I may want to change... without recoding the intent functions to make it work...

Thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…