ContentChooser, VideoRecordApp, SDK Version

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I am developing an App that uses CameraEx, ContentChooser, and VideoRecordApp.

My test devices include Android 2.2, two 4.0.3, and a 4.2.2.

CameraEx says it requires 2.3 and higher so it does not work on my 2.2, that is expected, but it does work on the others.

I can't find any specific version requirements for VideoRecordApp and ContentChooser. Both don't work on my 2.2 device. When returning from ContentChooser or VideoRecordApp it does not invoke the _Result subroutine.

One 4.0.3 works as expected, but the second, an Acer tablet, invokes the _Result subroutine on return from recording a video if Cancel was selected (returns success=false), but does not invoke the _Result subroutine if Done is selected to complete the video.

The 4.2.2 device works as expected.

Are there minimum Android version requirements for ContentChooser and VideoRecordApp?

Any idea why I'm getting strange results returning from VideoRecordApp in the Acer 4.0.3 device?

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
There isn't a minimum version for ContentChooser and VideoRecordApp. Can you post the code you are using? You might be doing something wrong.

Thanks for your reply. I can't post the actual code, but I wrote a small test app with several log statements that uses similar code. I attached my test app.

I found a directory string problem which would account for the difference between my two 4.0.3 devices.

I also found differences in the way my 2.2 device versus the 4.x devices return from chooser and video record activities. The 2.2 device would also sometimes delay trying to reestablish the connection to the debugger causing it to follow a different path upon return from the activity, if I compiled in debug mode.

I moved my VidFile definition from Globals to Process Globals to prevent it from being reinitialized on my 2.2 device.

Note on my 2.2 device, after a chooser button click (step 4) it goes to activity_create with firsttime true. It does not do an OnActivityResult and never goes through the chooser result subroutine. The btnVR_Click does an OnActivityResult.

{Added Later:
I noticed in posts from 2011 and 2012 about peculiarities with ContentChooser not going through the Chooser_Result subroutine. This happens every time on my 2.2 device and I also noticed once out of about 25 tries on a 4.0.3 device that Chooser_Result was not called. This happened only once and I was not able to repeat the error. Most of the time on the 4.x devices returning from Chooser goes through the Result subroutine.

I also moved the "Dim CC as ContentChooser" to Process_Globals and the CC.initialize to Activity_Create within First Time = True. This change made no difference in execution on any device.}

Below I have attached log outputs generated from each device:

B4X:
Vibrant (Android ver 2.2, Compiled Release)

PackageAdded: package:b4a.example.vrcctst
** Activity (main) Create, isFirst = true **
1>> In Create
** Activity (main) Resume **
2>> In Resume
3>> btnCC_Click()
** Activity (main) Pause, UserClosed = false **
4>> In Pause, UserClosed = false
** Activity (main) Create, isFirst = true **  NOTE HERE
1>> In Create
** Activity (main) Resume **
2>> In Resume

3>> btnVR_Click()
** Activity (main) Pause, UserClosed = false **
4>> In Pause, UserClosed = false
sending message to waiting queue (OnActivityResult)
** Activity (main) Create, isFirst = false **
5>> In Create
running waiting messages (1)
6>> Vid Rec Comp, Success = true
** Activity (main) Resume **
7>> In Resume
** Activity (main) Pause, UserClosed = false **
8>> In Pause, UserClosed = false
** Activity (main) Create, isFirst = false **
9>> In Create
** Activity (main) Resume **
10>> In Resume

B4X:
Acer A500 (Android ver 4.0.3, Compiled Release)

PackageAdded: package:b4a.example.vrcctst
** Activity (main) Create, isFirst = true **
1>> In Create
** Activity (main) Resume **
2>> In Resume
3>> btnCC_Click()
** Activity (main) Pause, UserClosed = false **
4>> In Pause, UserClosed = false
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
5>> Chooser Result, Success  = true, dir = ContentDir, fn = content://media/external/images/media/889
** Activity (main) Resume **
6>> In Resume

7>> btnVR_Click()
** Activity (main) Pause, UserClosed = false **
8>> In Pause, UserClosed = false
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
9>> Vid Rec Comp, Success = true
** Activity (main) Resume **
10>> In Resume
** Activity (main) Pause, UserClosed = true **
11>> In Pause, UserClosed = true

B4X:
HTC Amaze (Android ver 4.0.3, Compiled Release)

** Activity (main) Create, isFirst = true **
1>> In Create
** Activity (main) Resume **
2>> In Resume
3>> btnCC_Click()
** Activity (main) Pause, UserClosed = false **
4>> In Pause, UserClosed = false
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
5>> Chooser Result, Success  = true, dir = ContentDir, fn = content://media/external/images/media/2829
** Activity (main) Resume **
6>> In Resume

7>> btnVR_Click()
** Activity (main) Pause, UserClosed = false **
8>> In Pause, UserClosed = false
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
9>> Vid Rec Comp, Success = true
** Activity (main) Resume **
10>> In Resume

B4X:
Nexus 7 (Android ver 4.2.2, Compiled Debug)

PackageAdded: package:b4a.example.vrcctst
** Activity (main) Create, isFirst = true **
1>> In Create
** Activity (main) Resume **
2>> In Resume
3>> btnCC_Click()
** Activity (main) Pause, UserClosed = false **
4>> In Pause, UserClosed = false
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
5>> Chooser Result, Success  = true, dir = ContentDir, fn = content://media/external/images/media/4771
** Activity (main) Resume **
6>> In Resume

7>> btnVR_Click()
** Activity (main) Pause, UserClosed = false **
8>> In Pause, UserClosed = false
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
9>> Vid Rec Comp, Success = true
** Activity (main) Resume **
10>> In Resume

Barry.
 

Attachments

  • VRCCTst.zip
    6.3 KB · Views: 292
Last edited:
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
ContentChooser should be declared in Process_Globals (I know that you tried it). It will not work properly in any other place.

The result will be lost if the process gets killed. You can add a service to your application and start it. You can also call Service.StartForeground. It will keep your process running.

Thanks for your reply.

I will move the ContentChooser declaration to Process_Globals.

I am not completely sure what you mean by "add a service". Does that mean create a service, use Service.StartForeground, have the service invoke ContentChooser, have the service handle the Result subroutine and report the result back to the main activity somehow?

Also, I am not concerned with supporting Android version 2.2 devices. I would be happy to put a "requires version 2.3" message in there as long as I could be sure that 2.3 handles ContentChooser similarly to my 4.x devices – unfortunately I don't have any 2.3 devices.

Barry.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
What happened in the first test is that the process was killed while the video was recording. This caused the result to be lost. I haven't experienced such a case before. One way to avoid it is by adding a service and calling Service.StartForeground. This will force the OS to keep the process running.

Though this behavior is not expected.
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
What happened in the first test is that the process was killed while the video was recording. This caused the result to be lost. I haven't experienced such a case before. One way to avoid it is by adding a service and calling Service.StartForeground. This will force the OS to keep the process running.

Though this behavior is not expected.

Hello,
Thanks. I have been working with my test app trying to determine exactly what is happening. The latest version of my test app is attached. I have added a service and that seems to prevent Chooser from skipping its _Result event on my Android 2.2 device.

I also added the same service create/start/stop in the VideoRecordApp portion. What is weird – on my 4.0.3 device everything works the way I would expect, but on the 2.2 device after the Pause and _RecordComplete, it goes through Activity_Create – even if I don't stop the service in _RecordComplete. Setting breakpoints I found that the buttons were no longer initialized. As Erel mentioned, the process must have been terminated.

I've added log outputs below. Notice the difference after the "Pause". The 2.2 device goes through create twice. The 4.0.3 device does not.

B4X:
Samsung Vibrant Android 2.2
4>> btnVR_Click()
5>> VideoRec.Record()
** Service (contentsrv) Create **
Service Create
** Service (contentsrv) Start **
Service Start
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
** Activity (main) Create, isFirst = false **
running waiting messages (1)
6>> Vid Rec Comp, Success = true
** Activity (main) Resume **
** Service (contentsrv) Destroy **
Service Destroy
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **

B4X:
HTC Amaze 4.0.3
1>> btnVR_Click()
2>> VideoRec.Record()
** Service (contentsrv) Create **
Service Create
** Service (contentsrv) Start **
Service Start
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
3>> Vid Rec Comp, Success = true
** Activity (main) Resume **
** Service (contentsrv) Destroy **
Service Destroy

Any ideas? I would like support 2.2 devices since they still account for a small number of users. It could also just be an anomaly in the Samsung Vibrant implementation.

Barry.
 

Attachments

  • VRCCTst2.zip
    10 KB · Views: 255
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Why do you need the Phone.SetScreenOrientation call? You should instead set the supportedOrientation attribute.

Actually I have used both. They seem to be equivalent, are they?

Phone.SetScreenOrientation occurs at runtime. In other projects I have used this, for example, to lock phones in portrait while allowing tablets to change orientation.

For this test project only portrait orientation makes sense. When taking pictures or videos the device can be rotated and the results are correct. I hope this is not causing the anomaly I see on my 2.2 device :eek:


*** Added Later... ***

On my 2.2 device I tried both ways, using the Attribute and using the Phone setting. Both seem to work identically. But, then by accident I noticed something else :sign0148:

With the screen locked in portrait (using either method) if I use the VideoRecordApp holding the phone in portrait mode I get the extra Activity_Create executions. But, with the screen locked in portrait, if I hold the phone in landscape and execute the VideoRecordApp I don't get the Activity_Create executions. This only happens on my 2.2 phone – my 4.0.3 phone and other devices operate as expected.

B4X:
Samsung Vibrant (Android 2.2) holding phone in portrait
7>> btnVR_Click()
8>> VideoRec.Record()
** Service (contentsrv) Start **
Service Start
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
** Activity (main) Create, isFirst = false **
running waiting messages (1)
9>> Vid Rec Comp, Success = true
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **

B4X:
Samsung Vibrant (Android 2.2) holding phone in landscape
10>> btnVR_Click()
11>> VideoRec.Record()
** Service (contentsrv) Start **
Service Start
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
12>> Vid Rec Comp, Success = true
** Activity (main) Resume **

I'm starting to get the feeling that this has nothing to do with the VideoRecordApp or B4A, but is just the implementation of Android 2.2 on the Vibrant by Samsung.

I am looking for a cheap, used, 2.2 or 2.3 phone on eBay to use as an additional development device.

I save and restore state in my target app. I will have to make sure it handles returning from a video recording also.

The important thing is that, with the service added, it is always running the _RecordComplete (and Chooser_Result) routine.

Thanks,
Barry.
 
Last edited:
Upvote 0
Top