Tag: android fileprovider

来自File Provider Uri的Android 7.0 Notification Sound无法播放

我正在更改我的应用程序代码以支持Android 7,但是在我的NotificationCompat.Builder.setSound(Uri)中,从FileProvider传递Uri,Notification不播放任何声音,在Android 6中使用Uri.fromFile()正常工作。 mp3文件位于: /Animeflv/cache/.sounds/ 这是我的通知代码: knf.animeflv.RequestBackground NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_not_r) .setContentTitle(NotTit) .setContentText(mess); … mBuilder.setVibrate(new long[]{100, 200, 100, 500}); mBuilder.setSound(UtilSound.getSoundUri(not)); //int 这是我的UtilSound.getSoundUri(int) public static Uri getSoundUri(int not) { switch (not) { case 0: return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); default: try { File file=new File(Environment.getExternalStorageDirectory()+”/Animeflv/cache/.sounds”,getSoundsFileName(not)); if (file.exists()) { file.setReadable(true,false); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){ return FileProvider.getUriForFile(context, “knf.animeflv.RequestsBackground”,file); }else { return […]

尝试使用fileProvider从assets文件夹打开PDF文件,但它给出FileNotFoundException:没有这样的文件或目录

我正在尝试显示存储在我的Android应用程序的资产文件夹中的“NEFT.pdf”文件。 以下代码在API 25之前完全正常 private void CopyReadAssets(String filename) { AssetManager assetManager = getAssets(); InputStream in = null; OutputStream out = null; File file = new File(getFilesDir(), filename); try { in = assetManager.open(filename); out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType( Uri.parse(“file://” + getFilesDir() […]