Java Code Examples for android.content.Intent#setClassName()

The following examples show how to use android.content.Intent#setClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntentUtil.java    From BaseProject with MIT License 6 votes vote down vote up
/**
 * 跳转到系统程序详细信息界面
 */
@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);
}
 
Example 2
Source File: LinkingBeaconManager.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
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);
        }
    }
 
Example 3
Source File: PermissionPageUtils.java    From ToDoList with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: MqttCallbackHandler.java    From Sparkplug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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);
    }
}
 
Example 5
Source File: SettingsCompat.java    From settingscompat with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: InitActivity.java    From Vitamio with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example 7
Source File: RemoteConnection.java    From CC with Apache License 2.0 6 votes vote down vote up
/**
 * 检测组件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;
    }
}
 
Example 8
Source File: SocialApiIml.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: MiuiUtils.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 小米 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!");
  }
}
 
Example 10
Source File: SettingsCompat.java    From settingscompat with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: BaseApi.java    From letv with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: BrowserUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 直接启动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);
}
 
Example 13
Source File: MainActivity.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent();
    intent.setClassName("com.android.settings",
            "com.android.settings.Settings$AppOpsSummaryActivity");
    startActivity(intent);

    return true;
}
 
Example 14
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 15
Source File: IntentSubjectTest.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Test
public void hasComponentClass() {
  Intent intent = new Intent();
  intent.setClassName(getApplicationContext(), "Foo");
  assertThat(intent).hasComponentClass("Foo");
}
 
Example 16
Source File: ExternalNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: ServerController.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
ServerController(Context context) {
    this.context = context;
    intent = new Intent();
    intent.setClassName(serverServicePackageName, serverServiceClassName);
}
 
Example 18
Source File: ResultHandler.java    From reacteu-app with MIT License 4 votes vote down vote up
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);
}
 
Example 19
Source File: Tool.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** 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);
}