当我从图库中选择视频时,会出现安全类型异常。但是除了4.3版本之外,同样的代码在所有Android版本中都可以正常工作。我搜索了答案,有人建议在activity部分使用android:exported="true"
。但是我仍然遇到了相同的异常。
我的代码如下:
@Override
public void onClick(View v) {
if(btngetvideo==v)
{
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 1); //<-- Here m getting exception
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);
Log.v(TAG + ".onActivityResult", "onActivityResult call");
try {
if ( resultData != null) {
String[] projection = { MediaStore.Video.Media.DATA };
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection, null, null, null);
int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToLast();
videopath= cursor.getString(column_index_data);
messageText.setText("Uploading file path :"+ videopath);
dialog = ProgressDialog.show(MainActivity.this, "", "Uploading file...", true);
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("uploading started.....");
}
});
uploadFile(videopath);
//uploadFile(path);
}
}).start();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
和清单代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test333"
android:versionCode="1"
android:versionName="1.0" >
< <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
日志输出错误
10-04 08:21:42.549: E/AndroidRuntime(874): FATAL EXCEPTION: main
10-04 08:21:42.549: E/AndroidRuntime(874): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.PICK dat=content://media/external/video/media cmp=com.android.music/.VideoBrowserActivity } from ProcessRecord{41c469c8 874:com.example.test333/u0a10039} (pid=874, uid=10039) not exported from uid 10019
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.os.Parcel.readException(Parcel.java:1431)
10-04 08:21:42.549: E/AndroidRuntime(874): at android.os.Parcel.readException(Parcel.java:1385)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1947)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.app.Activity.startActivityForResult(Activity.java:3390)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.app.Activity.startActivityForResult(Activity.java:3351)
10-04 08:21:42.549: E/AndroidRuntime(874): at com.example.test333.MainActivity.onClick(MainActivity.java:48)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.view.View.performClick(View.java:4240)
10-04 08:21:42.549: E/AndroidRuntime(874): at android.view.View$PerformClick.run(View.java:17721)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.os.Handler.handleCallback(Handler.java:730)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 08:21:42.549:
E/AndroidRuntime(874): at android.os.Looper.loop(Looper.java:137)
10-04 08:21:42.549: E/AndroidRuntime(874): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-04 08:21:42.549:
E/AndroidRuntime(874): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 08:21:42.549:
E/AndroidRuntime(874): at java.lang.reflect.Method.invoke(Method.java:525)
10-04 08:21:42.549:
E/AndroidRuntime(874): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-04 08:21:42.549:
E/AndroidRuntime(874): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-04 08:21:42.549: E/AndroidRuntime(874): at dalvik.system.NativeStart.main(Native Method)
帮我解决问题,谢谢。