本文整理汇总了Java中android.content.Intent.setComponent方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.setComponent方法的具体用法?Java Intent.setComponent怎么用?Java Intent.setComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.setComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onClick
import android.content.Intent; //导入方法依赖的package包/类
@Override
public void onClick(View view) {
int position = (int) view.getTag();
long artistId = mData.get(position).mArtistId;
String artistName = mData.get(position).mArtistName;
Intent intent = new Intent();
intent.putExtra(Constants.ARTIST_ID, artistId);
intent.putExtra(Constants.ARTIST_NAME, artistName);
intent.putExtra(Constants.WHICH_DETAIL_PAGE, Constants.ARTIST_DETAIL);
ComponentName componentName = new ComponentName(Constants.MUSIC_PACKAGE_NAME,
Constants.DETAIL_PACKAGE_NAME);
intent.setComponent(componentName);
mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(
((AppCompatActivity) mContext), new Pair<View, String>(mAlbum,
mAlbumTransitionName)).toBundle());
}
示例2: startPitService
import android.content.Intent; //导入方法依赖的package包/类
private void startPitService() {
// TODO 其实,有一种更好的办法……敬请期待
String pname = IPC.getCurrentProcessName();
int process = PluginClientHelper.getProcessInt(pname);
ComponentName cn = PluginPitService.makeComponentName(mContext, process);
if (LOG) {
LogDebug.d(TAG, "startPitService: Start " + cn);
}
Intent intent = new Intent();
intent.setComponent(cn);
try {
mContext.startService(intent);
} catch (Exception e) {
// 就算AMS出了问题(如system_server挂了,概率极低,和低配ROM有关),最多也就是服务容易被系统回收,但不能让它“不干活”
e.printStackTrace();
}
}
示例3: stopServiceToken
import android.content.Intent; //导入方法依赖的package包/类
public boolean stopServiceToken(ComponentName cn, IBinder token, int startId) throws Exception {
Service service = mTokenServices.get(token);
if (service != null) {
Integer lastId = mServiceTaskIds.get(token);
if (lastId == null) {
return false;
}
if (startId != lastId) {
return false;
}
Intent intent = new Intent();
intent.setComponent(cn);
ServiceInfo info = PluginManager.getInstance().resolveServiceInfo(intent, 0);
if (info != null) {
handleOnUnbindOne(intent);
handleOnDestroyOne(info);
return true;
}
}
return false;
}
示例4: createExplicitFromImplicitIntent
import android.content.Intent; //导入方法依赖的package包/类
/***
* Android L (lollipop, API 21) introduced a new problem when trying to invoke implicit intent,
* "java.lang.IllegalArgumentException: Service Intent must be explicit"
* <p>
* If you are using an implicit intent, and know only 1 target would answer this intent,
* This method will help you turn the implicit intent into the explicit form.
* <p>
* Inspired from SO answer: http://stackoverflow.com/a/26318757/1446466
*
* @param context
* @param implicitIntent - The original implicit intent
* @return Explicit Intent created from the implicit original intent
*/
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
// Retrieve all services that can match the given intent
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);
// Make sure only one match was found
if (resolveInfo == null || resolveInfo.size() != 1) {
return null;
}
// Get component info and create ComponentName
ResolveInfo serviceInfo = resolveInfo.get(0);
String packageName = serviceInfo.serviceInfo.packageName;
String className = serviceInfo.serviceInfo.name;
ComponentName component = new ComponentName(packageName, className);
// Create a new intent. Use the old one for extras and such reuse
Intent explicitIntent = new Intent(implicitIntent);
// Set the component to be explicit
explicitIntent.setComponent(component);
return explicitIntent;
}
示例5: a
import android.content.Intent; //导入方法依赖的package包/类
private void a(Context context) {
if (!(g.a(context).b() || !a.a(context).i() || a.a(context).n())) {
try {
Intent intent = new Intent();
intent.setComponent(new ComponentName(context, "com.xiaomi.push.service" +
".XMPushService"));
intent.setAction("com.xiaomi.push.network_status_changed");
context.startService(intent);
} catch (Throwable e) {
b.a(e);
}
}
if (d.d(context) && g.a(context).f()) {
g.a(context).c();
}
}
示例6: intentForPosition
import android.content.Intent; //导入方法依赖的package包/类
public Intent intentForPosition(int position) {
DisplayResolveInfo dri = mList.get(position);
Intent intent = new Intent(dri.origIntent != null
? dri.origIntent : mIntent);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
| Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
ActivityInfo ai = dri.ri.activityInfo;
intent.setComponent(new ComponentName(
ai.applicationInfo.packageName, ai.name));
return intent;
}
示例7: openAppActivity
import android.content.Intent; //导入方法依赖的package包/类
public static boolean openAppActivity(Context context,
String packageName,
String activityName) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(packageName, activityName);
intent.setComponent(cn);
try {
context.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
return false;
}
}
示例8: startActivityForProfile
import android.content.Intent; //导入方法依赖的package包/类
public void startActivityForProfile(ComponentName component, UserHandleCompat user,
Rect sourceBounds, Bundle opts) {
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
launchIntent.setComponent(component);
launchIntent.setSourceBounds(sourceBounds);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(launchIntent, opts);
}
示例9: requestShowKeyboardShortcuts
import android.content.Intent; //导入方法依赖的package包/类
/**
* Request the Keyboard Shortcuts screen to show up. This will trigger
* {@link #onProvideKeyboardShortcuts} to retrieve the shortcuts for the foreground activity.
*/
public final void requestShowKeyboardShortcuts() {
Intent intent = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS);
intent.setComponent(new ComponentName(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME,
KEYBOARD_SHORTCUTS_RECEIVER_CLASS_NAME));
sendBroadcast(intent);
}
示例10: openSettings
import android.content.Intent; //导入方法依赖的package包/类
public static void openSettings(Activity context, String action) {
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.android.settings", action);
intent.setComponent(comp);
intent.setAction("android.intent.action.VIEW");
context.startActivityForResult(intent, 0);
}
示例11: onListItemClick
import android.content.Intent; //导入方法依赖的package包/类
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Map<String, String> item = (Map<String, String>)l.getItemAtPosition(position);
String className = item.get("class");
Intent intent = new Intent();
intent.setComponent(new ComponentName(this, className));
intent.putExtra("name", item.get("name"));
intent.putExtra("data", item.get("data"));
startActivity(intent);
}
示例12: getComponentNameIntent
import android.content.Intent; //导入方法依赖的package包/类
/**
* 获取其他应用的Intent
*
* @param packageName 包名
* @param className 全类名
* @return 意图
*/
public static Intent getComponentNameIntent(String packageName, String className, Bundle bundle) {
Intent intent = new Intent(Intent.ACTION_VIEW);
if (bundle != null)
intent.putExtras(bundle);
ComponentName cn = new ComponentName(packageName, className);
intent.setComponent(cn);
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
示例13: openSetting
import android.content.Intent; //导入方法依赖的package包/类
/**
* 打开网络设置界面
*/
public static void openSetting(Activity activity) {
Intent intent = new Intent("/");
ComponentName cm = new ComponentName("com.android.settings",
"com.android.settings.WirelessSettings");
intent.setComponent(cm);
intent.setAction("android.intent.action.VIEW");
activity.startActivityForResult(intent, 0);
}
示例14: openAppActivity
import android.content.Intent; //导入方法依赖的package包/类
public static boolean openAppActivity(Context context, String packageName,
String activityName) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ComponentName cn = new ComponentName(packageName, activityName);
intent.setComponent(cn);
try {
context.startActivity(intent);
return true;
} catch (Exception e) {
return false;
}
}
示例15: createShortcutIntent
import android.content.Intent; //导入方法依赖的package包/类
private Intent createShortcutIntent(String activity, String shortcutName, ShortcutIconResource shortcutIcon, String action) {
Intent shortcutIntent = new Intent();
shortcutIntent.setComponent(new ComponentName(this.getPackageName(), activity));
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcon);
intent.setAction(action);
return intent;
}