本文整理汇总了Java中android.content.Intent.setPackage方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.setPackage方法的具体用法?Java Intent.setPackage怎么用?Java Intent.setPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.setPackage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: b
import android.content.Intent; //导入方法依赖的package包/类
private static a b(Context context) throws Exception {
try {
context.getPackageManager().getPackageInfo("com.android.vending", 0);
ServiceConnection bVar = new b();
Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
intent.setPackage("com.google.android.gms");
if (context.bindService(intent, bVar, 1)) {
try {
c cVar = new c(bVar.a());
a aVar = new a(cVar.a(), cVar.a(true));
context.unbindService(bVar);
return aVar;
} catch (Exception e) {
throw e;
} catch (Throwable th) {
context.unbindService(bVar);
}
} else {
throw new IOException("Google Play connection failed");
}
} catch (Exception e2) {
throw e2;
}
}
示例2: onClick
import android.content.Intent; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.rl_grade:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri;
if (checkMarketInstall()) {
uri = Uri.parse("market://details?id=com.lingju.assistant");
intent.setPackage(pkgs[0]);
} else {
uri = Uri.parse("http://android.myapp.com/myapp/detail.htm?apkName=com.lingju.assistant");
}
intent.setData(uri);
startActivity(intent);
break;
case R.id.rl_feedback:
startActivity(new Intent(this, FeedbackActivity.class));
break;
case R.id.rl_about:
startActivity(new Intent(this, AboutLJActivity.class));
break;
case R.id.rl_connect:
startActivity(new Intent(this, ConnectUsActivity.class));
break;
}
goInto();
}
示例3: initOpenCV
import android.content.Intent; //导入方法依赖的package包/类
public static boolean initOpenCV(String Version, final Context AppContext,
final LoaderCallbackInterface Callback)
{
AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback);
Intent intent = new Intent("org.opencv.engine.BIND");
intent.setPackage("org.opencv.engine");
if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE))
{
return true;
}
else
{
AppContext.unbindService(helper.mServiceConnection);
InstallService(AppContext, Callback);
return false;
}
}
示例4: getDetailActivityStartIntent
import android.content.Intent; //导入方法依赖的package包/类
@NonNull
private static Intent getDetailActivityStartIntent(Context context,
int position,
PhotoViewHolder holder) {
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://multi-feature.instantappsample.com/detail/" + position));
intent.setPackage(context.getPackageName());
intent.addCategory(Intent.CATEGORY_BROWSABLE);
TextView author =
holder.itemView.findViewById(com.example.android.unsplash.base.R.id.author);
// Working around unboxing issues with multiple dex files on platforms prior to N.
intent.putExtra(IntentUtil.SELECTED_ITEM_POSITION, position);
intent.putExtra(IntentUtil.FONT_SIZE, author.getTextSize());
intent.putExtra(IntentUtil.PADDING,
new Rect(author.getPaddingLeft(),
author.getPaddingTop(),
author.getPaddingRight(),
author.getPaddingBottom()));
intent.putExtra(IntentUtil.TEXT_COLOR, author.getCurrentTextColor());
return intent;
}
示例5: openApplicationMarket
import android.content.Intent; //导入方法依赖的package包/类
public static void openApplicationMarket(String appPackageName, String marketPackageName,
Context context) {
try {
String url = "market://details?id=" + appPackageName;
Intent localIntent = new Intent(Intent.ACTION_VIEW);
if (marketPackageName != null) {
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
localIntent.setPackage(marketPackageName);
}
openLink(context, localIntent, url, true);
} catch (Exception e) {
e.printStackTrace();
openApplicationMarketForLinkBySystem(appPackageName, context);
}
}
示例6: launch
import android.content.Intent; //导入方法依赖的package包/类
private void launch(){
String url = AppConfig.getLaunchUrl();
Intent intent = new Intent(Intent.ACTION_VIEW);
String scheme = Uri.parse(url).getScheme();
StringBuilder builder = new StringBuilder();
if (TextUtils.equals("file", scheme)) {
intent.putExtra("isLocal", true);
} else if (!TextUtils.equals("http", scheme) && !TextUtils.equals("https", scheme)) {
builder.append("http:");
}
builder.append(url);
Uri uri = Uri.parse(builder.toString());
intent.setData(uri);
intent.addCategory("com.taobao.android.intent.category.WEEX");
intent.setPackage(getPackageName());
startActivity(intent);
finish();
}
示例7: connectService
import android.content.Intent; //导入方法依赖的package包/类
/**
* Connect to sip service by flagging itself as the component to consider as outgoing activity
*/
private void connectService() {
PreferencesProviderWrapper prefsWrapper = new PreferencesProviderWrapper(this);
Intent sipService = new Intent(SipManager.INTENT_SIP_SERVICE);
// Optional, but here we bundle so just ensure we are using csipsimple package
sipService.setPackage(getPackageName());
if (prefsWrapper.isValidConnectionForOutgoing()) {
sipService.putExtra(SipManager.EXTRA_OUTGOING_ACTIVITY, getComponentName());
startService(sipService);
}
bindService(sipService, connection, Context.BIND_AUTO_CREATE);
}
示例8: d
import android.content.Intent; //导入方法依赖的package包/类
private static boolean d(Context context, String str, String str2) {
PackageManager packageManager = context.getPackageManager();
Intent intent = new Intent(str2);
intent.setPackage(context.getPackageName());
for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent, 0)) {
ActivityInfo activityInfo = resolveInfo.activityInfo;
if (activityInfo != null && activityInfo.name.equals(str)) {
return true;
}
}
return false;
}
示例9: isUseClientToShare
import android.content.Intent; //导入方法依赖的package包/类
/** 判断指定平台是否只能使用客户端分享 */
final boolean isUseClientToShare(Platform platform) {
String name = platform.getName();
if ("Wechat".equals(name) || "WechatMoments".equals(name)
|| "WechatFavorite".equals(name) || "ShortMessage".equals(name)
|| "Email".equals(name) || "GooglePlus".equals(name)
|| "QQ".equals(name) || "Pinterest".equals(name)
|| "Instagram".equals(name) || "Yixin".equals(name)
|| "YixinMoments".equals(name) || "QZone".equals(name)
|| "Mingdao".equals(name) || "Line".equals(name)
|| "KakaoStory".equals(name) || "KakaoTalk".equals(name)
|| "Bluetooth".equals(name) || "WhatsApp".equals(name)
|| "BaiduTieba".equals(name) || "Laiwang".equals(name)
|| "LaiwangMoments".equals(name) || "Alipay".equals(name)
|| "FacebookMessenger".equals(name)
) {
return true;
} else if ("Evernote".equals(name)) {
if ("true".equals(platform.getDevinfo("ShareByAppClient"))) {
return true;
}
} else if ("SinaWeibo".equals(name)) {
if ("true".equals(platform.getDevinfo("ShareByAppClient"))) {
Intent test = new Intent(Intent.ACTION_SEND);
test.setPackage("com.sina.weibo");
test.setType("image/*");
ResolveInfo ri = platform.getContext().getPackageManager().resolveActivity(test, 0);
return (ri != null);
}
}
return false;
}
示例10: initiateScan
import android.content.Intent; //导入方法依赖的package包/类
/**
* Initiates a scan, using the specified camera, only for a certain set of barcode types, given as strings corresponding
* to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants
* like {@link #PRODUCT_CODE_TYPES} for example.
*
* @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
* @param cameraId camera ID of the camera to use. A negative value means "no preference".
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
* if a prompt was needed, or null otherwise
*/
public final AlertDialog initiateScan(Collection<String> desiredBarcodeFormats, int cameraId) {
Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
// check which types of codes to scan for
if (desiredBarcodeFormats != null) {
// set the desired barcode types
StringBuilder joinedByComma = new StringBuilder();
for (String format : desiredBarcodeFormats) {
if (joinedByComma.length() > 0) {
joinedByComma.append(',');
}
joinedByComma.append(format);
}
intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
}
// check requested camera ID
if (cameraId >= 0) {
intentScan.putExtra("SCAN_CAMERA_ID", cameraId);
}
String targetAppPackage = findTargetAppPackage(intentScan);
if (targetAppPackage == null) {
return showDownloadDialog();
}
intentScan.setPackage(targetAppPackage);
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentScan.addFlags(FLAG_NEW_DOC);
attachMoreExtras(intentScan);
startActivityForResult(intentScan, REQUEST_CODE);
return null;
}
示例11: Init
import android.content.Intent; //导入方法依赖的package包/类
public void Init(Context context, String mainPackage, InitListener listener) {
this.context = context;
this.listener = listener;
//绑定服务
Intent intent = new Intent();
intent.setAction(RobotService.class.getName());
intent.setPackage(mainPackage);
context.bindService(intent, connection, context.BIND_AUTO_CREATE);
}
示例12: getSkipNextAction
import android.content.Intent; //导入方法依赖的package包/类
/**
* Returns the {@link NotificationCompat.Action} for skipping to the next item in the queue. If
* we are already at the end of the queue, we show a dimmed version of the icon for this action
* and won't send any {@link PendingIntent}
*/
protected NotificationCompat.Action getSkipNextAction() {
PendingIntent pendingIntent = null;
int iconResourceId = R.drawable.ic_notification_skip_next_semi_48dp;
if (mHasNext) {
Intent intent = new Intent(this, VideoIntentReceiver.class);
intent.setAction(ACTION_PLAY_NEXT);
intent.setPackage(getPackageName());
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
iconResourceId = R.drawable.ic_notification_skip_next_48dp;
}
return new NotificationCompat.Action.Builder(iconResourceId,
getString(R.string.ccl_skip_next), pendingIntent).build();
}
示例13: openRestaurantDirection
import android.content.Intent; //导入方法依赖的package包/类
@OnClick(R.id.tvDirection)
void openRestaurantDirection(View view) {
if (business != null) {
// Create a Uri from an intent string. Use the result to create an Intent.
Uri gmmIntentUri = Uri.parse(String.format("google.streetview:cbll=%1$f,%2%f", business.getLatitude(), business.getLongitude()));
// Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
// Make the Intent explicit by setting the Google Maps package
mapIntent.setPackage("com.google.android.apps.maps");
// Attempt to start an activity that can handle the Intent
startActivity(mapIntent);
}
}
示例14: sendCommandMessageBroadcast
import android.content.Intent; //导入方法依赖的package包/类
public static void sendCommandMessageBroadcast(Context context, MiPushCommandMessage
miPushCommandMessage) {
Intent intent = new Intent("com.xiaomi.mipush.RECEIVE_MESSAGE");
intent.setPackage(context.getPackageName());
intent.putExtra(MESSAGE_TYPE, 3);
intent.putExtra(KEY_COMMAND, miPushCommandMessage);
new PushServiceReceiver().onReceive(context, intent);
}
示例15: getPackageNameToUse
import android.content.Intent; //导入方法依赖的package包/类
/**
* Goes through all apps that handle VIEW intents and have a warmup service. Picks
* the one chosen by the user if there is one, otherwise makes a best effort to return a
* valid package name.
* <p>
* This is <strong>not</strong> threadsafe.
*
* @param context
* {@link Context} to use for accessing {@link PackageManager}.
* @return The package name recommended to use for connecting to custom tabs related components.
*/
static String getPackageNameToUse(Context context) {
if (sPackageNameToUse != null) return sPackageNameToUse;
PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}
// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
sPackageNameToUse = null;
} else if (packagesSupportingCustomTabs.size() == 1) {
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
&& !hasSpecializedHandlerIntents(context, activityIntent)
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
sPackageNameToUse = defaultViewHandlerPackageName;
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
sPackageNameToUse = STABLE_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
sPackageNameToUse = BETA_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
}
return sPackageNameToUse;
}