我需要制作一个从设备中选择文件(类型apk)并通过HTTP发布将其发送到网络服务的Android应用。 问题是,如何从文件中获取字节以进行发送?
我已经执行以下操作:
public class MainActivity extends AppCompatActivity {
Button button1;
Button button2;
Intent intent;
String PathHolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = findViewById(R.id.button1);
button2 = findViewById(R.id.button2);
//FileManager
button1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View v){
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
// TODO Auto-generated method stub
switch(requestCode){
case 1:
if(resultCode==RESULT_OK){
//String PathHolder = data.getData().getPath();
PathHolder = data.getData().getPath();
Toast.makeText(MainActivity.this, PathHolder , Toast.LENGTH_LONG).show();
}
break;
}
}
}
现在,我只有文件路径。