在启动像相机这样的风景活动后,我无法开始其他活动。
首先我开始使用活动相机:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, requestCode);
然后我开始了另外一个这样的活动:
Intent target = new Intent("android.intent.action.VIEW");
String mimeType = getMimeType(fileName);
target.setDataAndType(Uri.fromFile(new File(fileName)), mimeType);
Intent intent = Intent.createChooser(target, "Open File");
try {
context.startActivity(intent);
} catch (ActivityNotFoundException x) {}
但是新活动在启动后闪烁,应用程序崩溃
我的清单是:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:hardwareAccelerated="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout"
android:launchMode="singleTop"
android:screenOrientation="portrait"
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>
我的设备是三星N-5100 android:4.4.2
重复打印此日志
03-14 13:04:19.080 5668-5668/com.myapp E/ViewRootImpl: sendUserActionEvent() mView == null
03-14 13:04:19.090 5668-5668/com.myapp I/PersonaManager: getPersonaService() name persona_policy
03-14 13:04:19.200 5668-5668/com.myapp D/AbsListView: onDetachedFromWindow
03-14 13:04:19.215 5668-5668/com.myapp W/ResolverActivity: mLaunchedFromPackage=com.imyapp
03-14 13:04:19.240 5668-5668/com.myapp D/AbsListView: Get MotionRecognitionManager
D/MultiPhoneWindow: generateLayout : sMinimumStackBoundForPortraitOrientRect(0, 0 - 0, 0), sMinimumStackBoundForLandscapeOrient=Rect(0, 0 - 0, 0)
答案 0 :(得分:0)
如果你得到这个方法,那么你得到错误消息ActivityNotFound然后改变这一行
target.setDataAndType(Uri.fromFile(new File(fileName)), mimeType);
至
File file = new File(fileName);
target.setDataAndType(Uri.fromFile(file.getAbsolutePath(), mimeType);
你的问题解决了