Hey meine test App Funktioniert nur Auf dem Handy, sobald ich diese auf der Uhr starte stürzt Sie ab sobald ich auf den Knopf record drücke.
Auf dem Handy klappt alles wunderbar
würde mich über Hilfe sehr freuen.
(geplant ist es selbst eine App zu machen, die auf der Uhr einen Knopf anzeigt mit dem mann eine Aufnahme starten kann)
java Activity:
import android.app.*;
import android.os.*;
import android.widget.*;
import android.app.*;
import android.os.*;
import android.content.*;
import android.Manifest;
import android.content.pm.PackageManager;
import android.util.*;
import android.view.*;
import java.io.*;
import android.media.*;
import android.provider.*;
public class WearableActivity extends Activity
{
private Button play;
private Button record;
private Button stop;
private MediaRecorder myAudioRecorder;
private String outputFile;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wearable);
play=(Button) findViewById(R.id.play);
stop=(Button) findViewById(R.id.stop);
record=(Button) findViewById(R.id.record);
//stop.setEnabled(false);
// play.setEnabled(false);
outputFile= Environment.getExternalStorageDirectory().getAbsolutePath()+"/recording.3gp";
myAudioRecorder=new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
record.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
try{
myAudioRecorder.prepare();
myAudioRecorder.start();
}catch (IllegalStateException ise) {
// make somthing
}catch (IOException ioe){
// make somthing
}
record.setEnabled(false);
stop.setEnabled(true);
Toast.makeText(getApplicationContext(),"Recording started",Toast.LENGTH_LONG).show();
}
});
stop.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
myAudioRecorder.stop();
myAudioRecorder.release();
myAudioRecorder= null;
record.setEnabled(true);
stop.setEnabled(false);
play.setEnabled(true);
Toast.makeText(getApplicationContext(),"Audio Recorder successfully", Toast.LENGTH_LONG).show();
}
});
play.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
MediaPlayer mediaPlayer =new MediaPlayer();
try{
mediaPlayer.setDataSource(outputFile);
mediaPlayer.prepare();
mediaPlayer.start();
Toast.makeText(getApplicationContext(), "Playing Audio", Toast.LENGTH_LONG).show();
}catch (Exception e){
// make something
}
}
});
}
}
wearable.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="record"
android:id="@+id/record"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="stop"
android:id="@+id/stop"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="play1"
android:id="@+id/play"/>
</LinearLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.Zer0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.Light" >
<activity
android:name=".WearableActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>