没有找到处理带有 ACTION_VIEW 意图的意图的活动
Posted
技术标签:
【中文标题】没有找到处理带有 ACTION_VIEW 意图的意图的活动【英文标题】:No Activity found to handle Intent With ACTION_VIEW Intent 【发布时间】:2015-12-03 11:43:01 【问题描述】:我正在构建一个用于复制视频的简单应用程序。我这样做是为了了解 textView。我已经完成了所有工作,但当我要重现视频时,应用程序崩溃了。我在这里发布所有代码。 这是 MainActivity,是应用程序的唯一 Activity。
package com.example.movieplayer;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.util.Log;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class MoviePlayerActivity extends Activity
implements OnItemClickListener
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_player);
ArrayList<Movie> movieList = new ArrayList<Movie>();
// elenco campi per la query sui media
String[] mediaColumns =
MediaStore.Video.Media._ID,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.DURATION,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.MIME_TYPE
;
// elenco campi per la query sui thumbnail
String[] thumbnailColumns = MediaStore.Video.Thumbnails.DATA ;
// cursore sulle righe risultato
Cursor cursoreMedia = getContentResolver().
query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
mediaColumns, null, null, null);
// per ogni riga del risultto
if ((cursoreMedia != null) && cursoreMedia.moveToFirst())
do
int id = cursoreMedia.getInt(cursoreMedia
.getColumnIndex(MediaStore.Video.Media._ID));
Cursor cursoreMiniature = getContentResolver().
query(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
thumbnailColumns, MediaStore.Video.Thumbnails.VIDEO_ID
+ "=" + id, null, null);
// nuovo oggetto per l'arraylist
Movie movie = new Movie(cursoreMedia, cursoreMiniature);
movieList.add(movie);
while (cursoreMedia.moveToNext());
MovieListAdapter movieListAdapter = new MovieListAdapter(this, movieList);
ListView movieListView = (ListView)findViewById(R.id.listView1);
movieListView.setAdapter(movieListAdapter);
movieListView.setOnItemClickListener(this);
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
// TODO Auto-generated method stub
Movie movie = (Movie) parent.getAdapter().getItem(position);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(movie.getMovieFilePath()),
movie.getMimeType());
startActivity(intent);
这是电影类。
package com.example.movieplayer;
import android.database.Cursor;
import android.provider.MediaStore;
class Movie
private String titolo;
private String videoFilePath;
private String mimeType;
private long durata;
private String miniaturaFilePath;
public Movie(Cursor mediaCursor, Cursor thumbnailCursor)
titolo = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
videoFilePath = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Video.Media.DATA));
mimeType = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE));
durata = mediaCursor.getLong(mediaCursor.getColumnIndex(MediaStore.Video.Media.DURATION));
if ((thumbnailCursor != null) && thumbnailCursor.moveToFirst())
miniaturaFilePath = thumbnailCursor.getString(thumbnailCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
else
miniaturaFilePath = null;
public String getTitolo()
return titolo;
public String getMovieFilePath()
return videoFilePath;
public String getMimeType()
return mimeType;
public long getDurata()
return durata;
public String getThumbnailFilePath()
return miniaturaFilePath;
public String toString()
return "Video [title=" + titolo + ", PathFileVideo=" + videoFilePath
+ ", mimeType=" + mimeType + ", durata=" + durata
+ ", thumbnailFilePath=" + miniaturaFilePath + "]";
这是 MovieListAdapter
package com.example.movieplayer;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;
@SuppressLint( "InflateParams", "DefaultLocale" )
class MovieListAdapter extends BaseAdapter
private Context context;
ArrayList<Movie> videoList;
public MovieListAdapter(Context context, ArrayList<Movie> movieList)
this.context = context;
this.videoList = movieList;
@Override
public int getCount()
return videoList.size();
@Override
public Object getItem(int position)
return videoList.get(position);
@Override
public long getItemId(int position)
return position;
@Override
public View getView(int position, View convertView, ViewGroup parent)
if (convertView == null)
LayoutInflater layoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.movie_item, null);
Movie movie = (Movie) getItem(position);
// thumbnail
ImageView thumbnail =
(ImageView) convertView.findViewById(R.id.thumbnail);
if (movie.getThumbnailFilePath() != null)
thumbnail.setImageURI(Uri.parse(movie.getThumbnailFilePath()));
else
thumbnail.setImageResource(R.drawable.ic_launcher);
//titolo
TextView titolo = (TextView) convertView.findViewById(R.id.titolo);
titolo.setText(movie.getTitolo());
//durata
TextView durata = (TextView) convertView.findViewById(R.id.durata);
durata.setText(getDurataAsString(movie.getDurata()));
return convertView;
private static String getDurataAsString(long durata)
long secondi = durata / 1000;
long millisecondi = durata % 1000;
long minuti = secondi / 60;
secondi %= 60;
long ore = minuti / 60;
minuti %= 60;
String durataString = String.format("%1$02d:%2$02d:%3$02d.%4$03d",
ore, minuti, secondi, millisecondi);
return durataString;
这是应用程序崩溃时 LogCat 给我的错误。
09-08 00:04:42.681: E/AndroidRuntime(9468): FATAL EXCEPTION: main
09-08 00:04:42.681: E/AndroidRuntime(9468): Process: com.example.movieplayer, PID: 9468
09-08 00:04:42.681: E/AndroidRuntime(9468): android.content.ActivityNotFoundException: No Activity found to handle Intent
act=android.intent.action.VIEW
dat=/storage/sdcard0/dcim/Camera/VID_20150804_193111.mp4 typ=video/mp4
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.app.Instrumentation.checkStartActivityResult
(Instrumentation.java:1776)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.app.Instrumentation.execStartActivity
(Instrumentation.java:1496)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.app.Activity.startActivityForResult(Activity.java:3801)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.app.Activity.startActivityForResult(Activity.java:3743)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.app.Activity.startActivity(Activity.java:4072)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.app.Activity.startActivity(Activity.java:4040)
09-08 00:04:42.681: E/AndroidRuntime(9468): at com.example.movieplayer.MoviePlayerActivity.onItemClick
(MoviePlayerActivity.java:85)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.widget.AdapterView.performItemClick(AdapterView.java:305)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.widget.AbsListView.performItemClick(AbsListView.java:1185)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3222)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.widget.AbsListView$3.run(AbsListView.java:4138)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.os.Handler.handleCallback(Handler.java:815)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.os.Handler.dispatchMessage(Handler.java:104)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.os.Looper.loop(Looper.java:194)
09-08 00:04:42.681: E/AndroidRuntime(9468): at android.app.ActivityThread.main(ActivityThread.java:5578)
09-08 00:04:42.681: E/AndroidRuntime(9468): at java.lang.reflect.Method.invoke(Native Method)
09-08 00:04:42.681: E/AndroidRuntime(9468): at java.lang.reflect.Method.invoke(Method.java:372)
09-08 00:04:42.681: E/AndroidRuntime(9468): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:955)
09-08 00:04:42.681: E/AndroidRuntime(9468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
有人知道是什么问题吗?
【问题讨论】:
【参考方案1】:替换:
Uri.parse(movie.getMovieFilePath()
与:
Uri.fromFile(new File(movie.getMovieFilePath()))
看看是否有帮助。从您的错误消息来看,您的 Intent
中的 Uri
没有方案,此更改应该可以解决该问题。
【讨论】:
它有效。你能详细解释一下它是如何以及为什么起作用的吗? @Sash_KP:我在答案的最后一句话中做到了。一个有效的Uri
必须有一个方案。如果传入的String
没有方案,Uri.parse()
将不会添加方案。因此,传递普通路径不适用于Uri.parse()
。以上是关于没有找到处理带有 ACTION_VIEW 意图的意图的活动的主要内容,如果未能解决你的问题,请参考以下文章
MIUI - 尝试启动 ACTION_SEND / ACTION_VIEW 意图时权限被拒绝
在三星设备 (SM-J200F-sdk 22) 中调用 ACTION_VIEW (geo / map) 的意图时应用程序崩溃但适用于许多其他设备!任何解决方案?