本文整理汇总了Java中android.content.Intent.setDataAndType方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.setDataAndType方法的具体用法?Java Intent.setDataAndType怎么用?Java Intent.setDataAndType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.setDataAndType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: installApk
import android.content.Intent; //导入方法依赖的package包/类
private void installApk() {
File[] files = mRxDownload.getRealFiles(mData.downloadUrl);
if (files != null) {
Uri uri = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(mContext, mContext.getApplicationInfo().packageName + ".provider", files[0]);
} else {
uri = Uri.fromFile(files[0]);
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
mContext.startActivity(intent);
} else {
Toast.makeText(mContext, "File not exists", Toast.LENGTH_SHORT).show();
}
}
示例2: handleMessage
import android.content.Intent; //导入方法依赖的package包/类
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case PICK_CITY:
// 跳转选择城市
Intent pickIntent = new Intent(mContext, HotspotMainActivity.class);
Intent intent = getIntent();
if(intent!=null&&("application/pdf").equals(intent.getType())) {
Uri data = getIntent().getData();
pickIntent.setDataAndType(data,intent.getType());
pickIntent.setData(data);
}
Intent mIntent = new Intent();
PicRecommendActivity.this.setResult(111, mIntent);
//finish();
overridePendingTransition(R.anim.slide_in_right,
R.anim.slide_in_left);// 这部分代码是切换Activity时的动画,看起来就不会很生硬
finish();
break;
}
}
示例3: getTextFileIntent
import android.content.Intent; //导入方法依赖的package包/类
public static Intent getTextFileIntent(String param, boolean paramBoolean)
{
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (paramBoolean)
{
Uri uri1 = Uri.parse(param );
intent.setDataAndType(uri1, "text/plain");
}
else
{
Uri uri2 = Uri.fromFile(new File(param ));
intent.setDataAndType(uri2, "text/plain");
}
return intent;
}
示例4: call
import android.content.Intent; //导入方法依赖的package包/类
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
String creator = (String) args[1];
String[] resolvedTypes = (String[]) args[6];
int type = (int) args[0];
int flags = (int) args[7];
if ((PendingIntent.FLAG_UPDATE_CURRENT & flags) != 0) {
flags = (flags & ~(PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_NO_CREATE)) | PendingIntent.FLAG_CANCEL_CURRENT;
}
if (args[5] instanceof Intent[]) {
Intent[] intents = (Intent[]) args[5];
if (intents.length > 0) {
Intent intent = intents[intents.length - 1];
if (resolvedTypes != null && resolvedTypes.length > 0) {
intent.setDataAndType(intent.getData(), resolvedTypes[resolvedTypes.length - 1]);
}
Intent targetIntent = redirectIntentSender(type, creator, intent);
if (targetIntent != null) {
args[5] = new Intent[]{targetIntent};
}
}
}
args[7] = flags;
args[1] = getHostPkg();
// Force userId to 0
if (args[args.length - 1] instanceof Integer) {
args[args.length - 1] = 0;
}
IInterface sender = (IInterface) method.invoke(who, args);
if (sender != null && creator != null) {
VActivityManager.get().addPendingIntent(sender.asBinder(), creator);
}
return sender;
}
示例5: startImageCheckActivity
import android.content.Intent; //导入方法依赖的package包/类
public void startImageCheckActivity(Context context, String path) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri;
File file = new File(path);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// 适配 N (解决FileUriExposedException)
// 见:https://my.oschina.net/shenhuniurou/blog/870156
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
uri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file);
} else {
uri = Uri.fromFile(file);
}
intent.setDataAndType(uri, "image/*");
context.startActivity(intent);
}
示例6: handleMessage
import android.content.Intent; //导入方法依赖的package包/类
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case PICK_CITY:
// 跳转选择城市
Intent pickIntent = new Intent(mContext, HotspotMainActivity.class);
Intent intent = getIntent();
if(intent!=null&&("application/pdf").equals(intent.getType())) {
Uri data = getIntent().getData();
pickIntent.setDataAndType(data,intent.getType());
pickIntent.setData(data);
}
startActivity(pickIntent);
overridePendingTransition(R.anim.slide_in_right,
R.anim.slide_in_left);// 这部分代码是切换Activity时的动画,看起来就不会很生硬
finish();
break;
}
}
示例7: selectPicture
import android.content.Intent; //导入方法依赖的package包/类
/***
* 选择一张图片
* 图片类型,这里是image/*,当然也可以设置限制
* 如:image/jpeg等
*
* @param activity Activity
*/
@SuppressLint("InlinedApi")
public void selectPicture(Activity activity) {
try {
//每次选择图片吧之前的图片删除
clearCropFile(buildUri(activity));
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
if (!isIntentAvailable(activity, intent)) {
return;
}
activity.startActivityForResult(intent, INTENT_SELECT);
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: openFile
import android.content.Intent; //导入方法依赖的package包/类
private void openFile(String filePath) {
Uri uri = FileProvider.getUriForFile(getActivity(),
BuildConfig.APPLICATION_ID + ".provider",
new File(filePath));
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension
(fileExtension);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mimeType);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intent, getString(R.string.open_file)));
}
示例9: cropPhoto
import android.content.Intent; //导入方法依赖的package包/类
/**
* 剪裁照片
*/
public void cropPhoto(Uri uri) {
if (uri == null) {
Log.i("sys", "--tc--> The uri is not exist.");
return;
}
Intent intent = new Intent("com.android.camera.action.CROP");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String url = getPath(HomeActivity.this, uri);
if (url != null) {
intent.setDataAndType(Uri.fromFile(new File(url)), "image/*");
} else {
Log.i("sys", "--tc-->EditUserInfo cropPhoto url is null");
}
} else {
intent.setDataAndType(uri, "image/*");
}
intent.putExtra("crop", "true");
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 210);
intent.putExtra("aspectY", 130);
// outputX outputY 是裁剪图片宽高
intent.putExtra("outputX", 210);
intent.putExtra("outputY", 130);
intent.putExtra("return-data", true);
startActivityForResult(intent, RESULT);
}
示例10: playVideo
import android.content.Intent; //导入方法依赖的package包/类
/**
* 打开视频文件.
*
* @param context 上下文
* @param file 视频文件
*/
public static void playVideo(Context context, File file) {
try {
// 调用系统程序打开文件.
Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(file), "video/*");
context.startActivity(intent);
} catch (Exception ex) {
Toast.makeText(context, "打开失败.", Toast.LENGTH_SHORT).show();
}
}
示例11: onCreate
import android.content.Intent; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.ease_showvideo_activity);
loadingLayout = (RelativeLayout) findViewById(R.id.loading_layout);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
final EMMessage message = getIntent().getParcelableExtra("msg");
if (!(message.getBody() instanceof EMVideoMessageBody)) {
Toast.makeText(EaseShowVideoActivity.this, "Unsupported message body", Toast.LENGTH_SHORT).show();
finish();
return;
}
EMVideoMessageBody messageBody = (EMVideoMessageBody)message.getBody();
localFilePath = messageBody.getLocalUrl();
if (localFilePath != null && new File(localFilePath).exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(localFilePath)),
"video/mp4");
startActivity(intent);
finish();
} else {
EMLog.d(TAG, "download remote video file");
downloadVideo(message);
}
}
示例12: showNotification
import android.content.Intent; //导入方法依赖的package包/类
protected void showNotification(String notificationText) {
// TODO Auto-generated method stub
NotificationCompat.Builder build = new NotificationCompat.Builder(
activity);
build.setSmallIcon(OneSheeldApplication.getNotificationIcon());
build.setContentTitle(activity.getString(R.string.data_logger_shield_name));
build.setContentText(notificationText);
build.setTicker(notificationText);
build.setWhen(System.currentTimeMillis());
build.setAutoCancel(true);
Toast.makeText(activity, notificationText, Toast.LENGTH_SHORT).show();
Vibrator v = (Vibrator) activity
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(1000);
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeFileType = mimeTypeMap.getMimeTypeFromExtension("csv");
if(Build.VERSION.SDK_INT>=24) {
Uri fileURI = FileProvider.getUriForFile(activity,
BuildConfig.APPLICATION_ID + ".provider",
new File(filePath == null || filePath.length() == 0 ? "" : filePath));
notificationIntent.setDataAndType(fileURI, mimeFileType);
}
else{
notificationIntent.setDataAndType(Uri.fromFile(new File(filePath == null
|| filePath.length() == 0 ? "" : filePath)), mimeFileType);
}
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PendingIntent intent = PendingIntent.getActivity(activity, 0,
notificationIntent, 0);
build.setContentIntent(intent);
Notification notification = build.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) activity
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) new Date().getTime(), notification);
}
示例13: installApk
import android.content.Intent; //导入方法依赖的package包/类
private void installApk()
{
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(filePath)),"application/vnd.android.package-archive");
startActivity(intent);
//进入安装Apk界面后直接关闭更新界面
finish();
}
示例14: playDirectVkLinkInExternalPlayer
import android.content.Intent; //导入方法依赖的package包/类
private void playDirectVkLinkInExternalPlayer(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "video/mp4");
if (nonNull(getActivity().getPackageManager().resolveActivity(intent, 0))) {
startActivity(intent);
} else {
Utils.showRedTopToast(getActivity(), R.string.no_compatible_software_installed);
}
}
示例15: start
import android.content.Intent; //导入方法依赖的package包/类
/**
* Start target select
*
* @param context
*/
public static void start(Context context) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setDataAndType(Uri.parse("content://example"), "*/*");
List<ResolveInfo> resolveInfo = context.getPackageManager().queryIntentActivities(shareIntent, 0);
Intent intent = new Intent(context, ChooserActivity.class);
intent.putParcelableArrayListExtra(EXTRA_RESOLVE_INFO, ResolveInfoHelper.filter(resolveInfo, true));
context.startActivity(intent);
}