• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

HELP IN CODING

Change your imports to this...

Java:
package com.speedevs.mtkporting;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
NOW me confused
 

Attachments

  • Screenshot_2019-01-08-04-06-46.png
    Screenshot_2019-01-08-04-06-46.png
    94.1 KB · Views: 77
  • Screenshot_2019-01-08-04-06-36.png
    Screenshot_2019-01-08-04-06-36.png
    92.4 KB · Views: 68
Also your apps build.gradle file should have this dependency...

Code:
implementation 'com.android.support:appcompat-v7:28.0.0'
Code:
package com.speedevs.mtkporting;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class MainActivity extends AppCompatActivity {

    // your sd card
    String sdCard = Environment.getExternalStorageDirectory().toString();
    // the file to be moved or copied
    File sourceLocation = new File (sdCard + "/sample.txt");
    // make sure your target location folder exists!
    File targetLocation = new File (sdCard + "/MyNewFolder/sample.txt");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void copyFile(View view) {
        try {
            copy(sourceLocation, targetLocation);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void copy(File src, File dst) throws IOException {
        InputStream in = new FileInputStream(src);
        try {
            OutputStream out = new FileOutputStream(dst);
            try {
                // Transfer bytes from in to out
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
            } finally {
                out.close();
            }
        } finally {
            in.close();
        }
    }

}
 
@SPEEDEVS
Alrighty, so I had a little time this morning and decided to make a working app to get you started.

It will create both the sample.txt file and destination directory if they don't exists on sd card and move the sample.txt into the destination directory called MyNewFolder.

I also request permission at runtime on a background thread for read/write to sd card.

I've included comments in the code to explain what each method does.

This is a sample app for educational purpose. You will have to add more logic later like allowing users to choose a file and create a destination directory of their choice.

I uploaded the project code to github so that you can download and import it in your IDE. This also makes it easy for any developer to help you with your app. I recommend you learn git and github.

Here is the compiled apk that you can install on your phone so that you or anyone can see how it works...
https://github.com/GameTheory-/Move-File-Sample-App/raw/master/app/release/app-release.apk

Here is the source code on my github account...
https://github.com/GameTheory-/Move-File-Sample-App

I'll be back in the evening to see your progress. Good luck.
 
@SPEEDEVS
Alrighty, so I had a little time this morning and decided to make a working app to get you started.

It will create both the sample.txt file and destination directory if they don't exists on sd card and move the sample.txt into the destination directory called MyNewFolder.

I also request permission at runtime on a background thread for read/write to sd card.

I've included comments in the code to explain what each method does.

This is a sample app for educational purpose. You will have to add more logic later like allowing users to choose a file and create a destination directory of their choice.

I uploaded the project code to github so that you can download and import it in your IDE. This also makes it easy for any developer to help you with your app. I recommend you learn git and github.

Here is the compiled apk that you can install on your phone so that you or anyone can see how it works...
https://github.com/GameTheory-/Move-File-Sample-App/raw/master/app/release/app-release.apk

Here is the source code on my github account...
https://github.com/GameTheory-/Move-File-Sample-App

I'll be back in the evening to see your progress. Good luck.
thanks but about the logic is that where to seee the codes to do it but i wil try ,but if know where to get codes i will be happy AND THANKS FOR THIS ,@GameTheory
 
and pls if you know where i can get source cides to be using i.will be glad to use
and BOOKS to read too so as not to disturb u because you are an app dev ,so just need to learn it fully wel
 
Last edited:
@SPEEDEVS
Honestly all I can recommend is to search google for code samples which will probably land you on StackOverflow(SO). Code you find on the internet usually never works directly in your app by just copy/paste.

The sample code will at least give you an idea of what to do. And if you decide to use it you'll have to figure out how to get it to work within your own code.

Programming involves a lot of problem solving and patience and also getting to know the tools you use really well like for example, your IDE. I use Android Studio(AS) and "gedit" because it doesn't help me code like AS which keeps me sharp.

Now if you just want to learn how to code I think below is a good place to start. They have free courses by some of which are top schools. You can participate in an online class or just take a course on your own time (self paced).

Here are some free courses I searched for you to get you started. Do keep in mind that most courses are using Android Studio...
Take this course first...
https://www.class-central.com/course/udacity-android-for-beginners-7623

Then take this one..
https://www.class-central.com/course/udacity-android-development-for-beginners-3579

Then this...
https://www.class-central.com/course/udacity-android-basics-make-your-first-app-7278

Now when you scroll down the page there is a "Related Courses" section which has more courses if you need more.

If you take the 3 courses I listed you will gain a solid foundation for developing your own apps.

Good luck on your new endeavor and hope to see you here in the future on AF teaching and helping others with their apps. :cool: :thumbsupdroid:
 
@SPEEDEVS
Honestly all I can recommend is to search google for code samples which will probably land you on StackOverflow(SO). Code you find on the internet usually never works directly in your app by just copy/paste.

The sample code will at least give you an idea of what to do. And if you decide to use it you'll have to figure out how to get it to work within your own code.

Programming involves a lot of problem solving and patience and also getting to know the tools you use really well like for example, your IDE. I use Android Studio(AS) and "gedit" because it doesn't help me code like AS which keeps me sharp.

Now if you just want to learn how to code I think below is a good place to start. They have free courses by some of which are top schools. You can participate in an online class or just take a course on your own time (self paced).

Here are some free courses I searched for you to get you started. Do keep in mind that most courses are using Android Studio...
Take this course first...
https://www.class-central.com/course/udacity-android-for-beginners-7623

Then take this one..
https://www.class-central.com/course/udacity-android-development-for-beginners-3579

Then this...
https://www.class-central.com/course/udacity-android-basics-make-your-first-app-7278

Now when you scroll down the page there is a "Related Courses" section which has more courses if you need more.

If you take the 3 courses I listed you will gain a solid foundation for developing your own apps.

Good luck on your new endeavor and hope to see you here in the future on AF teaching and helping others with their apps. :cool: :thumbsupdroid:
@SPEEDEVS
Honestly all I can recommend is to search google for code samples which will probably land you on StackOverflow(SO). Code you find on the internet usually never works directly in your app by just copy/paste.

The sample code will at least give you an idea of what to do. And if you decide to use it you'll have to figure out how to get it to work within your own code.

Programming involves a lot of problem solving and patience and also getting to know the tools you use really well like for example, your IDE. I use Android Studio(AS) and "gedit" because it doesn't help me code like AS which keeps me sharp.

Now if you just want to learn how to code I think below is a good place to start. They have free courses by some of which are top schools. You can participate in an online class or just take a course on your own time (self paced).

Here are some free courses I searched for you to get you started. Do keep in mind that most courses are using Android Studio...
Take this course first...
https://www.class-central.com/course/udacity-android-for-beginners-7623

Then take this one..
https://www.class-central.com/course/udacity-android-development-for-beginners-3579

Then this...
https://www.class-central.com/course/udacity-android-basics-make-your-first-app-7278

Now when you scroll down the page there is a "Related Courses" section which has more courses if you need more.

If you take the 3 courses I listed you will gain a solid foundation for developing your own apps.

Good luck on your new endeavor and hope to see you here in the future on AF teaching and helping others with their apps. :cool: :thumbsupdroid:
THANKS sir i appreciate greately
 
Back
Top Bottom