-2

Using android studio

When I try to compile with this in the main activity it gives the error at the end of the post

The code i use:

public void buttonOnClick(View v) {
        // do something when the button is clicked
        Button button=(Button) v;
        File from = new File(Environment.getInternalStorage().getAbsolutePath()+"/data/data/com.android.providers.contacts/databases/contacts2.db");
        File to = new File(Environment.getExternalStorage().getAbsolutePath()+"/backup/contacts2.db");
        from.renameTo(to);

Then I get this error :

Error:(25, 42) error: cannot find symbol method getInternalStorage()
Error:(26, 40) error: cannot find symbol method getExternalStorage()
Error:(34, 41) error: cannot find symbol method getExternalStorage()
Error:(35, 39) error: cannot find symbol method getInternalStorage()
Note: C:\Users\Alex\AndroidStudioProjects\QuickTransfer\app\src\main\java\com\am\tpz\quicktransfer\MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
mpromonet
  • 11,326
  • 43
  • 62
  • 91
epicdig07
  • 3
  • 7
  • Perhaps because the api is [Environment.getExternalStorageDirectory()](http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29) – mpromonet Aug 01 '15 at 10:41
  • 1
    @epicdig07: don't reuse accounts between co-workers then. Get your own account, and if a question was not as good as it could have been, *update the existing question*. – Martijn Pieters Aug 01 '15 at 10:46

1 Answers1

-1

Ok i found it. That works but you must put the following permissions in the android manifest. and change the

getExternalStorage

to

getExternalStorageDirectory

the permissions:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
epicdig07
  • 3
  • 7