0

here is code in receive intent with file uri.i just need to read the data in file and display it on text-view * is there any other method for doing this?

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Uri path = data.getData();
    String paths = path.toString();


    if (requestCode == PICK_FROM_FILE && resultCode == RESULT_OK) {


        // File file = new File(Environment.getExternalStorageDirectory(), data.getData().toString());

        String extension = paths.substring(paths.lastIndexOf("."));
        if(extension.equals(".txt"))
        {
            ContentResolver cr = this.getContentResolver();
            File f=new File(String.valueOf(path));
            StringBuilder string =new StringBuilder();
            try
            {
                BufferedReader br=new BufferedReader(new FileReader(f));
                String line;
                while((line=br.readLine())!=null)
                {

                   string.append(line);
                    string.append('\n');

                }
                br.close();
            } catch (IOException e) {

                e.printStackTrace();
            }

        }
        else
        {
            Toast.makeText(getApplicationContext(),"please choose text file",Toast.LENGTH_LONG).show();
        }
    }

}

Thank for help in advance...

my error log is:(HERE THE Warning occurred in my project)

    -06 10:17:24.573 1266-1591/? E/Resources: RunTimeException
                                            android.content.res.Resources$NotFoundException: Resource ID #0x7f02005d
                                            at android.content.res.Resources.getValue(Resources.java:2480)
                                            at android.content.res.Resources.startRC(Resources.java:1095)
                                            at android.app.ActivityThread$mRunnable.run(ActivityThread.java:2969)
                                            at      java.lang.Thread.run(Thread.java:818)
   06-06 10:17:24.673 1294-1294/? E/MotionRecognitionManager: mSContextService = null
   06-06 10:17:24.673 1294-1294/? E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@1aae3e6
   06-06 10:17:27.548 2725-3333/? E/ClipboardUIManager: Failed to get ClipboardService
   06-06 10:17:28.083 2725-2828/? E/libprocessgroup: failed to kill 1 processes for processgroup 22037
   06-06 10:17:28.953 1668-1668/? E/Zygote: MountEmulatedStorage()
   06-06 10:17:28.953 1668-1668/? E/Zygote: v2
   06-06 10:17:28.968 1668-1668/? E/SELinux: [DEBUG] get_category: variable seinfo:   untrusted sensitivity: NULL, cateogry: NULL
   06-06 10:17:29.383 1668-1668/? E/SysUtils: ApplicationContext is null in      ApplicationStatus
Shellz
  • 99
  • 1
  • 14

0 Answers0