summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNBruderman <nbruderman@gmail.com>2015-02-11 01:06:10 +0200
committerniks255 <niks255292@gmail.com>2017-03-02 03:02:34 +0300
commitf7ac96a6d9d83977401168dd852386d6352e8319 (patch)
treedf1497425a9d045f0294a56d2b809c2780b035f6
parentf74f1febfa63ce4f398604a4db0b7e1c9d9dbd40 (diff)
downloadandroid_packages_apps_SoundRecorder-cm-11.0.tar.gz
android_packages_apps_SoundRecorder-cm-11.0.tar.bz2
android_packages_apps_SoundRecorder-cm-11.0.zip
SoundRecorder: Fix trying to view recordings without CM File Managercm-11.0
If the CM file manager is frozen or deleted, trying to view recordings from the app will end up in a crash. Let's fix that. Change-Id: Ie7b68762220320df833e7322e29a24de3148ccc3 (cherry picked from commit 25ec9198c7740568f04148977f33a2788daa4816)
-rw-r--r--src/com/android/soundrecorder/SoundRecorder.java33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/com/android/soundrecorder/SoundRecorder.java b/src/com/android/soundrecorder/SoundRecorder.java
index 9d319c1..5324ff2 100644
--- a/src/com/android/soundrecorder/SoundRecorder.java
+++ b/src/com/android/soundrecorder/SoundRecorder.java
@@ -20,9 +20,11 @@ package com.android.soundrecorder;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
@@ -30,6 +32,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
@@ -954,6 +958,16 @@ public class SoundRecorder extends Activity
if (!mRemainingTimeCalculator.hasExternalStorage()) {
menu.removeItem(R.id.menu_item_storage);
}
+
+ // Remove view recordings if there isn't an activity that can handle it
+ Uri startDir = Uri.fromFile(Environment.getExternalStorageDirectory());
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(startDir, "resource/folder");
+ final PackageManager packageManager = getPackageManager();
+ List<ResolveInfo> info = packageManager.queryIntentActivities(intent, 0);
+ if (info.size() == 0) {
+ menu.removeItem(R.id.menu_item_view_recordings);
+ }
return super.onCreateOptionsMenu(menu);
}
@@ -1002,15 +1016,16 @@ public class SoundRecorder extends Activity
}
break;
case R.id.menu_item_view_recordings:
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setClassName("com.cyanogenmod.filemanager",
- "com.cyanogenmod.filemanager.activities.ShortcutActivity");
- intent.putExtra("extra_shortcut_type", "navigate");
- intent.putExtra("extra_shortcut_fso", mStoragePath);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
+ try {
+ Uri startDir = Uri.fromFile(new File(mStoragePath));
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(startDir, "resource/folder");
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ startActivity(intent);
+ } catch (ActivityNotFoundException ex) {
+ // Ignore. This shouldn't happen. we have checked previously.
+ }
break;
}
return super.onOptionsItemSelected(item);