當前位置: 首頁>>代碼示例>>Java>>正文


Java Activity.getSystemService方法代碼示例

本文整理匯總了Java中android.app.Activity.getSystemService方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.getSystemService方法的具體用法?Java Activity.getSystemService怎麽用?Java Activity.getSystemService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.getSystemService方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hideSoftKeyboard

import android.app.Activity; //導入方法依賴的package包/類
public static void hideSoftKeyboard(Activity act) {
    InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
    if(inputMethodManager != null ) {
        View localView = act.getCurrentFocus();
        if(localView != null && localView.getWindowToken() != null ) {
            IBinder windowToken = localView.getWindowToken();
            inputMethodManager.hideSoftInputFromWindow(windowToken, 0);
        }
    }
}
 
開發者ID:Louis19910615,項目名稱:youkes_browser,代碼行數:11,代碼來源:SoftKeyboardUtil.java

示例2: hasNetworkConnection

import android.app.Activity; //導入方法依賴的package包/類
/**
 * Validate the network connection. Supports checking for WiFi only when
 * this settings has been set to true.
 *
 * @param activity Activity
 * @return Has network connection
 */
public static boolean hasNetworkConnection(Activity activity) {
    ConnectivityManager connMgr = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo == null)
        return false;

    if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(Settings.PREF_WIFI_ONLY, false))
        return networkInfo.getType() == ConnectivityManager.TYPE_WIFI;

    return networkInfo.isConnected();
}
 
開發者ID:linklux,項目名稱:android-schedules,代碼行數:20,代碼來源:NetUtil.java

示例3: hideKeyboard

import android.app.Activity; //導入方法依賴的package包/類
/**
 * Hide keyboard, the view is automatically detected from the activity
 *
 * @param a Activity
 */
public static void hideKeyboard(Activity a) {
    // Check if no view has focus:
    try {
        View view = a.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    } catch (Throwable e) {
        //Not the end of the world. Keyborad didn't hide, that's it.
        e.printStackTrace();
    }
}
 
開發者ID:yajnesh,項目名稱:AndroidGeneralUtils,代碼行數:19,代碼來源:ViewUtil.java

示例4: copyToClipboard

import android.app.Activity; //導入方法依賴的package包/類
public static void copyToClipboard(Activity activity, String textToCopy) {
    ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("Remindy text", textToCopy);
    clipboard.setPrimaryClip(clip);

    String toastMsg = String.format(Locale.getDefault(), activity.getResources().getString(R.string.dialog_text_attachment_text_copied_clipboard), textToCopy);
    Toast.makeText(activity, toastMsg, Toast.LENGTH_SHORT).show();
}
 
開發者ID:abicelis,項目名稱:Remindy,代碼行數:9,代碼來源:ClipboardUtil.java

示例5: ControllerDataProvider

import android.app.Activity; //導入方法依賴的package包/類
public ControllerDataProvider(Activity activity, int sensorRefreshSpeed) {
    fusedEulerAngles = new float[3];
    fusedQuaternion = new Quaternion();
    fusedQuaternion.loadIdentityQuat();
    zeroQuaternion = new Quaternion();
    zeroQuaternion.loadIdentityQuat();
    finalFusedQuaternion = new Quaternion();
    fusedQuaternion.loadIdentityQuat();
    sensorManager = (SensorManager) activity.getSystemService(SENSOR_SERVICE);
    currentOrientationProvider = new ImprovedOrientationSensor1Provider(sensorManager, sensorRefreshSpeed);
}
 
開發者ID:peter10110,項目名稱:Android-SteamVR-controller,代碼行數:12,代碼來源:ControllerDataProvider.java

示例6: hideSoftInput

import android.app.Activity; //導入方法依賴的package包/類
public static boolean hideSoftInput(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        return imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }
    return false;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:IMEUtils.java

示例7: showKeyboard

import android.app.Activity; //導入方法依賴的package包/類
/**
 * 顯示軟鍵盤
 * @param activity
 */
public static void showKeyboard(Activity activity) {
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!imm.isActive()) {
            imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
        }
    }
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:13,代碼來源:CommonUtils.java

示例8: hideSoftInput

import android.app.Activity; //導入方法依賴的package包/類
/**
 * @param mActivity
 * @param token
 */
private void hideSoftInput(Activity mActivity, IBinder token) {
    if (token != null) {
        InputMethodManager im = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
開發者ID:devzwy,項目名稱:KUtils,代碼行數:11,代碼來源:HideUtil.java

示例9: NoNetWorkNotice

import android.app.Activity; //導入方法依賴的package包/類
private NoNetWorkNotice(final Activity context){

        wdm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

        mView = View.inflate(context, R.layout.no_net_worke_layout , null);
        mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Settings.ACTION_SETTINGS);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.getApplicationContext().startActivity(intent);


            }
        });
        //設置LayoutParams(全局變量)相關參數
        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_APPLICATION,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.TRANSLUCENT);

        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;


    }
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:28,代碼來源:NoNetWorkNotice.java

示例10: getUDID

import android.app.Activity; //導入方法依賴的package包/類
@SuppressLint("HardwareIds")
public static String getUDID(Activity activity) {
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        String tmDevice = "" + (tm != null ? tm.getDeviceId() : null);
        String tmSerial = "" + (tm != null ? tm.getSimSerialNumber() : null);
        String androidId = "" + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
        UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

        return deviceUuid.toString();
    }
    else{
        return Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
    }
}
 
開發者ID:afiqiqmal,項目名稱:MVP-Android,代碼行數:16,代碼來源:DeviceUtils.java

示例11: hideSoftInput

import android.app.Activity; //導入方法依賴的package包/類
/**
 * 多種隱藏軟件盤方法的其中一種
 *
 * @param token
 */
public static void hideSoftInput(Activity activity, IBinder token) {
    if (token != null) {
        InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(token,
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
開發者ID:zhou-you,項目名稱:RxEasyHttp,代碼行數:13,代碼來源:AppTools.java

示例12: getUDID

import android.app.Activity; //導入方法依賴的package包/類
@SuppressLint("HardwareIds")
public static String getUDID(Activity activity) {
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        String tmDevice = "" + tm.getDeviceId();
        String tmSerial = "" + tm.getSimSerialNumber();
        String androidId = "" + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
        UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

        return deviceUuid.toString();
    }
    else{
        return Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
    }
}
 
開發者ID:afiqiqmal,項目名稱:My-Android-Base-Code,代碼行數:16,代碼來源:DeviceUtils.java

示例13: hideKeyboard

import android.app.Activity; //導入方法依賴的package包/類
/**
 * Hides the onscreen keyboard if it is visisble
 */
public static void hideKeyboard(Activity activity) {
	// Check if no view has focus:
	View view = activity.getCurrentFocus();
	if (view != null) {
		InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
	}
}
 
開發者ID:SebastianRask,項目名稱:Pocket-Plays-for-Twitch,代碼行數:12,代碼來源:Service.java

示例14: showKeyboard

import android.app.Activity; //導入方法依賴的package包/類
/**
 * Show the soft keyboard.
 * @param activity the current activity
 */
public static void showKeyboard(@Nullable Activity activity) {
    if (activity == null) return;
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
 
開發者ID:TryGhost,項目名稱:Ghost-Android,代碼行數:10,代碼來源:KeyboardUtils.java

示例15: lockOrientation

import android.app.Activity; //導入方法依賴的package包/類
public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:42,代碼來源:AndroidUtilities.java


注:本文中的android.app.Activity.getSystemService方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。