本文整理匯總了Java中android.content.Intent.setClassName方法的典型用法代碼示例。如果您正苦於以下問題:Java Intent.setClassName方法的具體用法?Java Intent.setClassName怎麽用?Java Intent.setClassName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Intent
的用法示例。
在下文中一共展示了Intent.setClassName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: goToInstalledAppDetails
import android.content.Intent; //導入方法依賴的package包/類
/**
* 打開已安裝應用的詳情
*/
public static void goToInstalledAppDetails(Context context, 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);
}
示例2: onClick
import android.content.Intent; //導入方法依賴的package包/類
@Override
public void onClick(View v) {
Intent intent = new Intent();
switch (v.getId()) {
case R.id.mintest:
intent.setClassName("net.fercanet.LNM", "net.fercanet.LNM.Game");
intent.putExtra("omt", true);
startActivity(intent);
break;
case R.id.training:
intent.setClassName("net.fercanet.LNM", "net.fercanet.LNM.Game");
intent.putExtra("omt", false);
startActivity(intent);
break;
case R.id.hof:
intent.setClassName("net.fercanet.LNM", "net.fercanet.LNM.Hof");
startActivity(intent);
break;
case R.id.endgame:
moveTaskToBack(true);
break;
}
}
示例3: handleInstallShortcutIntent
import android.content.Intent; //導入方法依賴的package包/類
private Intent handleInstallShortcutIntent(Intent intent) {
Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (shortcut != null) {
ComponentName component = shortcut.resolveActivity(VirtualCore.getPM());
if (component != null) {
String pkg = component.getPackageName();
Intent newShortcutIntent = new Intent();
newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
newShortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
newShortcutIntent.putExtra("_VA_|_intent_", shortcut);
newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
newShortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
intent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);
Intent.ShortcutIconResource icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (icon != null && !TextUtils.equals(icon.packageName, getHostPkg())) {
try {
Resources resources = VirtualCore.get().getResources(pkg);
if (resources != null) {
int resId = resources.getIdentifier(icon.resourceName, "drawable", pkg);
if (resId > 0) {
Drawable iconDrawable = resources.getDrawable(resId);
Bitmap newIcon = BitmapUtils.drawableToBitmap(iconDrawable);
if (newIcon != null) {
intent.removeExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newIcon);
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
return intent;
}
示例4: showInstalledAppDetails
import android.content.Intent; //導入方法依賴的package包/類
public static void showInstalledAppDetails(Context context, String packageName) {
Intent intent = new Intent();
final int apiLevel = Build.VERSION.SDK_INT;
if (apiLevel >= 9) { // above 2.3
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts(SCHEME, packageName, null);
intent.setData(uri);
} else { // below 2.3
final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
: APP_PKG_NAME_21);
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName(APP_DETAILS_PACKAGE_NAME,
APP_DETAILS_CLASS_NAME);
intent.putExtra(appPkgName, packageName);
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
示例5: setup
import android.content.Intent; //導入方法依賴的package包/類
@Before
public void setup() throws InterruptedException {
synchronized (objectLock) {
Intent remoterServiceIntent = new Intent(INTENT_AIDL_SERVICE);
remoterServiceIntent.setClassName("util.remoter.aidlservice", INTENT_AIDL_SERVICE);
mActivityRule.getActivity().startService(remoterServiceIntent);
mActivityRule.getActivity().bindService(remoterServiceIntent, serviceConnection, 0);
objectLock.wait();
Log.i(TAG, "Service connected");
}
}
示例6: ApplicationInfo
import android.content.Intent; //導入方法依賴的package包/類
/**
* 應用信息界麵
* @param activity
*/
public static void ApplicationInfo(Activity activity){
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 9) {
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
localIntent.setData(Uri.fromParts("package", activity.getPackageName(), null));
} else if (Build.VERSION.SDK_INT <= 8) {
localIntent.setAction(Intent.ACTION_VIEW);
localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
localIntent.putExtra("com.android.settings.ApplicationPkgName", activity.getPackageName());
}
activity.startActivity(localIntent);
}
示例7: isActivityExists
import android.content.Intent; //導入方法依賴的package包/類
/**
* 判斷是否存在Activity
*
* @param packageName 包名
* @param className activity全路徑類名
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isActivityExists(@NonNull final String packageName,
@NonNull final String className) {
Intent intent = new Intent();
intent.setClassName(packageName, className);
return !(Utils.getContext().getPackageManager().resolveActivity(intent, 0) == null ||
intent.resolveActivity(Utils.getContext().getPackageManager()) == null ||
Utils.getContext().getPackageManager().queryIntentActivities(intent, 0).size() == 0);
}
示例8: doBindService
import android.content.Intent; //導入方法依賴的package包/類
/**
* Bind this Activity to Android-ROS bridge service
*/
private void doBindService() {
Intent intent = new Intent();
intent.setClassName(GUESTSCIENCE_SERVICE_CONTEXT, GUESTSCIENCE_SERVICE_CLASSNAME);
bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
mTextCommStatus.setText("Comm Status: Binded");
Log.i(LOGTAG, "BINDED to SERVICE!");
}
示例9: onOptionsItemSelected
import android.content.Intent; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
switch (item.getItemId()) {
case R.id.menu_settings:
intent.setClassName(this, PreferencesActivity.class.getName());
startActivity(intent);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
示例10: bind
import android.content.Intent; //導入方法依賴的package包/類
void bind() {
Log.v(TAG, "initiating bind to authenticator type " + mAuthenticatorInfo.desc.type);
Intent intent = new Intent();
intent.setAction(AccountManager.ACTION_AUTHENTICATOR_INTENT);
intent.setClassName(mAuthenticatorInfo.serviceInfo.packageName, mAuthenticatorInfo.serviceInfo.name);
intent.putExtra("_VA_|_user_id_", mUserId);
if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
Log.d(TAG, "bind attempt failed for " + toDebugString());
onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "bind failure");
}
}
示例11: ifHuaweiAlert
import android.content.Intent; //導入方法依賴的package包/類
private void ifHuaweiAlert() {
final SharedPreferences settings = getSharedPreferences("ProtectedApps", MODE_PRIVATE);
final String saveIfSkip = "skipProtectedAppsMessage";
boolean skipMessage = settings.getBoolean(saveIfSkip, false);
if (!skipMessage) {
final SharedPreferences.Editor editor = settings.edit();
Intent intent = new Intent();
intent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");
if (isCallable(intent)) {
final AppCompatCheckBox dontShowAgain = new AppCompatCheckBox(this);
dontShowAgain.setText(R.string.Do_not_show_again);
dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
editor.putBoolean(saveIfSkip, isChecked);
editor.apply();
}
});
new AlertDialog.Builder(this)
.setTitle("Huawei Protected Apps")
.setMessage(String.format("%s requires to be enabled in 'Protected Apps' to send notifications.%n", getString(R.string.app_name)))
.setView(dontShowAgain)
.setPositiveButton("Protected Apps", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
huaweiProtectedApps();
}
})
.setNegativeButton("Cancel", null)
.show();
} else {
editor.putBoolean(saveIfSkip, true);
editor.apply();
}
}
}
示例12: run
import android.content.Intent; //導入方法依賴的package包/類
public void run() {
if (!MiPushClient.shouldUseMIUIPush(this.a) && 1 == a.a(this.a).m()) {
try {
List<PackageInfo> installedPackages = this.a.getPackageManager()
.getInstalledPackages(4);
if (installedPackages != null) {
for (PackageInfo packageInfo : installedPackages) {
ServiceInfo[] serviceInfoArr = packageInfo.services;
if (serviceInfoArr != null) {
for (ServiceInfo serviceInfo : serviceInfoArr) {
if (serviceInfo.exported && serviceInfo.enabled && ("com.xiaomi" +
".mipush.sdk.PushMessageHandler").equals(serviceInfo
.name) && !this.a.getPackageName().equals(serviceInfo
.packageName)) {
try {
Thread.sleep(((long) ((Math.random() * PathListView
.ZOOM_X2) + PathListView.NO_ZOOM)) * 1000);
} catch (InterruptedException e) {
}
Intent intent = new Intent();
intent.setClassName(serviceInfo.packageName, serviceInfo.name);
intent.setAction("com.xiaomi.mipush.sdk.WAKEUP");
this.a.startService(intent);
}
}
continue;
}
}
}
} catch (Throwable th) {
}
}
}
示例13: forceOpenGPS
import android.content.Intent; //導入方法依賴的package包/類
/**
* 強製打開GPS
*
* @param context
*/
public static void forceOpenGPS(Context context) {
// 4.0++
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
context.sendBroadcast(intent);
String provider = Settings.Secure.getString(
context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (!provider.contains("gps")) { // if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
context.sendBroadcast(poke);
}
} else {
Intent GPSIntent = new Intent();
GPSIntent.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
GPSIntent.setData(Uri.parse("custom:3"));
try {
PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
} catch (CanceledException e) {
}
}
}
示例14: onReceive
import android.content.Intent; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent == null) {
Log.e("Received a null intent.");
return;
}
// Parse manifest and pull metadata which contains client broadcast receiver class.
String receiver = LeanplumManifestHelper.parseNotificationMetadata();
// If receiver isn't found we will open up notification with default activity
if (receiver == null) {
Log.d("Custom broadcast receiver class not set, using default one.");
LeanplumPushService.openNotification(context, intent);
} else {
Log.d("Custom broadcast receiver class found, using it to handle push notifications.");
// Forward Intent to a client broadcast receiver.
Intent forwardIntent = new Intent();
// Add action to be able to differentiate between multiple intents.
forwardIntent.setAction(LeanplumPushService.LEANPLUM_NOTIFICATION);
forwardIntent.setClassName(context, receiver);
forwardIntent.putExtras(intent.getExtras());
context.sendBroadcast(forwardIntent);
}
} catch (Throwable t) {
Util.handleException(t);
}
}
示例15: isActivityExists
import android.content.Intent; //導入方法依賴的package包/類
/**
* 判斷是否存在Activity
*
* @param packageName 包名
* @param className activity全路徑類名
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isActivityExists(String packageName, String className) {
Intent intent = new Intent();
intent.setClassName(packageName, className);
PackageManager packageManager = ContextUtils.getContext()
.getPackageManager();
return !(packageManager.resolveActivity(intent, 0) == null ||
intent.resolveActivity(packageManager) == null ||
packageManager.queryIntentActivities(intent, 0)
.isEmpty());
}