-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendImage.java
86 lines (72 loc) · 2.99 KB
/
SendImage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.mediagoblin;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.*;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.util.Log;
/* the following PHP page will accept this HTTPPost
<?php
$target_path = "./";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$target_path = $_FILES['uploadedfile']['name'];
print_r($_FILES);
echo "<br/>";
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
*/
public class SendImage extends Activity {
private String serverName;
private String username;
private String password;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
serverName = settings.getString("server", "");
username = settings.getString("username", "");
password = settings.getString("password", "");
if (serverName.length() == 0 || username.length() == 0 || password.length() ==0){
final AlertDialog d = new AlertDialog.Builder(SendImage.this).create();
d.setTitle("Error");
d.setMessage("Server, Username, or Password is not configured");
d.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
d.dismiss();
finish();
}
});
d.show();
}
else {
Intent intent = getIntent();
if (Intent.ACTION_SEND.equals(intent.getAction())) {
Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_STREAM)) {
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
String scheme = uri.getScheme();
if (scheme.equals("content")) {
// String mimeType = intent.getType();
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(uri, null, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
Intent sendIntent = new Intent(this, SendService.class);
sendIntent.putExtra("fileName", filePath);
Log.d("MGH", "before startService()");
startService(sendIntent);
finish();
}
}
}
}
}
}