jen*_*fer 89 android android-2.2-froyo galaxy-tab
这是我播放录制的音频3gp文件的代码
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(path);
intent.setDataAndType(data, "audio/mp3");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但是在我的HTC设备(Android 2.2 Froyo)中运行它时会显示异常:
05-04 16:37:37.597: WARN/System.err(4065): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/mnt/sdcard/audio-android.3gp typ=audio/mp3 }
05-04 16:37:37.597: WARN/System.err(4065): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1567)
05-04 16:37:37.597: INFO/ActivityManager(92): Starting activity: Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/mnt/sdcard/audio-android.3gp typ=audio/mp3 }
05-04 16:37:37.607: WARN/System.err(4065): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1537)
05-04 16:37:37.607: WARN/System.err(4065): at android.app.Activity.startActivityForResult(Activity.java:2858)
05-04 16:37:37.607: WARN/System.err(4065): at android.app.Activity.startActivity(Activity.java:2964)
05-04 16:37:37.607: WARN/System.err(4065): at com.ey.camera.AudioRecorder.playAudio(AudioRecorder.java:244)
05-04 16:37:37.607: WARN/System.err(4065): at com.ey.camera.AudioRecorder$4.onClick(AudioRecorder.java:225)
05-04 16:37:37.607: WARN/System.err(4065): at android.view.View.performClick(View.java:2408)
05-04 16:37:37.607: WARN/System.err(4065): at android.view.View$PerformClick.run(View.java:8817)
05-04 16:37:37.607: WARN/System.err(4065): at android.os.Handler.handleCallback(Handler.java:587)
05-04 16:37:37.607: WARN/System.err(4065): at android.os.Handler.dispatchMessage(Handler.java:92)
05-04 16:37:37.607: WARN/System.err(4065): at android.os.Looper.loop(Looper.java:144)
05-04 16:37:37.607: WARN/System.err(4065): at android.app.ActivityThread.main(ActivityThread.java:4937)
05-04 16:37:37.607: WARN/System.err(4065): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 16:37:37.607: WARN/System.err(4065): at java.lang.reflect.Method.invoke(Method.java:521)
05-04 16:37:37.607: WARN/System.err(4065): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-04 16:37:37.607: WARN/System.err(4065): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-04 16:37:37.607: WARN/System.err(4065): at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
在Galaxy平板电脑,它工作正常.我该如何解决这个问题?
Mar*_*ues 145
网址必须以http://开头
Uri uri = Uri.parse("www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
Run Code Online (Sandbox Code Playgroud)
抛出ActivityNotFoundException.如果你前置"http://",问题就解决了.
Uri uri = Uri.parse("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)
可能无法帮助OP,但我最终在这里搜索相同的异常,也许它可以帮助其他人.
小智 34
这是正确的方法.
try
{
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
File file = new File(aFile.getAbsolutePath());
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
myIntent.setDataAndType(Uri.fromFile(file),mimetype);
startActivity(myIntent);
}
catch (Exception e)
{
// TODO: handle exception
String data = e.getMessage();
}
Run Code Online (Sandbox Code Playgroud)
你需要导入import android.webkit.MimeTypeMap;
ojo*_*ifu 28
如果您在尝试从Android应用程序打开网页时也遇到此错误,那是因为您的网址如下所示:
www.google.com
而不是:
https://www.google.com或http://www.google.com
将此代码添加到您的Activity/Fragment:
public void openWebPage(String url) {
Uri webpage = Uri.parse(url);
if (!url.startsWith("http://") && !url.startsWith("https://")) {
webpage = Uri.parse("http://" + url);
}
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
只需将您的网址传递给openWebPage().如果它已经带有前缀https://或者http://你很好,那么if语句会为你处理
Joe*_*ega 17
回答Maragues让我看看logcat输出.看来您传递给Uri的路径需要加上前缀
file:/
因为它是存储的本地路径.
你也可能也想看看路径本身.
`05-04 16:37:37.597: WARN/System.err(4065): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/mnt/sdcard/audio-android.3gp typ=audio/mp3 }`
Run Code Online (Sandbox Code Playgroud)
挂载点似乎在完整路径中出现两次.
erl*_*man 16
在我尝试打开链接时对我来说:
Uri uri = Uri.parse("https://www.facebook.com/abc/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
我得到了同样的错误 android.content.ActivityNotFoundException: No Activity found to handle Intent
问题是因为我没有任何可以打开手机中安装的URL(即浏览器)的应用程序.所以在安装浏览器之后问题就解决了.
*课程:确保至少有一个应用程序处理你打电话的意图*
小智 7
如果您没有通过正确的Web URL并且没有浏览器,则会发生ActivityNotFoundException,因此请检查这些要求或显式处理该异常。那可以解决您的问题。
public static void openWebPage(Context context, String url) {
try {
if (!URLUtil.isValidUrl(url)) {
Toast.makeText(context, " This is not a valid link", Toast.LENGTH_LONG).show();
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
context.startActivity(intent);
}
} catch (ActivityNotFoundException e) {
Toast.makeText(context, " You don't have any browser to open web page", Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
Deep linking如果没有安装默认浏览器,当您处理浏览器的 URL 时,可能会引发此异常。在深层链接的情况下,可能没有安装可以处理格式链接的应用程序myapp://mylink。
您可以使用tangerine解决方案来处理最多 29 个 API:
private fun openUrl(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
val activityInfo = intent.resolveActivityInfo(packageManager, intent.flags)
if (activityInfo?.exported == true) {
startActivity(intent)
} else {
Toast.makeText(
this,
"No application that can handle this link found",
Toast.LENGTH_SHORT
).show()
}
}
Run Code Online (Sandbox Code Playgroud)
对于 API >= 30,请参阅API 30 中的intent.resolveActivity 返回 null。
为了避免崩溃,需要检查以下两件事
科特林
if (url.startsWith("http") || url.startsWith("https")) {
Intent(Intent.ACTION_VIEW,Uri.parse(url)).apply{
// Below condition checks if any app is available to handle intent
if (resolveActivity(packageManager) != null) {
startActivity(this)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有两个想法:
第一:如果你想播放 3gp 文件,你应该使用 mime 类型“audio/3gpp”或“audio/mpeg”
其次:您可以尝试使用setData(data)没有intent任何 mime 类型的方法。
| 归档时间: |
|
| 查看次数: |
125750 次 |
| 最近记录: |