尝试制作音频记录然后使用GMAIL应用程序发送它,但它粉碎并告诉空指针异常和blah-blah-blah看到下面的图片。 我试图在5秒内创建一个记录,然后停止计时器并发送电子邮件消息。
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
outputFile = Environment.getExternalStorageDirectory().
getAbsolutePath() + "/recordMemo.3gp";
eDB = new dbConfig(this);
sqlDB = eDB.getWritableDatabase();
smsPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
smsText = smsPreferences.getString("smsTXT", "I'll call you later");
Log.d("TEXT", smsText);
gpsManager = new GPSManager();
gpsManager.startListening(getApplicationContext());
gpsManager.setGPSCallback((GPSCallback) this);
StateListener phoneStateListener = new StateListener();
telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(outputFile);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
//gpsInfo = (TextView) findViewById(R.id.gps_info);
//gpsInfo.setText(getString(R.string.gpsSPEED));
//
}
CountDownTimer start = new CountDownTimer(5000, 1000) {
@Override
public void onTick(long l) {
//Toast.makeText(getApplicationContext(), "Recording!!!",
// Toast.LENGTH_SHORT).show();
}
@Override
public void onFinish() {
try {
myRecorder.stop();
myRecorder.release();
myRecorder = null;
Log.d("STOP", "STOP");
Toast.makeText(getApplicationContext(), "Stop recording...",
Toast.LENGTH_SHORT).show();
} catch (IllegalStateException e) {
e.printStackTrace();
}
catch (RuntimeException e) {
e.printStackTrace();
}
if (action.equals("1")) {
//Log.d("OUTPUT", outputFile);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("application/octet-stream");
share.putExtra(Intent.EXTRA_SUBJECT, "My Memo");
share.putExtra(Intent.EXTRA_TEXT, "Sending my memo");
share.putExtra(Intent.EXTRA_EMAIL,
new String[] { myEmail });
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://" + outputFile));
MainActivity.this.startActivity(share);
}
}
}.start();