开发者

i want to transfer data from pc to android phone for which i am using the following code, i am not able to get working directory

开发者 https://www.devze.com 2023-02-23 07:41 出处:网络
I am getting followin error in the code: java.io.IOException: Error running exec(). Command: [\"/adb\", -s, 9774d56d682e549c, push, \"C:\\Documents, and, Settings\\My, Documents\\other\\music\\b.wma,

I am getting followin error in the code:

java.io.IOException: Error running exec(). Command: ["/adb", -s, 9774d56d682e549c, push, "C:\Documents, and, Settings\My, Documents\other\music\b.wma, ", \sdcard\music] Working Directory: null Environment: null

public class TransferData extends Activity {

private String device_id  ;
private String from = "C:\\Documents and Settings\\My Documents\\other\\music\\b.wma ";
private String to ="\\sdcard\\music";
 private static final String ADB_PUSH = "\"" /*+ Utility.getWorkDir()*/ + File.separator + "adb\" -s %s push \"%s\" %s";
   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
     device_id = Secure.getString(getBaseContext().getContentResolver(),Secure.ANDROID_ID); 

     push(device_id,from,to);
}
   /**  Pushes a file to a connected device via ADB
    * @param deviceId Device serial number 
    * @param from Path of source file (on PC)  
    * @param to Path of file destination (on device)  */
   开发者_如何学Pythonpublic static void push(String deviceId, String from, String to) {
    try { 




        String cmd = String.format(ADB_PUSH, deviceId, from, to);
        System.out.println("adb push: " + cmd);
        Process p = Runtime.getRuntime().exec(cmd);
        InputStream is = p.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println("adb: " + line);
            }
        } catch (IOException e) {
            System.out.println(e);
            }
        } 

}


You can not access your computer disk drive from android.

Just keep the b.wma in the assets folder .

Then use the following code to use b.wma

 try {
    InputStream  is = context.getAssets().open(url);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
      }

Hope this helps you.

0

精彩评论

暂无评论...
验证码 换一张
取 消