Recent

Author Topic: [SOLVED]ActivityForResult in Jcamera --Crash  (Read 3599 times)

Guser979

  • New Member
  • *
  • Posts: 40
Re: ActivityForResult in Jcamera --Crash[SOLVED]
« Reply #15 on: September 08, 2020, 09:01:36 pm »
Hi,  Jm.

Even with the changes and tips I get error when starting activity:

The error has changed and is now:

09-08 14:22:56.611 10481 15385 15385 E AndroidRuntime: FATAL EXCEPTION: main

09-08 14:22:56.611 10481 15385 15385 E AndroidRuntime: Process: org.lamw.appajustscreen, PID: 15385

09-08 14:22:56.611 10481 15385 15385 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

09-08 14:22:56.611 10481 15385 15385 E AndroidRuntime:    at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:605)

09-08 14:22:56.611 10481 15385 15385 E AndroidRuntime:    at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:579)

09-08 14:22:56.611 10481 15385 15385 E AndroidRuntime:    at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)

09-08 14:22:56.611 10481 15385 15385 E AndroidRuntime:    at org.lamw.appajustscreen.jSupported.FileProviderGetUriForFile(jSupported.java:30)

Note: As in the previous situation ...
 Using (In Controls.java)

import android.os.StrictMode;

And adding this just before trigger the camera, it works :

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder ();
   StrictMode.setVmPolicy (builder.build ());



i've tried to insert Authorithies, create providerpath.xml and other tips obtained by searching, but without success so far.

Could not edit manifest. Lawm does not allow for example to edit
this line

<provider android: name = ". jFileProvider" android: authorities = "org.lamw.appajustscreen" android: exported = "true" android: grantUriPermissions = "true" />


I can't see what could be wrong in Lawm. It looks ok, according to what I researched.
 I know almost nothing about java but it seems to be ok.
 So I don't really understand. PS: Manifest was not allowing editing because I had a jprovider component in the project.
 I removed it and was able to add authorithies. But it still doesn't work.






 controls.java

..............
............
   Uri uri = jSupported.FileProviderGetUriForFile(this.GetContext(), newfile);
          if (jSupported.IsAppSupportedProject()) {
             intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //outputFileUri
             intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
          }
          else {
           intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri); //mImageCaptureUri
           intent.putExtra("return-data", true);
          }
       
       
.........
.........
.........
       
jSupported.java      

package org.lamw.appsupportdemo5;

import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;
import java.io.File;


public class jSupported {   

   public static Uri FileProviderGetUriForFile(Controls controls, File file) {
      Uri r = null;
      if (Build.VERSION.SDK_INT >= 24) {
         //[ifdef_api24up]
         r = FileProvider.getUriForFile(controls.GetContext(), controls.GetContext().getApplicationContext().getPackageName() + ".provider", file);
         //[endif_api24up]
      }
      else {
         r = Uri.fromFile(file);
      }
      return r;
   }

   public static Uri FileProviderGetUriForFile(Context context, File file) {
      Uri r = null;

      if (Build.VERSION.SDK_INT >= 24) {
         //[ifdef_api24up]
         r = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
         //[endif_api24up]
      }
      else {
         r = Uri.fromFile(file);
      }
      return r;
   }

   public static boolean IsAppSupportedProject() {
      return true;
   }

}   
       
« Last Edit: September 09, 2020, 02:38:21 pm by Guser979 »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: ActivityForResult in Jcamera --Crash[SOLVED]
« Reply #16 on: September 09, 2020, 10:02:14 pm »

Please, put here your "providerpath.xml" ...

Thanks!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Guser979

  • New Member
  • *
  • Posts: 40
Re: ActivityForResult in Jcamera --Crash[SOLVED]
« Reply #17 on: September 09, 2020, 11:35:41 pm »

I'm currently using this

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: ActivityForResult in Jcamera --Crash[SOLVED]
« Reply #18 on: September 10, 2020, 12:23:07 am »
@Guser979,

Consider putting the [SOLVED] at the beginning of the thread title instead of the end because at the end of it, it is often not visible.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: ActivityForResult in Jcamera --Crash[SOLVED]
« Reply #19 on: September 10, 2020, 12:23:54 am »

Ok.

Meanwhile, I commited  the  "StrictMode"  solution....

You put "providerpath.xm" and this add on in manifest?

Quote
<application>
...................
  <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.appcamerademo.provider"
        android:exported="false"
        android:grantUriPermissions="true">

        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/providerpath"> 
        </meta-data>

   </provider>

<application>

Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Guser979

  • New Member
  • *
  • Posts: 40
Re: ActivityForResult in Jcamera --Crash[SOLVED]
« Reply #20 on: September 10, 2020, 12:36:35 am »
Almost

My

 <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="org.lamw.appajustscreen.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
 </provider>
 

Note: In this case it is not the demo camera I am using. But the errors are the same.


And my res  xml is   provider_paths.xml ...


When compiling with

         </meta-data>


I get

> org.xml.sax.SAXParseException; systemId:AndroidManifest.xml; lineNumber: 56; columnNumber: 51; The element type "meta-data" must be followed by the attribute specifications, ">" or "/>".
« Last Edit: September 10, 2020, 12:49:34 am by Guser979 »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: [SOLVED]ActivityForResult in Jcamera --Crash
« Reply #21 on: September 10, 2020, 04:05:20 am »

My suggestion [not add meta-data]

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="org.lamw.appajustscreen.provider"
        android:exported="false"
        android:grantUriPermissions="true">
 </provider>

Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Guser979

  • New Member
  • *
  • Posts: 40
Re: [SOLVED]ActivityForResult in Jcamera --Crash
« Reply #22 on: September 10, 2020, 04:32:45 am »
 Done.

 9-09 23:22:44.953 10482  8758  8758 E AndroidRuntime: FATAL EXCEPTION: main
09-09 23:22:44.953 10482  8758  8758 E AndroidRuntime: Process: org.lamw.appajustscreen, PID: 8758
09-09 23:22:44.953 10482  8758  8758 E AndroidRuntime: java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data


And returning with Meta Data

09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime: FATAL EXCEPTION: main
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime: Process: org.lamw.appajustscreen, PID: 15762
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime: android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/12345%4081.jpg exposed beyond app through ClipData.Item.getUri()
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1978)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.net.Uri.checkFileUriExposed(Uri.java:2371)

09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.content.ClipData.prepareToLeaveProcess(ClipData.java:966)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.content.Intent.prepareToLeaveProcess(Intent.java:10947)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.content.Intent.prepareToLeaveProcess(Intent.java:10932)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1671)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.app.Activity.startActivityForResult(Activity.java:4703)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.app.Activity.startActivityForResult(Activity.java:4661)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at org.lamw.appajustscreen.Controls.jCamera_takePhoto(Controls.java:2841)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at org.lamw.appajustscreen.Controls.pOnClick(Native Method)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at org.lamw.appajustscreen.jButton$1.onClick(jButton.java:80)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.view.View.performClick(View.java:7357)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.widget.TextView.performClick(TextView.java:14263)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.view.View.performClickInternal(View.java:7323)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.view.View.access$3200(View.java:849)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.view.View$PerformClick.run(View.java:27895)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:873)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:216)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7266)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
« Last Edit: September 10, 2020, 04:47:15 am by Guser979 »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: [SOLVED]ActivityForResult in Jcamera --Crash
« Reply #23 on: September 10, 2020, 07:29:45 pm »

Quote
And returning with Meta Data

Quote
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1978)
09-09 23:36:50.466 10482 15762 15762 E AndroidRuntime:    at android.net.Uri.checkFileUriExposed(Uri.java:2371)

Using  "StrictMode"?


Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Guser979

  • New Member
  • *
  • Posts: 40
Re: [SOLVED]ActivityForResult in Jcamera --Crash
« Reply #24 on: September 10, 2020, 08:22:26 pm »
no "Strict mode" lines. 

UPDATE :

jCamera is finally working perfectly on my Android 9 device. NO Strictmode.
I had written before that I couldn't understand the error, since the code in Lawm seemed to me within what the official Android documentation points to. In fact, after countless tests and rebuilds, I decided to delete the android_wizard in lawm folder.

 I Extract the original "android_wizard" folder to the correct location and did what JM indicated:

I copied jSupported.java  from  lazandroidmodulewizard-master \ android_wizard \ smartdesigner \ java \ support \    to   lazandroidmodulewizard-master\ android_wizard \ smartdesigner \ java \.

Then I opened the appcamerademo and did the conversion to use gladde: Tools \ [Lawm] Android Module Wizard \ Convert the project to appcompat Theme.

Next :

added in Manifest

 <provider
        android: name = "android.support.v4.content.FileProvider"
        android: authorities = "com.example.appcamerademo.provider"
        android: exported = "false"
        android: grantUriPermissions = "true">
        <meta-data
            android: name = "android.support.FILE_PROVIDER_PATHS"
            android: resource = "@ xml / provider_paths" />
 </provider>

in created in res \ xml the file provider_paths.xml

 <?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
 <external-path name="external_files" path="."/>
</paths>

Finally: Build Android Apk and Run (in device).

That is all.

Thanks to Jm and everyone who allows us to use Lazarus and Android.


PS :
My "config"
android-ndk-r10e-windows-x86
android-sdk_r24.4.1-windows
gradle-6.5-all
jdk-8u251-windows-x64.exe
JavaSetup8u251.exe

Important :

Everything is working as expected now. When starting New Project with "add support", jSupported.java is automatically copied and
{
    ............. ..........
    implementation com.android.support:support-v4:28.+'
}.....
So,only add provider needed in manifest and add provider_paths.
« Last Edit: September 12, 2020, 01:13:51 pm by Guser979 »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: [SOLVED]ActivityForResult in Jcamera --Crash
« Reply #25 on: September 13, 2020, 08:48:02 pm »
Quote
So,only add provider needed in manifest and add provider_paths.

Ok. I will improve the LAMW wizard [to add the missing xml ...] and drop "StrictMode" code!

Thank you!!!!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018