Search code examples
androidbox-apiboxboxapiv2

can not delete file using BOX SDK on android


I'm fresh with box sdk, I'm trying to use it to delete my box file,but it seems doesn't work. Here is my code, authentication works fine but delete function has problem:

public class MainActivity extends ActionBarActivity {

private Button button_login;
private Button button_logout;
private Button button_delete;

BoxSession session=null;
BoxApiFile file_delete_api = null;
BoxFile file_delete = null;



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

    button_login = (Button) findViewById(R.id.button_login);
    button_logout = (Button) findViewById(R.id.button_logout);
    button_delete = (Button) findViewById(R.id.button_delete);


    BoxConfig.CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    BoxConfig.CLIENT_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

    BoxConfig.REDIRECT_URL = "http://0.0.0.0";

    session = new BoxSession(MainActivity.this);


    button_login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           // BoxApiFile fileApi = new BoxApiFile(session);
            session.authenticate();


        }
    });

    button_logout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            session.logout();
        }
    });

    button_delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new deletefile().execute();
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public class deletefile extends AsyncTask<Void,Void,Void>{

    @Override
    protected Void doInBackground(Void... params) {

        file_delete_api = new BoxApiFile(session);
        try {
            file_delete = file_delete_api.getInfoRequest("f_33651677581").send();
           // file_delete = file_delete_api.getUpdateRequest("f_33651677581").setName("change").setDescription("test change").send();
        } catch (BoxException e) {
            e.printStackTrace();
        }


        return null;
    }
}

}

Here is the exception from log:

07-22 21:12:08.582  26066-26287/? W/System.err﹕ at com.box.androidsdk.content.requests.BoxRequest.send(BoxRequest.java:177)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at com.example.kuhou.box_test_delete_file.MainActivity$deletefile.doInBackground(MainActivity.java:102)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at com.example.kuhou.box_test_delete_file.MainActivity$deletefile.doInBackground(MainActivity.java:95)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)

It seems like there is some thing wrong with

 file_delete = file_delete_api.getInfoRequest("f_33651677581").send();

Is there anyone can help? Thanks a lots.


Solution

  • Try removing the leading f_ from the file ID. That prefix appears in the web UI but the ID is just the numeric portion.

    file_delete = file_delete_api.getInfoRequest("33651677581").send();