Skip to content

Commit

Permalink
ensure mic permissions are requested!
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Oct 30, 2017
1 parent 5c29260 commit 6a867f5
Showing 1 changed file with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package info.guardianproject.phoneypot.ui;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.os.Message;
import android.os.RemoteException;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
Expand All @@ -21,6 +26,8 @@

import java.util.LinkedList;

import info.guardianproject.phoneypot.ListActivity;
import info.guardianproject.phoneypot.MonitorActivity;
import info.guardianproject.phoneypot.PreferenceManager;
import info.guardianproject.phoneypot.R;
import info.guardianproject.phoneypot.model.EventTrigger;
Expand Down Expand Up @@ -69,20 +76,7 @@ public void onValueChanged(int oldValue, int newValue) {

mPrefManager = new PreferenceManager(this.getApplicationContext());

/**
if (mPrefManager.getMicrophoneSensitivity().equals("High")) {
mNumberTrigger.setValue(40);
} else if (mPrefManager.getMicrophoneSensitivity().equals("Medium")) {
mNumberTrigger.setValue(60);
}
else
{
try {
//maybe it is a threshold value?
mNumberTrigger.setValue(Integer.parseInt(mPrefManager.getMicrophoneSensitivity()));
}
catch (Exception e){}
}**/


initWave();
startMic();
Expand Down Expand Up @@ -168,15 +162,45 @@ public void progressTouch(int progress, MotionEvent event) {
//show...
mWaveform.refresh();
}
private void startMic ()
{
try {
microphone = MicrophoneTaskFactory.makeSampler(this);
microphone.setMicListener(this);
microphone.execute();
} catch (MicrophoneTaskFactory.RecordLimitExceeded e) {
// TODO Auto-generated catch block
e.printStackTrace();
private void startMic () {
String permission = Manifest.permission.RECORD_AUDIO;
int requestCode = 999;
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

//This is called if user has denied the permission before
//In this case I am just asking the permission again
ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);

} else {

ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
}
} else {

try {
microphone = MicrophoneTaskFactory.makeSampler(this);
microphone.setMicListener(this);
microphone.execute();
} catch (MicrophoneTaskFactory.RecordLimitExceeded e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

switch (requestCode) {
case 999:
startMic();
break;

}

}
Expand Down

0 comments on commit 6a867f5

Please sign in to comment.