本文整理了Java中android.content.Intent.resolveActivity()
方法的一些代码示例,展示了Intent.resolveActivity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.resolveActivity()
方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:resolveActivity
暂无
代码示例来源:origin: stackoverflow.com
/**
* Open a web page of a specified URL
*
* @param url URL to open
*/
public void openWebPage(String url) {
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
代码示例来源:origin: stackoverflow.com
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
代码示例来源:origin: ACRA/acra
@NonNull
private List<Intent> buildInitialIntents(@NonNull PackageManager pm, @NonNull Intent resolveIntent, @NonNull Intent emailIntent) {
final List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(resolveIntent, PackageManager.MATCH_DEFAULT_ONLY);
final List<Intent> initialIntents = new ArrayList<>();
for (ResolveInfo info : resolveInfoList) {
final Intent packageSpecificIntent = new Intent(emailIntent);
packageSpecificIntent.setPackage(info.activityInfo.packageName);
if (packageSpecificIntent.resolveActivity(pm) != null) {
initialIntents.add(packageSpecificIntent);
}
}
return initialIntents;
}
代码示例来源:origin: hidroh/materialistic
public static void share(Context context, String subject, String text) {
Intent intent = new Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_SUBJECT, subject)
.putExtra(Intent.EXTRA_TEXT, !TextUtils.isEmpty(subject) ?
TextUtils.join(" - ", new String[]{subject, text}) : text);
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
}
}
public static Uri createItemUri(@NonNull String itemId) {
代码示例来源:origin: Flipboard/bottomsheet
/**
* This checks to see if there is a suitable activity to handle the `ACTION_PICK` intent
* and returns it if found. {@link Intent#ACTION_PICK} is for picking an image from an external app.
*
* @return A prepared intent if found.
*/
@Nullable
private Intent createPickIntent() {
Intent picImageIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if (picImageIntent.resolveActivity(getPackageManager()) != null) {
return picImageIntent;
} else {
return null;
}
}
代码示例来源:origin: Flipboard/bottomsheet
/**
* This checks to see if there is a suitable activity to handle the {@link MediaStore#ACTION_IMAGE_CAPTURE}
* intent and returns it if found. {@link MediaStore#ACTION_IMAGE_CAPTURE} is for letting another app take
* a picture from the camera and store it in a file that we specify.
*
* @return A prepared intent if found.
*/
@Nullable
private Intent createCameraIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
return takePictureIntent;
} else {
return null;
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
public static void resolveActivityOrAskToInstall(Context context, Intent intent) {
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
} else {
if (context instanceof Activity) {
new AlertDialog.Builder(context)
.setMessage(R.string.no_player_found)
.setPositiveButton(R.string.install, (dialog, which) -> {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(context.getString(R.string.fdroid_vlc_url)));
context.startActivity(i);
})
.setNegativeButton(R.string.cancel, (dialog, which) -> Log.i("NavigationHelper", "You unlocked a secret unicorn."))
.show();
//Log.e("NavigationHelper", "Either no Streaming player for audio was installed, or something important crashed:");
} else {
Toast.makeText(context, R.string.no_player_found_toast, Toast.LENGTH_LONG).show();
}
}
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
private boolean canBrowse(Intent intent) {
return intent.resolveActivity(getPackageManager()) != null && mShareLink != null;
}
代码示例来源:origin: googlesamples/android-testing
private void dispatchTakePictureIntent() {
// Open the camera to take a photo.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
代码示例来源:origin: donglua/PhotoPicker
public Intent dispatchTakePictureIntent() throws IOException {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {
// Create the File where the photo should go
File file = createImageFile();
Uri photoFile;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
String authority = mContext.getApplicationInfo().packageName + ".provider";
photoFile = FileProvider.getUriForFile(this.mContext.getApplicationContext(), authority, file);
} else {
photoFile = Uri.fromFile(file);
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);
}
}
return takePictureIntent;
}
代码示例来源:origin: android-hacker/VirtualXposed
private void handleUninstallShortcutIntent(Intent intent) {
Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (shortcut != null) {
ComponentName componentName = shortcut.resolveActivity(getPM());
if (componentName != null) {
Intent newShortcutIntent = new Intent();
newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
newShortcutIntent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);
}
}
}
代码示例来源:origin: zhihu/Matisse
public void dispatchCaptureIntent(Context context, int requestCode) {
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (captureIntent.resolveActivity(context.getPackageManager()) != null) {
File photoFile = null;
try {
代码示例来源:origin: TeamNewPipe/NewPipe
private boolean viewWithFileProvider(@NonNull File file) {
if (!file.exists()) return true;
String ext = Utility.getFileExt(file.getName());
if (ext == null) return false;
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.substring(1));
Log.v(TAG, "Mime: " + mimeType + " package: " + BuildConfig.APPLICATION_ID + ".provider");
Uri uri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".provider", file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mimeType);
intent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
intent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION);
}
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
}
//mContext.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
Log.v(TAG, "Starting intent: " + intent);
if (intent.resolveActivity(mContext.getPackageManager()) != null) {
mContext.startActivity(intent);
} else {
Toast noPlayerToast = Toast.makeText(mContext, R.string.toast_no_player, Toast.LENGTH_LONG);
noPlayerToast.show();
}
return true;
}
代码示例来源:origin: udacity/ud851-Sunshine
/**
* This method uses the URI scheme for showing a location found on a map in conjunction with
* an implicit Intent. This super-handy intent is detailed in the "Common Intents" page of
* Android's developer site:
*
* @see "http://developer.android.com/guide/components/intents-common.html#Maps"
* <p>
* Protip: Hold Command on Mac or Control on Windows and click that link to automagically
* open the Common Intents page
*/
private void openLocationInMap() {
String addressString = SunshinePreferences.getPreferredWeatherLocation(this);
Uri geoLocation = Uri.parse("geo:0,0?q=" + addressString);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
}
}
代码示例来源:origin: udacity/ud851-Sunshine
/**
* This method uses the URI scheme for showing a location found on a map in conjunction with
* an implicit Intent. This super-handy intent is detailed in the "Common Intents" page of
* Android's developer site:
*
* @see "http://developer.android.com/guide/components/intents-common.html#Maps"
* <p>
* Protip: Hold Command on Mac or Control on Windows and click that link to automagically
* open the Common Intents page
*/
private void openLocationInMap() {
String addressString = SunshinePreferences.getPreferredWeatherLocation(this);
Uri geoLocation = Uri.parse("geo:0,0?q=" + addressString);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
}
}
代码示例来源:origin: udacity/ud851-Sunshine
/**
* This method uses the URI scheme for showing a location found on a map in conjunction with
* an implicit Intent. This super-handy intent is detailed in the "Common Intents" page of
* Android's developer site:
*
* @see "http://developer.android.com/guide/components/intents-common.html#Maps"
* <p>
* Protip: Hold Command on Mac or Control on Windows and click that link to automagically
* open the Common Intents page
*/
private void openLocationInMap() {
String addressString = SunshinePreferences.getPreferredWeatherLocation(this);
Uri geoLocation = Uri.parse("geo:0,0?q=" + addressString);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
}
}
代码示例来源:origin: udacity/ud851-Sunshine
/**
* This method uses the URI scheme for showing a location found on a map in conjunction with
* an implicit Intent. This super-handy intent is detailed in the "Common Intents" page of
* Android's developer site:
*
* @see "http://developer.android.com/guide/components/intents-common.html#Maps"
* <p>
* Protip: Hold Command on Mac or Control on Windows and click that link to automagically
* open the Common Intents page
*/
private void openLocationInMap() {
String addressString = SunshinePreferences.getPreferredWeatherLocation(this);
Uri geoLocation = Uri.parse("geo:0,0?q=" + addressString);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
}
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
private void showCameraAction() {
if (config.maxNum <= Constant.imageList.size()) {
Toast.makeText(getActivity(), "最多选择" + config.maxNum + "张图片", Toast.LENGTH_SHORT).show();
return;
}
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) {
tempFile = new File(FileUtils.createRootPath(getActivity()) + "/" + System.currentTimeMillis() + ".jpg");
LogUtils.e(tempFile.getAbsolutePath());
FileUtils.createFile(tempFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
startActivityForResult(cameraIntent, REQUEST_CAMERA);
} else {
Toast.makeText(getActivity(), "打开相机失败", Toast.LENGTH_SHORT).show();
}
}
代码示例来源:origin: hidroh/materialistic
private void offerExternalApp() {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mItem.getUrl()));
if (intent.resolveActivity(getActivity().getPackageManager()) == null) {
return;
}
mExternalRequired = true;
mWebView.setVisibility(GONE);
getActivity().findViewById(R.id.empty).setVisibility(VISIBLE);
getActivity().findViewById(R.id.download_button).setOnClickListener(v -> startActivity(intent));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void addIntentFilterForComponent() throws Exception {
ComponentName testComponent = new ComponentName("package", "name");
IntentFilter intentFilter = new IntentFilter("ACTION");
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
intentFilter.addCategory(Intent.CATEGORY_APP_CALENDAR);
shadowPackageManager.addActivityIfNotPresent(testComponent);
shadowPackageManager.addIntentFilterForActivity(testComponent, intentFilter);
Intent intent = new Intent();
intent.setAction("ACTION");
assertThat(intent.resolveActivity(packageManager)).isEqualTo(testComponent);
intent.setPackage("package");
assertThat(intent.resolveActivity(packageManager)).isEqualTo(testComponent);
intent.addCategory(Intent.CATEGORY_APP_CALENDAR);
assertThat(intent.resolveActivity(packageManager)).isEqualTo(testComponent);
intent.putExtra("key", "value");
assertThat(intent.resolveActivity(packageManager)).isEqualTo(testComponent);
intent.setData(Uri.parse("content://boo")); // data matches only if it is in the filter
assertThat(intent.resolveActivity(packageManager)).isNull();
intent.setData(null).setAction("BOO"); // different action
assertThat(intent.resolveActivity(packageManager)).isNull();
}
内容来源于网络,如有侵权,请联系作者删除!