سلام این کدمه
نمیتونم بفهمم چرا این ارور رو میده
نمیتونم بفهمم چرا این ارور رو میده
کد پیاچپی:
package com.example.mehrdad.myapplication;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.media.Image;
import android.net.Uri;
import android.os.Environment;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import static com.example.mehrdad.myapplication.R.id.textView;
public class MainActivity extends AppCompatActivity {
protected static final int request = 0;
public static class App {
public static File _file;
public static Bitmap bitmap;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final File dir = new File(Environment.getExternalStorageDirectory()+"/myFolder");
dir.mkdirs();
Button btnCamera = (Button) findViewById(R.id.button2);
btnCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Date date = new Date();
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
App._file = new File(dir,dateFormat.format(date)+".jpg");
intent.putExtra (MediaStore.EXTRA_OUTPUT, Uri.fromFile (App._file));
startActivityForResult(intent, 0);
}
});
Button btnSave= (Button) findViewById(R.id.button);
Button btnOpen= (Button) findViewById(R.id.btnOpen);
final EditText txtData= (EditText) findViewById(R.id.editText);
txtData.setHint("write your note");
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
final Date date = new Date();
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
File myFile = new File(dir, dateFormat.format(date) + ".txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter fWrite = new OutputStreamWriter(fOut);
fWrite.append(txtData.getText());
fWrite.close();
fOut.close();
Toast.makeText(getBaseContext(), dateFormat.format(date) + ".txt is saved", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == request) {
//use imageUri here to access the image
Bundle extras = data.getExtras();
Log.e("URI", App._file.toString());
App.bitmap = (Bitmap) extras.get("data");
// here you will get the image as bitmap
}
}
}
/* @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Intent mediaScanIntent = new Intent (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(App._file);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
// Display in ImageView. We will resize the bitmap to fit the display.
// Loading the full sized image will consume to much memory
// and cause the application to crash.
int height = Resources.DisplayMetrics.HeightPixels;
int width = showpic.Height ;
App.bitmap = App._file.Path.LoadAndResizeBitmap (width, height);
if (App.bitmap != null) {
showpic.SetImageBitmap (App.bitmap);
App.bitmap = null;
}
// Dispose of the Java side bitmap.
GC.Collect();
}
*/
@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);
}
}