在我开发的android应用中,用户应该能够录制视频,观看视频并通过应用内的电子邮件发送视频。我弄清楚了工作代码,这些动作运行良好,但是后来我的Android Studio疯狂了,几乎每个文件的代码都被iself弄乱了,所以我被迫在同一项目中再次编写代码。但是在那之后,尽管代码完全相同,但是它不再起作用。运行日志不会出现错误,但是应用程序不会崩溃。权限应该可以。
问题可能出在其他地方吗? Build.gradle? Settings.gradle?还是其他可能性?
以下是XML文件中的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".VideoContactActivity">
<TextView
android:id="@+id/textView_recordVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/record_video"
android:textColor="@color/colorTitles1"
android:textSize="@dimen/text_record_video"
android:fontFamily="@font/cinzel_bold"
android:layout_marginStart="70dp"
android:layout_marginTop="160dp"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/record_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView_recordVideo"
android:layout_marginTop="100dp"
android:layout_marginStart="130dp"
android:text="@string/startrRecording"
android:textSize="@dimen/text_record_video"
android:fontFamily="@font/cinzel_bold"
android:textColor="@color/colorTitles2"
android:onClick="captureVideo"/>
<Button
android:id="@+id/check_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/record_video"
android:layout_marginTop="40dp"
android:layout_marginStart="80dp"
android:text="@string/check_recording"
android:textSize="@dimen/text_record_video"
android:fontFamily="@font/cinzel_bold"
android:textColor="@color/colorTitles2"
android:onClick="playVideo"/>
<Button
android:id="@+id/send_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/check_video"
android:layout_marginTop="40dp"
android:layout_marginStart="130dp"
android:text="@string/send_video"
android:textSize="@dimen/text_record_video"
android:fontFamily="@font/cinzel_bold"
android:textColor="@color/colorTitles2"
android:onClick="shareVideo"/>
</RelativeLayout>
和Java文件:
package com.example.mobdog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v7.widget.ContentFrameLayout;
import android.view.View;
import android.widget.Gallery;
public class YhteysKouluttajaanActivity extends AppCompatActivity {
private static int VIDEO_REQUEST = 101;
private Uri videoUri = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_contact);
}
public void captureVideo(View view)
{
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if(videoIntent.resolveActivity(getPackageManager()) !=null)
{
startActivityForResult(videoIntent, VIDEO_REQUEST);
}
}
public void playVideo(View view)
{
Intent playIntent = new Intent(this, VideoPlayActivity.class);
playIntent.putExtra("videoUri", videoUri.toString());
startActivity(playIntent);
}
public void shareVideo(View view) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My problem");
emailIntent.putExtra(Intent.EXTRA_TEXT, "I'd like to get help for this kind of problem");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(videoUri.toString()));
emailIntent.setData(Uri.parse("my-email@outlook.com"));
if (emailIntent.resolveActivity(getPackageManager()) != null) {
startActivity(emailIntent);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==VIDEO_REQUEST && resultCode==RESULT_OK)
{
videoUri = data.getData();
}
}
}
谢谢。