我想讓我的android應用程序爲當前正在運行的活動截圖,然後將其保存在解析服務器..但它沒有工作...有誰知道這是什麼問題代碼保存在解析服務器的屏幕截圖
我的代碼...
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
takeScreenshot();
}
});
}
private void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".png";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.PNG, quality, outputStream);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Uri uri = Uri.fromFile(imageFile);
byte[] image = stream.toByteArray();
// Create the ParseFile
ParseFile file = new ParseFile(uri.toString(), image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a New Class called "ImageUpload" in Parse
ParseObject imgupload = new ParseObject("Image");
// Create a column named "ImageName" and set the string
// Create a column named "ImageFile" and insert the image
imgupload.put("IMG", file);
// Create the class and the columns
imgupload.saveInBackground();
// Show a simple toast message
Toast.makeText(MainActivity.this, "Image Uploaded",
Toast.LENGTH_SHORT).show();
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
}
發佈logcat的錯誤,或者我會問你「你試過了什麼?你是否用調試器來做它? – Shark
它告訴我,圖像上傳....但沒有出現在解析 –