Java Code Examples for android.content.Intent.setDataAndType()

The following are Jave code examples for showing how to use setDataAndType() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Hotspot-master-devp   File: PicRecommendActivity.java   View Source Code Vote up 7 votes
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;
    }
}
 
Example 2
Project: CXJPadProject   File: FileOpenHelper.java   View Source Code Vote up 7 votes
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;

    }
 
Example 3
Project: VirtualHook   File: MethodProxies.java   View Source Code Vote up 7 votes
@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;
}
 
Example 4
Project: GitHub   File: AppInfoViewHolder.java   View Source Code Vote up 7 votes
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();
    }
}
 
Example 5
Project: Musicoco   File: ActivityManager.java   View Source Code Vote up 7 votes
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);
}
 
Example 6
Project: Hotspot-master-devp   File: GuideActivity.java   View Source Code Vote up 7 votes
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;
	}
}
 
Example 7
Project: sealtalk-android-master   File: PhotoUtils.java   View Source Code Vote up 7 votes
/***
 * 选择一张图片
 * 图片类型,这里是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();
    }
}
 
Example 8
Project: metacom-android   File: ChatFragment.java   View Source Code Vote up 6 votes
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)));
}
 
Example 9
Project: TripBuyer   File: HomeActivity.java   View Source Code Vote up 6 votes
/**
 * 剪裁照片
 */
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);
}
 
Example 10
Project: Simpler   File: FileUtils.java   View Source Code Vote up 6 votes
/**
 * 打开视频文件.
 *
 * @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();
    }
}
 
Example 11
Project: GCSApp   File: EaseShowVideoActivity.java   View Source Code Vote up 6 votes
@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);
	}
}
 
Example 12
Project: CustomAndroidOneSheeld   File: DataLoggerShield.java   View Source Code Vote up 6 votes
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);
}
 
Example 13
Project: SmartButler   File: UpdateActivity.java   View Source Code Vote up 6 votes
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();
}
 
Example 14
Project: Phoenix-for-VK   File: VideoPreviewFragment.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 15
Project: Bridge   File: ChooserActivity.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 16
Project: USay   File: PersonSettingActivity.java   View Source Code Vote up 6 votes
/**
 * 裁剪图片方法实现
 *
 * @param uri uri
 */
public void startPhotoZoom(Uri uri) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");  // crop=true是设置在开启的Intent中设置显示的VIEW可裁剪
    intent.putExtra("aspectX", 1);   // aspectX aspectY 是宽高的比例
    intent.putExtra("aspectY", 1);
    intent.putExtra("outputX", 300);  // outputX outputY 是裁剪图片宽高
    intent.putExtra("outputY", 300);
    intent.putExtra("scale", true);
    intent.putExtra("noFaceDetection", true);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, REQUEST_CODE_CROP_12);
}
 
Example 17
Project: android-project-gallery   File: AppHelper.java   View Source Code Vote up 6 votes
/**
 * 安装应用程序
 * 
 * @param context 上下文
 * @param path 文件地址
 */
public static final void install(Context context, String path)
{
	Intent intent = new Intent();
	intent.setAction(android.content.Intent.ACTION_VIEW);
	intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	intent.setDataAndType(Uri.parse("file://" + path), "application/vnd.android.package-archive");
	context.startActivity(intent);
}
 
Example 18
Project: Bing   File: SaveFileTask.java   View Source Code Vote up 6 votes
private void autoInstallApk(File file) {
    if (FileUtil.getExtension(file.getPath()).equals("apk")) {
        final Intent install = new Intent();
        install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        install.setAction(Intent.ACTION_VIEW);
        install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        Bing.getApplicationContext().startActivity(install);
    }
}
 
Example 19
Project: stynico   File: SimpleActivity.java   View Source Code Vote up 5 votes
/**
    * 打开文件
    *
    * @param f
    */
   private void openFile(File f)
{
       final MyUser bmobUser = BmobUser.getCurrentUser(SimpleActivity.this, MyUser.class);
       if (bmobUser != null)
	{
           MyUser newUser = new MyUser();
           newUser.setAddress("激活");
           newUser.update(SimpleActivity.this, bmobUser.getObjectId(), new UpdateListener() {

				@Override
				public void onSuccess()
				{
				}

				@Override
				public void onFailure(int code, String msg)
				{
					Toast.makeText(SimpleActivity.this, "认证失败,请重试(" + code + ")", Toast.LENGTH_SHORT).show();
				}
			});
       }
	else
	{
           //toast("本地用户为null,请登录。");

       }
       FK__ feedback = new FK__();
       feedback.setContent((String) BmobUser.getObjectByKey(this, "objectId"));
       feedback.save(SimpleActivity.this, new SaveListener() {

			@Override
			public void onFailure(int p1, String p2)
			{

			}

			@Override
			public void onSuccess()
			{

				Toast.makeText(SimpleActivity.this, "已关闭弹屏", Toast.LENGTH_SHORT).show();
				final SharedPreferences setting = SimpleActivity.this.getSharedPreferences("Viewpa__m", 0);
				setting.edit().putBoolean("FIRST", false).commit();

			}

		});
       Intent intent = new Intent(Intent.ACTION_VIEW);
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//将一个新的view置于台前
       intent.setDataAndType(Uri.fromFile(f), "application/vnd.android.package-archive");//打开apk格式的文件
       this.startActivity(intent);

   }
 
Example 20
Project: EasyScreenRecorder   File: MainActivity.java   View Source Code Vote up 5 votes
void play(String path) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(path));
    intent.setDataAndType(Uri.parse(path), "video/mp4");
    startActivity(intent);
}