下面列出了android.content.Intent#setClassName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 跳转到系统程序详细信息界面
*/
@SuppressLint("ObsoleteSdkInt")
public static void startInstalledAppDetails(
@NonNull Context context, @NonNull String packageName) {
Intent intent = new Intent();
int sdkVersion = Build.VERSION.SDK_INT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", packageName, null));
} else {
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
intent.putExtra((sdkVersion == Build.VERSION_CODES.FROYO ?
"pkg" : "com.android.settings.ApplicationPkgName"),
packageName);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
/**
* @see org.eclipse.paho.client.mqttv3.MqttCallback#connectionLost(java.lang.Throwable)
*/
@Override
public void connectionLost(Throwable cause) {
if (cause != null) {
Log.d(TAG, "Connection Lost: " + cause.getMessage());
Connection c = Connections.getInstance(context).getConnection(clientHandle);
c.addAction("Connection Lost");
c.changeConnectionStatus(Connection.ConnectionStatus.DISCONNECTED);
String message = context.getString(R.string.connection_lost, c.getId(), c.getHostName());
//build intent
Intent intent = new Intent();
intent.setClassName(context, activityClass);
intent.putExtra("handle", clientHandle);
//notify the user
Notify.notifcation(context, message, intent, R.string.notifyTitle_connectionLost);
}
}
public void handleMessage(Message msg) {
InitActivity ctx = (InitActivity) mContext.get();
switch (msg.what) {
case 0:
ctx.mPD.dismiss();
Intent src = ctx.getIntent();
Intent i = new Intent();
i.setClassName(src.getStringExtra("package"), src.getStringExtra("className"));
i.setData(src.getData());
i.putExtras(src);
i.putExtra(FROM_ME, true);
ctx.startActivity(i);
ctx.finish();
break;
}
}
/**
* 检测组件App是否存在,并顺便唤醒App
* @param packageName app的包名
* @return 成功与否(true:app存在,false: 不存在)
*/
public static boolean tryWakeup(String packageName) {
long time = SystemClock.elapsedRealtime();
Intent intent = new Intent();
intent.setClassName(packageName, RemoteConnectionActivity.class.getName());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
CC.getApplication().startActivity(intent);
CC.log("wakeup remote app '%s' success. time=%d", packageName, (SystemClock.elapsedRealtime() - time));
return true;
} catch(Exception e) {
CCUtil.printStackTrace(e);
CC.log("wakeup remote app '%s' failed. time=%d", packageName, (SystemClock.elapsedRealtime() - time));
return false;
}
}
private static boolean manageDrawOverlaysForEmui(Context context) {
Intent intent = new Intent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
intent.setClassName(HUAWEI_PACKAGE, "com.huawei.systemmanager.addviewmonitor.AddViewMonitorActivity");
if (startSafely(context, intent)) {
return true;
}
}
// Huawei Honor P6|4.4.4|3.0
intent.setClassName(HUAWEI_PACKAGE, "com.huawei.notificationmanager.ui.NotificationManagmentActivity");
intent.putExtra("showTabsNumber", 1);
if (startSafely(context, intent)) {
return true;
}
intent.setClassName(HUAWEI_PACKAGE, "com.huawei.permissionmanager.ui.MainActivity");
if (startSafely(context, intent)) {
return true;
}
return false;
}
private void goXiaoMiMainager() {
String rom = getMiuiVersion();
Log.i(TAG,"goMiaoMiMainager --- rom : "+rom);
Intent intent=new Intent();
if ("V6".equals(rom) || "V7".equals(rom)) {
intent.setAction("miui.intent.action.APP_PERM_EDITOR");
intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
intent.putExtra("extra_pkgname", packageName);
} else if ("V8".equals(rom) || "V9".equals(rom)) {
intent.setAction("miui.intent.action.APP_PERM_EDITOR");
intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
intent.putExtra("extra_pkgname", packageName);
} else {
goIntentSetting();
}
mContext.startActivity(intent);
}
private void startBeaconScanInternal(final LinkingBeaconUtil.ScanMode scanMode) {
if (BuildConfig.DEBUG) {
Log.i(TAG, "LinkingBeaconManager#startBeaconScan");
}
Intent intent = new Intent();
intent.setClassName(LinkingBeaconUtil.LINKING_PACKAGE_NAME, LinkingBeaconUtil.BEACON_SERVICE_NAME);
intent.setAction(mContext.getPackageName() + LinkingBeaconUtil.ACTION_START_BEACON_SCAN);
// intent.putExtra(mContext.getPackageName() + LinkingBeaconUtil.EXTRA_SERVICE_ID, new int[] {0, 1, 2, 3, 4, 5, 15});
if (scanMode != null) {
intent.putExtra(mContext.getPackageName() + LinkingBeaconUtil.EXTRA_SCAN_MODE, scanMode.getValue());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mContext.startForegroundService(intent);
} else {
mContext.startService(intent);
}
}
protected void a(Activity activity, String s, IUiListener iuilistener)
{
Intent intent = new Intent();
intent.setClassName(Constants.PACKAGE_QZONE, "com.tencent.open.agent.AgentActivity");
intent.putExtra("key_action", "action_check");
Bundle bundle = new Bundle();
bundle.putString("apiName", s);
intent.putExtra("key_params", bundle);
mActivityIntent = intent;
startAssitActivity(activity, iuilistener);
}
@Override
public Intent getLaunchIntentForPackage(String packageName) {
// First see if the package has an INFO activity; the existence of
// such an activity is implied to be the desired front-door for the
// overall package (such as if it has multiple launcher entries).
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_INFO);
intentToResolve.setPackage(packageName);
List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
// Otherwise, try to find a main launcher activity.
if (ris == null || ris.size() <= 0) {
// reuse the intent instance
intentToResolve.removeCategory(Intent.CATEGORY_INFO);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage(packageName);
ris = queryIntentActivities(intentToResolve, 0);
}
if (ris == null || ris.size() <= 0) {
return null;
}
Intent intent = new Intent(intentToResolve);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(ris.get(0).activityInfo.packageName,
ris.get(0).activityInfo.name);
return intent;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent();
intent.setClassName("com.android.settings",
"com.android.settings.Settings$AppOpsSummaryActivity");
startActivity(intent);
return true;
}
/**
* 直接启动Opera,用于验证测试。
*/
public static void showOperaBrowser(Context context, String visitUrl) {
Intent intent = new Intent();
intent.setClassName("com.opera.mini.android",
"com.opera.mini.android.Browser");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
context.startActivity(intent);
}
protected Intent getAgentIntentWithTarget(String str) {
Intent intent = new Intent();
Intent targetActivityIntent = getTargetActivityIntent(str);
if (targetActivityIntent == null || targetActivityIntent.getComponent() == null) {
return null;
}
intent.setClassName(targetActivityIntent.getComponent().getPackageName(), ACTIVITY_AGENT);
return intent;
}
private static boolean manageDrawOverlaysForQihu(Context context) {
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.Settings$OverlaySettingsActivity");
if (startSafely(context, intent)) {
return true;
}
intent.setClassName("com.qihoo360.mobilesafe", "com.qihoo360.mobilesafe.ui.index.AppEnterActivity");
return startSafely(context, intent);
}
/**
* 小米 V6 版本 ROM权限申请
*/
public static void goToMiuiPermissionActivity_V6(Context context) {
Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
intent.setClassName("com.miui.securitycenter",
"com.miui.permcenter.permissions.AppPermissionsEditorActivity");
intent.putExtra("extra_pkgname", context.getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (isIntentAvailable(intent, context)) {
context.startActivity(intent);
} else {
Log.e(TAG, "Intent is not available!");
}
}
/** Sets the appropriate class for {@link AndroidListener} service intents. */
static Intent setAndroidListenerClass(Context context, Intent intent) {
String simpleListenerClass = new AndroidTiclManifest(context).getListenerServiceClass();
return intent.setClassName(context, simpleListenerClass);
}
public static Intent getIntentFromApp(App app) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(app.getPackageName(), app.getClassName());
return intent;
}
final void searchBookContents(String isbnOrUrl) {
Intent intent = new Intent(Intents.SearchBookContents.ACTION);
intent.setClassName(activity, SearchBookContentsActivity.class.getName());
putExtra(intent, Intents.SearchBookContents.ISBN, isbnOrUrl);
launchIntent(intent);
}
@Test
public void hasComponentClass() {
Intent intent = new Intent();
intent.setClassName(getApplicationContext(), "Foo");
assertThat(intent).hasComponentClass("Foo");
}
/**
* Retrieve the best activity for the given intent. If a default activity is provided,
* choose the default one. Otherwise, return the Intent picker if there are more than one
* capable activities. If the intent is pdf type, return the platform pdf viewer if
* it is available so user don't need to choose it from Intent picker.
*
* Note this function is slow on Android versions less than Lollipop.
*
* @param context Context of the app.
* @param intent Intent to open.
* @param allowSelfOpen Whether chrome itself is allowed to open the intent.
* @return true if the intent can be resolved, or false otherwise.
*/
public static boolean resolveIntent(Context context, Intent intent, boolean allowSelfOpen) {
try {
boolean activityResolved = false;
ResolveInfo info = context.getPackageManager().resolveActivity(intent, 0);
if (info != null) {
final String packageName = context.getPackageName();
if (info.match != 0) {
// There is a default activity for this intent, use that.
if (allowSelfOpen || !packageName.equals(info.activityInfo.packageName)) {
activityResolved = true;
}
} else {
List<ResolveInfo> handlers = context.getPackageManager().queryIntentActivities(
intent, PackageManager.MATCH_DEFAULT_ONLY);
if (handlers != null && !handlers.isEmpty()) {
activityResolved = true;
boolean canSelfOpen = false;
boolean hasPdfViewer = false;
for (ResolveInfo resolveInfo : handlers) {
String pName = resolveInfo.activityInfo.packageName;
if (packageName.equals(pName)) {
canSelfOpen = true;
} else if (PDF_VIEWER.equals(pName)) {
if (isPdfIntent(intent)) {
intent.setClassName(pName, resolveInfo.activityInfo.name);
Uri referrer = new Uri.Builder().scheme(
IntentHandler.ANDROID_APP_REFERRER_SCHEME).authority(
packageName).build();
intent.putExtra(Intent.EXTRA_REFERRER, referrer);
hasPdfViewer = true;
break;
}
}
}
if ((canSelfOpen && !allowSelfOpen) && !hasPdfViewer) {
activityResolved = false;
}
}
}
}
return activityResolved;
} catch (RuntimeException e) {
IntentUtils.logTransactionTooLargeOrRethrow(e, intent);
}
return false;
}
ServerController(Context context) {
this.context = context;
intent = new Intent();
intent.setClassName(serverServicePackageName, serverServiceClassName);
}