|
1
2
3
4
5
6
7
8
9
10
|
Intent intent = newIntent(
this
, PlayerActivity.
class
);
startActivity(intent);
Intent intent =
new
Intent();
intent.setClass(
this
,PlayerActivity.
class
);
startActivity(intent);
Intent intent =
new
Intent();
intent.setClassName(“com.jhuster.videoplayer”,“com.jhuster.videoplayer.PlayerActivity”);
startActivity(intent);
|
|
1
2
|
Intent intent =
new
Intent(Intent.ACTION_DIAL,Uri.parse(“tel:
021
-
80961111
”));
startActivity(intent);
|
|
1
2
3
4
5
|
<activity android:name=
"com.jhuster.videoplayer.PlayerActivity"
>
<intent-filter>
<action android:name=
"android.intent.action.VIEW"
/>
</intent-filter>
</activity>
|
|
1
2
3
|
DEFAULT 默认动作
HOME 设置为本地桌面应用
LAUNCHER 本APP的启动Activity
|
|
1
2
3
4
5
6
|
<activityandroid:name=
"com.jhuster.videoplayer.PlayerActivity"
>
<intent-filter>
<actionandroid:name=
"android.intent.action.VIEW"
/>
<categoryandroid:name=
"android.intent.category.DEFAULT"
/>
</intent-filter>
</activity>
|
|
1
2
3
4
5
|
android:host: 指定主机名,例如:google.com
android:port: 制定主机端口,例如: 80
android:path: 指定URL的有效路径值,例如: /index/examples
android:mimeType: 指定组件可以执行的数据类型,例如:image/jpeg,video/*
android:scheme: 指定特定的模式,例如:content,http
|
|
1
2
3
4
|
<
data
android:scheme
=
"file"
/>
<
data
android:scheme
=
"content"
/>
<
data
android:scheme
=
"http"
/>
<
data
android:scheme
=
"rtsp"
/>
|
|
1
2
3
|
Intent intent =
new
Intent(Intent.ACTION_VIEW);
intent.setData(Uri.fromFile(
new
File(
"/sdcard/test.3gp"
)));
startActivity(intent);
|
|
1
2
3
|
Intent intent =
new
Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
"http://ticktick.blog.51cto.com/test.mp4"
));
startActivity(intent);
|
|
1
2
|
<data android:mimeType=
"video/3gpp"
/>
<data android:mimeType=
"video/mp4"
/>
|
|
1
2
3
|
Intent intent =
new
Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(
new
File(
"/sdcard/test.3gp"
)),
"video/3gpp"
);
startActivity(intent);
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<
activity
android:name
=
"com.jhuster.videoplayer.PlayerActivity"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.action.VIEW"
/>
<
category
android:name
=
"android.intent.category.DEFAULT"
/>
<
data
android:scheme
=
"file"
/>
<
data
android:scheme
=
"content"
/>
<
data
android:scheme
=
"http"
/>
<
data
android:scheme
=
"rtsp"
/>
<
data
android:scheme
=
"rtmp"
/>
<
data
android:mimeType
=
"video/3gpp"
/>
<
data
android:mimeType
=
"video/mp4"
/>
</
intent-filter
>
</
activity
>
|
|
1
2
3
4
|
public
String getAction();
public
Uri getData();
public
String getScheme();
public
String getType();
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
public
static
String getVideoPath(Context context, Uri uri) {
Uri videopathURI = uri;
if
(uri.getScheme().toString().compareTo(
"content"
) ==
0
) {
Cursor cursor = context.getContentResolver().query(uri,
null
,
null
,
null
,
null
);
if
(cursor.moveToFirst()) {
int
column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videopathURI = Uri.parse(cursor.getString(column_index));
return
videopathURI.getPath();
}
}
else
if
(uri.getScheme().compareTo(
"file"
) ==
0
) {
return
videopathURI.getPath();
}
return
videopathURI.toString();
}
|
本文通过实战案例,详细讲解了Android开发中隐式Intent的配置与使用方法,包括如何为Activity添加<intent-filter>标签,以及如何解析Intent中的参数。
329

被折叠的 条评论
为什么被折叠?



