3
當我從庫中選擇視頻時,它會給出安全類型異常。但相同的代碼在所有版本的Android中工作,只有4.3。我搜索了同樣的答案,建議在活動部分使用android:exported="true"
。但仍然得到同樣的例外。java.lang.SecurityException:權限拒絕:新版本4.3中的意圖
我的代碼是
@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>
logcat的錯誤
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)
幫我理清感謝
它是什麼解決方案? –
@sunil:不要使用'Intent'。不幸的是,您將不得不創建自己的視頻瀏覽活動。 – CommonsWare
以其他方式瀏覽視頻的任何相關代碼建議plz? –