- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用相机拍照的应用程序,然后将照片转发到一个电子邮件地址。然而,在我拍完照片后, Activity 关闭并且我崩溃了,如下图所示:
过去很容易跟踪这个错误,因为我总是检查 Logcat。崩溃很好地显示为红色文本和与之相关的文本。但是,不久前,这种行为消失了,我无法跟踪错误。我不知道我是否更改了某些内容,或者是因为我将 Firebase 与该应用关联...
任何人都可以给我任何关于如何在这种情况下查看错误的提示吗?如果我可能错误地做了一些事情来改变这种行为?
发生崩溃时 Logcat 中唯一显示的是:
01-23 17:03:13.958 27525-6169/packagename V/FA: Connecting to remote service
01-23 17:03:13.988 27525-27525/packagename I/Adreno-EGL: <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.12.SPL
Build Date: 03/03/14 Mon
Local Branch: default
Remote Branch:
Local Patches:
Reconstruct Branch:
01-23 17:03:14.038 27525-6169/packagename V/FA: Activity resumed, time: 2962508140
01-23 17:03:14.128 27525-6169/packagename D/FA: Connected to remote service
01-23 17:03:14.128 27525-6169/packagename V/FA: Processing queued up service tasks: 1
01-23 17:03:19.174 27525-27525/packagename I/PersonaManager: getPersonaService() name persona_policy
01-23 17:03:19.184 27525-27525/packagename V/FA: onActivityCreated
01-23 17:03:19.334 27525-6169/packagename V/FA: Recording user engagement, ms: 5372
01-23 17:03:19.855 27525-6169/packagename V/FA: Activity paused, time: 2962513278
01-23 17:03:19.945 27525-6169/packagename V/FA: Activity resumed, time: 2962513501
01-23 17:03:19.955 27525-6169/packagename V/FA: Inactivity, disconnecting from the service
但它看起来不像是会导致应用程序崩溃的错误。
编辑:根据要求,代码如下:主要 Java 文件:
import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
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 com.karan.churi.PermissionManager.PermissionManager;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Civic extends AppCompatActivity {
static final int REQUEST_TAKE_PHOTO = 1;
private static final int ID_UL_MEU_PENTRU_PERMISIA_DE_WRITING = 1001;
private static final int ID_UL_MEU_PENTRU_PERMISIA_DE_CAMERA = 1000;
public String img1;
public String path;
public int[] store;
PermissionManager permissionManager;
ImageView img;
EditText editTextEmailValue;
EditText editTextNumeValue;
EditText message;
String mCurrentPhotoPath = null;
private Bitmap imgBitmap;
private int mDstWidth;
private int mDstHeight;
private Bitmap scaledBitmap;
private BitmapDrawable drawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawableResource(R.drawable.statuie_thirty_opac);
setContentView(R.layout.activity_civic);
/* CheckPermissionsCamera();*/
TextView info = findViewById(R.id.info);
img = findViewById(R.id.imageV);
Button btnImg = findViewById(R.id.camera);
Button btnSend = findViewById(R.id.sendCivic);
editTextEmailValue = findViewById(R.id.emailCivic);
editTextNumeValue = findViewById(R.id.numeCivic);
message = findViewById(R.id.descriereCivic);
mDstHeight = 720;
mDstWidth = 720;
//CHECK PERMISSIONS
permissionManager = new PermissionManager() {};
permissionManager.checkAndRequestPermissions(this);
//END CHECK PERMISSION
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
//Call back for Dialog!
public void Dialog(View view) {
if (check() == 0) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setMessage("Mulțumim pentru sesizare. Te vom contacta în cel mai scurt timp.")
.setTitle("Mesajul se trimite!")
.setCancelable(false)
.setPositiveButton("Închide", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
sendMail();
Toast.makeText(getApplicationContext(), "Photo saved in:" + mCurrentPhotoPath, Toast.LENGTH_SHORT).show();
message.setText("");
editTextEmailValue.setText("");
editTextNumeValue.setText("");
}
}).show();
}
}
//Conditii!
private int check() {
Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
int counter = 0, leng, x = 300, y = 20;
if (emailVerif(editTextEmailValue.getText().toString()) == false || editTextEmailValue.getText().toString().equals("")) {
editTextEmailValue.setError("Nu ați respectat formatul de email : aaa@bbb.ccc");
editTextEmailValue.requestFocus();
counter++;
}
if (editTextNumeValue.getText().toString().equals("")) {
editTextNumeValue.setError("Obligatoriu!");
editTextNumeValue.requestFocus();
counter++;
}
if (message.getText().toString().equals("")) {
message.setError("Obligatoriu!");
message.requestFocus();
counter++;
}
if (message.getText().length() > x) {
leng = message.getText().length() - x;
message.setError("Ați depășit limita cu : " + leng + " caractere!");
message.requestFocus();
counter++;
} else if (message.getText().length() < y) {
leng = y - message.getText().length();
message.setError("Detaliați cu încă : " + leng + " caractere!");
message.requestFocus();
counter++;
}
if (mCurrentPhotoPath == null) {
Toast.makeText(getApplicationContext(), "Nu ați făcut poză!", Toast.LENGTH_LONG).show();
counter++;
}
if (counter != 0) {
vib.vibrate(500);
}
return (counter);
}
//Return true if email is good else return false
//AICI VERIFICAM DACA FORMATUL DE LA EMAIL ESTE RESPECTAT
protected boolean emailVerif(String email) {
String emailPattern = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" +
"[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Pattern pattern = Pattern.compile(emailPattern);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
//Send mail
private void sendMail() {
//Getting content for email
String email = editTextEmailValue.getText().toString().trim();
String nume = editTextNumeValue.getText().toString().trim();
String mesaj = message.getText().toString().trim();
String image = mCurrentPhotoPath.toString().trim();
//Creating SendMail object
SendMailCivic sm = new SendMailCivic(this, nume, email, mesaj, image);
//Executing sendmail to send email
sm.execute();
}
//Dialog for information!
public void infoCivic(View view) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setMessage("Instructions")
.setTitle("Informatii")
.setCancelable(false)
.setPositiveButton("Închide", null).show();
}
public void CheckPermissionsCamera(View view) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permisii insuficiente.", Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(this,
new String[] {
Manifest.permission.CAMERA
},
ID_UL_MEU_PENTRU_PERMISIA_DE_CAMERA
);
} else if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permisii insuficiente.", Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(this,
new String[] {
Manifest.permission.WRITE_EXTERNAL_STORAGE
},
ID_UL_MEU_PENTRU_PERMISIA_DE_WRITING
);
} else {
dispatchTakePictureIntent();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case ID_UL_MEU_PENTRU_PERMISIA_DE_WRITING:
{
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Ati acceptat permisiunea!", Toast.LENGTH_SHORT).show();
} else {
// daca grantResults e gol, a dat cancel
Toast.makeText(this, "Nu ati acceptat pemisiunea!", Toast.LENGTH_LONG).show();
}
}
case ID_UL_MEU_PENTRU_PERMISIA_DE_CAMERA:
{
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Ati acceptat permisiunea!", Toast.LENGTH_SHORT).show();
} else {
// daca grantResults e gol, a dat cancel
Toast.makeText(this, "Nu ati acceptat pemisiunea!", Toast.LENGTH_LONG).show();
}
}
}
}
}
和发送电子邮件的 SendMailCivic.java:
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
//Class is extending AsyncTask because this class is going to perform a networking operation
public class SendMailCivic extends AsyncTask<Void, Void, Void> {
//Declaring Variables
private Context context;
private Session session;
private ProgressDialog progressDialog;
//Information to send email
private String email;
private String mesaj;
private String nume;
private String image;
//Class Constructor
public SendMailCivic(Context context, String nume, String email, String mesaj, String image) {
//Initializing variables
this.context = context;
this.nume = nume;
this.email = email;
this.mesaj = mesaj;
this.image = image;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(context, "Sending email", "Please wait...", false, false);
progressDialog.show();
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
//Showing a success message
Toast.makeText(context, "Message Sent", Toast.LENGTH_LONG).show();
progressDialog.cancel();
}
@Override
protected Void doInBackground(Void... params) {
//Creating properties
Properties props = new Properties();
//Configuring properties for gmail
props.put("mail.smtp.host", "mail.server.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
//Creating a new session
session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
//Authenticating the password
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Configurare_email.EMAIL, Configurare_email.PASSWORD);
}
});
try {
//Creating MimeMessage object
MimeMessage mm = new MimeMessage(session);
//Setting sender address
mm.setFrom(new InternetAddress(Configurare_email.EMAIL));
//Adding receiver
//TODO set email in InternetAddress
mm.addRecipient(Message.RecipientType.TO, new InternetAddress("receiveradress@server.com"));
//Adding subject
mm.setSubject("MailSubject");
Multipart multipart = new MimeMultipart();
BodyPart mesajPart = new MimeBodyPart();
mesajPart.setText("Name" + nume + "email" + email + "body" + mesaj);
multipart.addBodyPart(mesajPart);
BodyPart attach = new MimeBodyPart();
DataSource source = new FileDataSource(image); //image = path
attach.setDataHandler(new DataHandler(source));
attach.setFileName(image);
multipart.addBodyPart(attach);
mm.setContent(multipart);
//Sending email
Transport.send(mm);
} catch (MessagingException e) {
e.printStackTrace();
}
return null;
}
}
list 文件中给出的路径为:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
@xml/file_paths 包含以下内容:
<< ? xml version = "1.0"
encoding = "utf-8" ? >
<
paths >
<
external - path name = "my_images" / >
<
/paths>
最佳答案
我无法将此作为评论留下,请尝试使用类似...的方法
private Uri getFileUri(String filepath) throws FileNotFoundException {
Uri uri = Uri.parse(filepath);
if (uri.getScheme() == null) {
// No prefix, assuming that provided path is absolute path to file
File file = new File(filepath);
if (file.isDirectory()) {
throw new FileNotFoundException("IsDirectory Not File");
}
uri = Uri.parse("file://" + filepath);
}
return uri;
}
然后,通过执行类似 new File(getFileUri(imagePath));
之类的操作,而不是通过路径传递文件,getFileUri 应该正确处理不正确的文件。然后您可以将文件而不是路径传递到 FileDataSource。
关于android - 相机崩溃但 Logcat 中未显示任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48407447/
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 4 年前。 Improve
我在终端中使用“adb -d logcat”来查看我的应用程序日志文件。最近,我遇到了一大堆运行时错误——由于某种原因我看不到所有这些错误。它只是在结尾处以“...30 more”结束: [ 08-1
我的 Logcat 停止与我的“开发者设备”Huawei Y5 一起工作。 我使用完全更新的 Android 3.5.1,直到两天前一切正常,现在突然我的应用程序日志不再显示了。 logcat 显示以
我使用 Eclipse 开发应用程序。当我转到 eclipse 的菜单窗口-> 显示 View -> 其他时,我发现两个项目名为“LogCat”和“LogCat(deprecated)”。 LogCa
我在我的应用程序中使用 Timber 和 DebugTree。我想将所有消息记录到 Firebase 崩溃报告中。 Timber.plant(object : Timber.DebugTree()
在 Moto G 上开发我的应用程序时,我经常遇到数以万计的以下消息淹没日志。 E/MM_OSAL ( 275): isSamePayload Sync byte(0x47) not found!!
在注意到 Android Studio 中没有显示 Logcat 消息后,我尝试了所有解决方案,但都没有奏效。我最终尝试了命令 adb devices 并确定我的设备在那里,但是当我尝试 adb lo
来自命令:C:\android-sdk-windows\platform-tools>adb shell 然后是 logcat -b radio 它打印旧的历史日志。我试着像这样调用 logcat -
我每15分钟就会遇到“blank logcat”或“logcat bug”的问题,随意告诉它! 我知道以下解决方案可以解决此问题: 进入 DDMS 并选择我的设备 => 80% 的情况下,logcat
请原谅我没有以完整尺寸显示 Logcat(到目前为止,我使用的是 RAM 和图形内存有限的 VM)。 每次启动 Eclipse 时,Logcat 都会像这样显示所有这些信息列(红色圆圈)。 现在,我想
我正在尝试运行 react-native log-android 来测试在我的 react-native 手机应用程序上上传谷歌照片。我得到错误 warn The following packages
对于 Android 应用程序,我将日志保存在设备本身上,以便在出现问题时我们可以找出问题所在。此设备在无互联网环境中运行,因此无法远程写入日志。 下面的代码首先清除缓冲区,然后将记录的内容连续写入“
显示 LogCat 几分钟后消失。我从 Window->Preferences->Logcat 中将 LogCat 输出消息的数量更改为 10000。但在读取整个堆栈之前仍然消失。知道为什么会发生这种
我有一些与 Android Logcat 相关的问题,我将这些问题称为 REAL DEVICE 而不是模拟器: 我有一个程序有很多 Log.d (或其他类似的日志功能),我做了一些谷歌搜索,发现这些日
我收到很多与我的应用程序相关的此类 logcat 消息。 2019-03-13 10:05:51.065 27319-27319/com.example.fir_s1 I/chatty: uid=10
我正在对一个奇怪的错误进行故障排除,当不良行为发生时,我在 logcat 中看到了这一点。 --------- beginning of system 这是什么意思?我没有找到任何 nativ
我想通过 APPIUM 获取特定标签(例如:testing_aws)的 ADB logcats。实际上我是直接从控制台完成此操作的,如下所示 我导航至 /home/jagadeesh/android-
我刚刚开始使用 android,正在制作一个 webview 应用程序 我的整个计划是显示启动屏幕,直到 webview 加载,然后切换某些内容的可见性,然后使 webview 可见 WebView
我刚刚在运行 Mountain Lion 的 Mac 上安装了 Eclipse 3.8。我打开了 LogCat 窗口并点击最小化,它去了某个地方...... 现在当我点击 Window>Show Vi
我使用 Parse 作为我的应用程序的后端,并且我使用了他们的 quick start guide设置推送通知。 我已经一步一步地跟着它了,没有得到插入。当我启动应用程序时,我还在 logcat 中收
我是一名优秀的程序员,十分优秀!