本文整理了Java中android.content.Intent.setPackage()
方法的一些代码示例,展示了Intent.setPackage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.setPackage()
方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:setPackage
暂无
代码示例来源:origin: google/ExoPlayer
private static PendingIntent createBroadcastIntent(
String action, Context context, int instanceId) {
Intent intent = new Intent(action).setPackage(context.getPackageName());
intent.putExtra(EXTRA_INSTANCE_ID, instanceId);
return PendingIntent.getBroadcast(
context, instanceId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
代码示例来源:origin: nickbutcher/plaid
public static void addToPocket(Context context,
String url,
String tweetStatusId) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage(PACKAGE);
intent.setType(MIME_TYPE);
intent.putExtra(Intent.EXTRA_TEXT, url);
if (tweetStatusId != null && tweetStatusId.length() > 0) {
intent.putExtra(EXTRA_TWEET_STATUS_ID, tweetStatusId);
}
intent.putExtra(EXTRA_SOURCE_PACKAGE, context.getPackageName());
context.startActivity(intent);
}
代码示例来源:origin: stackoverflow.com
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", smsText);
i.setPackage("com.whatsapp");
startActivity(i);
代码示例来源:origin: stackoverflow.com
// explicit Intent, safe
Intent serviceIntent = new Intent(ILicensingService.class.getName());
serviceIntent.setPackage("com.android.vending");
boolean bindResult = mContext.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
代码示例来源:origin: aa112901/remusic
private void sendIntent(String action){
Intent intent = new Intent();
intent.setAction(action);
intent.setPackage(IConstants.PACKAGE);
sendBroadcast(intent);
}
代码示例来源:origin: stackoverflow.com
public void onClickWhatsApp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
代码示例来源:origin: stackoverflow.com
public Intent findTwitterClient() {
final String[] twitterApps = {
// package // name - nb installs (thousands)
"com.twitter.android", // official - 10 000
"com.twidroid", // twidroid - 5 000
"com.handmark.tweetcaster", // Tweecaster - 5 000
"com.thedeck.android" }; // TweetDeck - 5 000 };
Intent tweetIntent = new Intent();
tweetIntent.setType("text/plain");
final PackageManager packageManager = getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(
tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (int i = 0; i < twitterApps.length; i++) {
for (ResolveInfo resolveInfo : list) {
String p = resolveInfo.activityInfo.packageName;
if (p != null && p.startsWith(twitterApps[i])) {
tweetIntent.setPackage(p);
return tweetIntent;
}
}
}
return null;
}
代码示例来源:origin: stackoverflow.com
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_HOME);
intentToResolve.setPackage("com.android.launcher");
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null)
{
Intent intent = new Intent(intentToResolve);
intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
代码示例来源:origin: stackoverflow.com
Intent intent = context.getPackageManager().getLaunchIntentForPackage(application);
if (intent != null) {
// The application exists
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage(application);
shareIntent.putExtra(android.content.Intent.EXTRA_TITLE, title);
shareIntent.putExtra(Intent.EXTRA_TEXT, description);
// Start the specific social application
context.startActivity(shareIntent);
} else {
// The application does not exist
// Open GooglePlay or use the default system picker
}
代码示例来源:origin: hidroh/materialistic
private PendingIntent createRefreshPendingIntent(int appWidgetId) {
return PendingIntent.getBroadcast(mContext, appWidgetId,
new Intent(WidgetProvider.ACTION_REFRESH_WIDGET)
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
.setPackage(mContext.getPackageName()),
PendingIntent.FLAG_UPDATE_CURRENT);
}
代码示例来源:origin: JackyAndroid/AndroidTVLauncher
public static List<ResolveInfo> findActivitiesForPackage(Context context, String packageName) {
final PackageManager packageManager = context.getPackageManager();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mainIntent.setPackage(packageName);
final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
return apps != null ? apps : new ArrayList<ResolveInfo>();
}
代码示例来源:origin: hidroh/materialistic
private static String getPackageNameToUse(Context context) {
// packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
List<String> packagesSupportingCustomTabs = new ArrayList<>();
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")), 0);
//noinspection Convert2streamapi
for (ResolveInfo info : resolvedActivityList) {
if (pm.resolveService(new Intent()
.setAction(ACTION_CUSTOM_TABS_CONNECTION)
.setPackage(info.activityInfo.packageName), 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
return packagesSupportingCustomTabs.isEmpty() ? null : packagesSupportingCustomTabs.get(0);
}
代码示例来源:origin: stackoverflow.com
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
i.setType("text/plain");
i.setPackage("com.whatsapp"); // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);
代码示例来源:origin: ArthurHub/Android-Image-Cropper
Intent galleryIntent =
action == Intent.ACTION_GET_CONTENT
? new Intent(action)
: new Intent(action, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0);
for (ResolveInfo res : listGallery) {
Intent intent = new Intent(galleryIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(res.activityInfo.packageName);
intents.add(intent);
代码示例来源:origin: stackoverflow.com
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
代码示例来源:origin: stackoverflow.com
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
代码示例来源:origin: firebase/firebase-jobdispatcher-android
@NonNull
private Intent createSchedulerIntent(String schedulerAction) {
Intent scheduleReq = new Intent(ACTION_SCHEDULE);
scheduleReq.setPackage(BACKEND_PACKAGE);
scheduleReq.putExtra(BUNDLE_PARAM_SCHEDULER_ACTION, schedulerAction);
scheduleReq.putExtra(BUNDLE_PARAM_TOKEN, token);
scheduleReq.putExtra(INTENT_PARAM_SOURCE, JOB_DISPATCHER_SOURCE_CODE);
scheduleReq.putExtra(INTENT_PARAM_SOURCE_VERSION, JOB_DISPATCHER_SOURCE_VERSION_CODE);
return scheduleReq;
}
}
代码示例来源: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: nickbutcher/plaid
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
代码示例来源:origin: stackoverflow.com
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
内容来源于网络,如有侵权,请联系作者删除!