[FP4S-185] [Sound][Clock]Can not set record sound as ringtone when the first time use sound recorder
Change-Id: I3b8e62ea1a11af158f43972db06e5b0353bbedf7
diff --git a/src/com/android/soundrecorder/SoundRecorder.java b/src/com/android/soundrecorder/SoundRecorder.java
index dc4001e..67d507c 100644
--- a/src/com/android/soundrecorder/SoundRecorder.java
+++ b/src/com/android/soundrecorder/SoundRecorder.java
@@ -271,6 +271,8 @@
private ProgressDialog mProgressDialog;
private final int MSG_DISMISS_PROGRESS_DIALOG = 1100;
+ private static final int RESULT_GRANTED = 99;
+ private static final int RESULT_NOT_GRANTED = 100;
int mAudioSourceType = MediaRecorderWrapper.AudioSource.MIC;
int mPhoneCount = 0;
@@ -390,20 +392,27 @@
@Override
public void onCreate(Bundle icycle) {
super.onCreate(icycle);
+ init(icycle);
- if (Build.VERSION.SDK_INT >= 23) {
+ if (Build.VERSION.SDK_INT >= 23) {
String[] permissions = getOperationPermissionName(OPERATION_RECORD);
if (PermissionUtils.checkAndRequestPermission(this, permissions)) {
Log.e(TAG,"Permission not granted!");
- finish();
return;
}
}
- init(icycle);
-
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode,
+ Intent data) {
+ switch (resultCode) {
+ case RESULT_NOT_GRANTED:
+ finish();
+ break;
+ }
+ }
public void init(Bundle icycle) {
if (getResources().getBoolean(R.bool.config_storage_path)) {
@@ -435,7 +444,8 @@
mIsGetContentAction = Intent.ACTION_GET_CONTENT.equals(i.getAction());
- mExitAfterRecord = i.getBooleanExtra(EXIT_AFTER_RECORD, mIsGetContentAction);
+ mExitAfterRecord = i.getBooleanExtra(EXIT_AFTER_RECORD, mIsGetContentAction);
+
maxDuration = i.getIntExtra(MediaStore.Audio.Media.DURATION, 0);
}
@@ -842,6 +852,7 @@
mSampleInterrupted = false;
mRecorder.stop();
mRecorderProcessed = true;
+
if (isExists) {
saveSample(false);
} else {
@@ -853,7 +864,7 @@
if (mExitAfterRecord) {
finish();
return false;
- }
+ }
return true;
}
diff --git a/src/com/android/soundrecorder/util/PermissionUtils.java b/src/com/android/soundrecorder/util/PermissionUtils.java
index 864cbda..0cb663d 100755
--- a/src/com/android/soundrecorder/util/PermissionUtils.java
+++ b/src/com/android/soundrecorder/util/PermissionUtils.java
@@ -60,7 +60,9 @@
private static final String REQUEST_PERMISSIONS = "request_permissions";
private String[] mRequestedPermissons;
private Intent mPreviousIntent;
-
+ private static final String EXIT_AFTER_RECORD = "exit_after_record";
+ private static final int RESULT_GRANTED = 99;
+ private static final int RESULT_NOT_GRANTED = 100;
private static String[] RECORD_PERMISSIONS = {
Manifest.permission.READ_PHONE_STATE, Manifest.permission.RECORD_AUDIO,
@@ -107,7 +109,7 @@
intent.putExtra(PERVIOUS_INTENT, activity.getIntent());
intent.putExtra(REQUEST_PERMISSIONS, permissions);
intent.setClass(activity, PermissionUtils.class);
- activity.startActivity(intent);
+ activity.startActivityForResult(intent,RESULT_GRANTED);
return true;
}
}
@@ -172,12 +174,8 @@
}
if(isAllPermissionsGranted) {
- if (mPreviousIntent != null){
- Intent intent = new Intent();
- intent.setClass(this, SoundRecorder.class);
- startActivity(intent);
- }
- finish();
+ setResult(RESULT_GRANTED);
+ finish();
} else {
showMissingPermissionDialog();
}
@@ -204,6 +202,7 @@
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
+ setResult(RESULT_NOT_GRANTED);
finish();
}
});