當前位置: 首頁>>代碼示例>>Java>>正文


Java Intent.setDataAndType方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:AppInfoViewHolder.java

示例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;
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:21,代碼來源:PicRecommendActivity.java

示例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;

    }
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:21,代碼來源:FileOpenHelper.java

示例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;
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:35,代碼來源:MethodProxies.java

示例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);
}
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:18,代碼來源:ActivityManager.java

示例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;
	}
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:19,代碼來源:GuideActivity.java

示例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();
    }
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:25,代碼來源:PhotoUtils.java

示例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)));
}
 
開發者ID:metarhia,項目名稱:metacom-android,代碼行數:15,代碼來源:ChatFragment.java

示例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);
}
 
開發者ID:linsir6,項目名稱:TripBuyer,代碼行數:31,代碼來源:HomeActivity.java

示例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();
    }
}
 
開發者ID:liying2008,項目名稱:Simpler,代碼行數:18,代碼來源:FileUtils.java

示例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);
	}
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:32,代碼來源:EaseShowVideoActivity.java

示例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);
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:39,代碼來源:DataLoggerShield.java

示例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();
}
 
開發者ID:WindFromFarEast,項目名稱:SmartButler,代碼行數:9,代碼來源:UpdateActivity.java

示例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);
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:11,代碼來源:VideoPreviewFragment.java

示例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);
}
 
開發者ID:RikkaW,項目名稱:Bridge,代碼行數:15,代碼來源:ChooserActivity.java


注:本文中的android.content.Intent.setDataAndType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。