我知道res
目录中的文件可以从R.class
资产的行为类似文件系统访问,但我想知道,一般来说,最好使用其中一个.
任何人都可以帮助我了解资产和资产之间的真正差异吗?
我需要知道assets文件夹上文件的字符串路径,因为我使用的是需要接收字符串路径的map API,我的地图必须存储在assets文件夹中
这是我正在尝试的代码:
MapView mapView = new MapView(this);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMapFile("file:///android_asset/m1.map");
setContentView(mapView);
Run Code Online (Sandbox Code Playgroud)
出现问题"file:///android_asset/m1.map"
因为没有加载地图.
哪个是存储在我的assets文件夹中的文件m1.map的正确字符串路径文件?
谢谢
编辑Dimitru:此代码不工作,它不能在is.read(buffer);
与IOException异常
try {
InputStream is = getAssets().open("m1.map");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
text = new String(buffer);
} catch (IOException e) {throw new RuntimeException(e);}
Run Code Online (Sandbox Code Playgroud) 我有很多.mp3文件存储在res/raw文件夹中.
我使用以下代码获取.mp3文件的URI.
Uri.parse("android.resource:///com.my.android.sharesound/"+resId);
Run Code Online (Sandbox Code Playgroud)
返回: android.resource:///com.my.android.sharesound/2130968609
现在我在创建Share Intent时使用此URI
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.my.android.sharesound/"+resId));
startActivity(Intent.createChooser(shareIntent,"Share Sound");
Run Code Online (Sandbox Code Playgroud)
当我选择任何邮件应用程序,例如.来自Share Intent的Gmail或YahooMail,已成功附加mp3文件.但它显示2130968609(作为附件)
我不希望出现resourceId(2130968609).
我想显示fileName.mp3
我怎样才能做到这一点?我错过了什么吗?
要么
有没有其他方法可以通过Share Intent将存储在res/raw中的.mp3文件附加到邮件中.
我需要在我的应用程序中获取assets文件夹的绝对路径,因为我想使用Web服务器提供文件,并且它需要绝对路径.这可能吗?
我原以为可能会有这样的事情:
String rootDir = getAssets().getRootDirectory();
Run Code Online (Sandbox Code Playgroud)
但事实并非如此.
任何帮助赞赏,欢呼.
我创建了一个ContentProvider.它导出我的assets /目录中的文件.我正在使用content:// urls来访问WebView中的导出内容.
以下HTML按预期工作:
<img src="content://<provider-name>/test.jpg">
Run Code Online (Sandbox Code Playgroud)
我正在尝试将内容提供程序用于mp3音频文件:
<div id='player'></div>
<script>
url = "content://<provider-name>/test.mp3";
var audio = document.createElement('audio');
audio.src = url;
audio.controls = "controls";
document.getElementById("player").appendChild(audio);
</script>
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息.
E/MediaPlayer(24120): Unable to to create media player
E/HTML5Audio(24120): couldn't load the resource: content://.../test.mp3 exc: java.io.IOException: setDataSource failed.: status=0x80000000
Run Code Online (Sandbox Code Playgroud)
我尝试了Android SDK 8和10但没有成功.我没有在日志中看到对ContentProvider的任何访问权限.看起来在WebView中无法访问音频标签中的内容.这看起来很奇怪,因为以下代码按预期工作:
MediaPlayer player = MediaPlayer.create(this,
Uri.parse("content://<provider-name>/test.mp3")
);
player.start();
Run Code Online (Sandbox Code Playgroud)
如何在WebView中播放ContentProvider中的音频文件?
我有一个Android应用程序用于将.png图像从Android应用程序的资产文件夹传输到我的本地服务器.我需要获取资产文件夹中的图像路径,请参阅下面的代码,
String stringPath = "android.resource//"+getPackageName()+"/raw/sample/logout.png";
File f = new File(stringPath);
Run Code Online (Sandbox Code Playgroud)
如果我使用上面的代码,我得到"文件未找到异常".那么如何在资产文件夹中获取图像路径?
我正在尝试从jar文件加载一个接口的插件实现,该文件位于我的.apk文件的/ assets目录中.我能够让它工作的唯一方法是将jar文件解压缩到私有外部存储器,然后将该文件传递给DexClassLoader.
这有效,但为什么jar必须存在于两个地方(.apk和私人外部存储)?DexClassLoader必须以文件路径作为参数.
有没有办法给它一个直接路径到/ assets文件夹中的文件,这样我就不必使用外部存储来获取已存在的文件的额外副本?
以下是相关的代码段:
// somewhere in my main Activity ...
final File aExtractedDexFile = new File(getDir("dex", Context.MODE_PRIVATE),
LIBRARY_DEX_JAR);
extractDexTo(aExtractedDexFile);
loadLibraryProvider(aExtractedDexFile);
Run Code Online (Sandbox Code Playgroud)
和
/** Extract the jar file that contains the implementation class.dex and place in private storage */
private void extractDexTo(File tJarInternalStoragePath) {
BufferedInputStream aJarInputStream = null;
OutputStream aDexOutputStream = null;
try {
aJarInputStream = new BufferedInputStream(getAssets().open(LIBRARY_DEX_JAR));
aJarOutputStream = new BufferedOutputStream(new FileOutputStream(tJarInternalStoragePath));
byte[] buf = new byte[BUF_SIZE];
int len;
while ((len = aJarInputStream.read(buf, 0, BUF_SIZE)) > 0)
{ …
Run Code Online (Sandbox Code Playgroud) 我正在开发带有通知系统的 android 应用程序,我需要 android 设备使用我存储在资产文件夹中的特定声音推送通知,这是我的通知 java 代码:
Notification noti = new Notification.Builder(MainActivity.this)
.setTicker("Calcupital")
.setContentTitle("Calcupital")
.setContentText("User Information has been updated successfully")
.setSmallIcon(R.drawable.login)
.setContentIntent(pIntent).getNotification();
noti.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
Run Code Online (Sandbox Code Playgroud)
假设我的声音是这样存储的:(\assets\hopo.mp3)
如何通过更改 Android 设备提供的列表中的声音,在不更改其他应用程序的推送通知系统的情况下,使用此声音推送此通知!!
我希望我的问题对你来说很清楚:)
我可以在调试控制台中看到以下警告
W / cr_CrashFileManager:/data/user/0/com.test/cache/WebView/Crash报告不存在或不是目录
我需要自己创建文件夹吗?如何解决警告?