'JAVA/android_studio'에 해당되는 글 47건
- 2024.06.29 :: WiFiManagerTest
- 2024.03.26 :: ListView 의 아이템으로 두가지 이상의 View사용하기
- 2024.03.14 :: 안드로이드 벡터 패스(Vector Path) 그리기
- 2024.03.14 :: Listview의 글자 크기 변경
- 2024.02.18 :: Bluetooth search
- 2023.10.15 :: +-> Fragment , getActivity()
WiFiManagerTest
안드로이드 버젼 7.0 지원하기 위한 버젼임.
- MainActivity.java
> OnCreate()에서 BroadcastReceiver 등록
> 퍼미션 요청 , ACCESS_FINE_LOCATION
> onResume 에서 BroadcastReceiver 등록
> onPause 에서 BroadcastReceiver 해제
public class MainActivity extends AppCompatActivity { private WifiManager wifiManager; private List<ScanResult> scanDatas; // ScanResult List final private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { if (ActivityCompat.checkSelfPermission( context.getApplicationContext() , android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } scanDatas = wifiManager.getScanResults(); Toast.makeText(context.getApplicationContext(), scanDatas.get(0).SSID, Toast.LENGTH_SHORT).show(); }else if(action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { //sendBroadcast(new Intent("wifi.ON_NETWORK_STATE_CHANGED")); //error context.sendBroadcast(new Intent("wifi.ON_NETWORK_STATE_CHANGED")); } } }; //API Level 30 // WifiManager.ScanResultsCallback callback = new WifiManager.ScanResultsCallback() { // @Override // public void onScanResultsAvailable() { // // Handle scan results here // // } // }; // Executor executor ; // @RequiresApi(api = Build.VERSION_CODES.R) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String[] PERMS_INITIAL={ // Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION , }; ActivityCompat.requestPermissions(this, PERMS_INITIAL, 127); Button buttonScan = (Button) findViewById( R.id.btnStartScan) ; buttonScan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { wifiManager.startScan() ; Log.d("WiFiManager" , "startScan() called--") ; } }); //The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing `getSystemService` to `getApplicationContext().getSystemService` wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); //wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); if(!wifiManager.isWifiEnabled()){ wifiManager.setWifiEnabled(true); } } @Override protected void onResume() { super.onResume(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){ // N=24, Android7.0 , // Do something for lollipop and above versions //{{ IntentFilter intentFilter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) ; intentFilter.addAction( WifiManager.NETWORK_STATE_CHANGED_ACTION); registerReceiver( receiver , intentFilter) ; //}} } else{ // do something for phones running an SDK before lollipop Log.d("AndroidVersion" , "Version is below : " + android.os.Build.VERSION.SDK_INT) ; } } @Override protected void onPause() { super.onPause(); unregisterReceiver( receiver ); } } |
- AndroidManifest.xml
> WiFi연결시 아래의 permission을 추가해줘야 함.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> |
- build.gradle(:app)
> WiFiManagerTest\app\ 폴더에 있음.
>minSdk, targetSdk 를 24로 설정후 에러가 없을려면
> dependencies 에서 material의 버젼을 1.5.0으로 설정해야함.
>> implementation 'com.google.android.material:material:1.5.0'
plugins { id 'com.android.application' } android { compileSdk 33 defaultConfig { applicationId "com.example.wifimanagertest" minSdk 24 targetSdk 24 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } |
'JAVA > android_studio' 카테고리의 다른 글
서비스 ForegroundService , BackgroundService (0) | 2024.09.10 |
---|---|
핸들러 , Handler (1) | 2024.09.10 |
ListView 의 아이템으로 두가지 이상의 View사용하기 (0) | 2024.03.26 |
안드로이드 벡터 패스(Vector Path) 그리기 (0) | 2024.03.14 |
Listview의 글자 크기 변경 (0) | 2024.03.14 |
- 아래와 같이 ListView 레이아웃 정의할때 listitem으로 별도의 레이아웃파일을 지정해야함.
tools:listitem="@layout/row_item">
</ListView>
https://recipes4dev.tistory.com/57
안드로이드 리스트뷰에 여러 종류의 아이템뷰 사용하기. (Android ListView with Multi Item)
1. 아이템이 다른 ListView 지금까지 안드로이드 ListView와 관련하여 기본 사용법, 커스텀 아이템, 속성, 아이템 다루기 등 몇 가지 주제들에 대해 살펴보았습니다. 여기까지 살펴본 내용 만으로도
recipes4dev.tistory.com
'JAVA > android_studio' 카테고리의 다른 글
핸들러 , Handler (1) | 2024.09.10 |
---|---|
WiFiManagerTest (0) | 2024.06.29 |
안드로이드 벡터 패스(Vector Path) 그리기 (0) | 2024.03.14 |
Listview의 글자 크기 변경 (0) | 2024.03.14 |
Bluetooth search (0) | 2024.02.18 |
https://www.charlezz.com/?p=1110
안드로이드 VectorDrawable 알아보기 | 찰스의 안드로이드
VectorDrawable 이전 포스트에서 Vector 이미지 포맷을 이용했을때의 장단점에 대해서 알아보았습니다. 이번 시간은 안드로이드 리소스인 VectorDrawable에 대해서 알아보도록 하겠습니다. xml 파일에서
www.charlezz.com
'JAVA > android_studio' 카테고리의 다른 글
WiFiManagerTest (0) | 2024.06.29 |
---|---|
ListView 의 아이템으로 두가지 이상의 View사용하기 (0) | 2024.03.26 |
Listview의 글자 크기 변경 (0) | 2024.03.14 |
Bluetooth search (0) | 2024.02.18 |
+-> Fragment , getActivity() (0) | 2023.10.15 |
https://stackoverflow.com/questions/20456393/how-to-change-text-size-of-listview
how to change text size of listview
I am using List Activity to retrieve data from SQLITE. But I can not set the font size of list view. Please help me. public class CartList extends ListActivity { private ArrayList<String>
stackoverflow.com
- source code :
Go into layout folder and create a new xml file named mytextview.xml(whatever you want to name it)
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:paddingTop="2dip"
android:paddingBottom="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12dp" />
in the code
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results));
change it to
setListAdapter(new ArrayAdapter<String>(this,
R.layout.mytextview, results));
'JAVA > android_studio' 카테고리의 다른 글
ListView 의 아이템으로 두가지 이상의 View사용하기 (0) | 2024.03.26 |
---|---|
안드로이드 벡터 패스(Vector Path) 그리기 (0) | 2024.03.14 |
Bluetooth search (0) | 2024.02.18 |
+-> Fragment , getActivity() (0) | 2023.10.15 |
+-> ListView 사용하기 , RecyclerView (0) | 2023.10.15 |
-
- 아래 그림에서 검색버튼을 누르면 블루투스 장치 목록이 나타남
2024-02-17 22:17:54.950 23048-23048/com.example.bluetoothsearch D/BluetoothAdapter: startDiscovery 2024-02-17 22:17:54.953 23048-23048/com.example.bluetoothsearch D/MainActivity: mOnBluetoothSearch(): mBluetoothAdapter.startDiscovery() called 2024-02-17 22:17:55.397 23048-23048/com.example.bluetoothsearch D/MainActivity: ======> BluetoothDevice.ACTION_FOUND received 2024-02-17 22:17:55.399 23048-23048/com.example.bluetoothsearch D/MainActivity: ===> BluetoothDevice.ACTION_FOUND{address=68:51:06:F7:71:03, name=null} 2024-02-17 22:17:55.410 23048-23048/com.example.bluetoothsearch D/MainActivity: ======> BluetoothDevice.ACTION_FOUND received 2024-02-17 22:17:55.414 23048-23048/com.example.bluetoothsearch D/MainActivity: ===> BluetoothDevice.ACTION_FOUND{address=D0:B5:C2:95:12:7C, name=HC-05_EdiTech} 2024-02-17 22:17:55.486 23048-23048/com.example.bluetoothsearch D/MainActivity: ======> BluetoothDevice.ACTION_FOUND received 2024-02-17 22:17:55.489 23048-23048/com.example.bluetoothsearch D/MainActivity: ===> BluetoothDevice.ACTION_FOUND{address=CC:4F:5C:3E:6E:3A, name=MEDICAL PHANTOM} 2024-02-17 22:17:56.742 23048-23048/com.example.bluetoothsearch D/MainActivity: ======> BluetoothDevice.ACTION_FOUND received 2024-02-17 22:17:56.744 23048-23048/com.example.bluetoothsearch D/MainActivity: ===> BluetoothDevice.ACTION_FOUND{address=41:63:F7:19:E7:DD, name=null} 2024-02-17 22:18:05.562 23048-23048/com.example.bluetoothsearch D/MainActivity: ======> BluetoothDevice.ACTION_FOUND received 2024-02-17 22:18:05.577 23048-23048/com.example.bluetoothsearch D/MainActivity: ===> BluetoothDevice.ACTION_FOUND{address=88:0F:10:9A:4B:A7, name=MI_SCALE} 2024-02-17 22:18:07.841 23048-23048/com.example.bluetoothsearch D/MainActivity: ===> BluetoothAdapter.ACTION_DISCOVERY_FINISHED |
'JAVA > android_studio' 카테고리의 다른 글
안드로이드 벡터 패스(Vector Path) 그리기 (0) | 2024.03.14 |
---|---|
Listview의 글자 크기 변경 (0) | 2024.03.14 |
+-> Fragment , getActivity() (0) | 2023.10.15 |
+-> ListView 사용하기 , RecyclerView (0) | 2023.10.15 |
+->Activity.runOnUiThread(Runnable) (0) | 2023.10.15 |
-
https://yongyi1587.tistory.com/10
[Android] Fragment에서 Activity Method 사용하기
Fragment에서 Activity의 method를 사용하는 법입니다.간단한 예제로 설명하겠습니다. MainActivity.javapublic class MainActivity extends AppCompatActivity {...private Button btn;...public void testMethod() {Log.d("MainActivity", "Test M
yongyi1587.tistory.com
'JAVA > android_studio' 카테고리의 다른 글
Listview의 글자 크기 변경 (0) | 2024.03.14 |
---|---|
Bluetooth search (0) | 2024.02.18 |
+-> ListView 사용하기 , RecyclerView (0) | 2023.10.15 |
+->Activity.runOnUiThread(Runnable) (0) | 2023.10.15 |
바인드 서비스 Bound Service (0) | 2022.10.12 |