android2019. 11. 27. 15:38

 

구글 홈페이지를 이용하여 실제 인터넷에 연결이 가능한지 여부를 확인


Thread connectionCheckThread = new Thread(){

        @Override
        public void run() {
            super.run();

            Context context = getApplicationContext();
            boolean result = isConnected(context);
            Log.d(LOG_TAG, "isConnected by thread : " + result);
            Message msg = mHandler.obtainMessage();
            msg.what=result ? 1 : 0;
            mHandler.sendMessage(msg);


        }
        public boolean isConnected(Context context) {
            ConnectivityManager cm = (ConnectivityManager)context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
            if (activeNetwork != null && activeNetwork.isConnected()) {
                try {
                    URL url = new URL("http://www.google.com/");
                    HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
                    urlc.setRequestProperty("User-Agent", "test");
                    urlc.setRequestProperty("Connection", "close");
                    urlc.setConnectTimeout(1000); // mTimeout is in seconds
                    urlc.connect();
                    if (urlc.getResponseCode() == 200) {
                        return true;
                    } else {
                        return false;
                    }
                } catch (IOException e) {
                    Log.e(LOG_TAG, "Error checking internet connection", e);
                    return false;
                }
            }

            return false;

        }

    };



출처: https://stackoverflow.com/questions/9570237/android-check-internet-connection 

'android' 카테고리의 다른 글

Android P native service 및 client 예제  (0) 2019.12.19
PDK에서 Android studio app을 gradle build 시 tips  (0) 2019.11.27
android alarm 세팅  (0) 2019.11.27
Android bp usage  (0) 2019.10.15
voice search later Android P  (0) 2019.09.26
Posted by easy16
android2019. 11. 27. 14:29

 

주의 사항: 

 

AndroidManifest에 아래와 같이 receiver 속성을 지정한다.

android:process=":remote" 없는 경우 동작하지 않음.

 

android:process=":remote"

android:name=".Alarm"


정확도와 overhead를 고려 어느 set함수를 호출할지 선택한다.

  setRepeating vs setInexactRepeating 

차이점은 검색해 보도록, 알람의 주기는 최소 1분이 되어야함.


public class Alarm extends BroadcastReceiver {
    private final String LOG_TAG = "WifiMonitoringService";

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.d(LOG_TAG,"Alarm");
        Toast.makeText(context, "Alarm", Toast.LENGTH_LONG ).show();

    }
    public void setAlarm(Context context)
    {
        AlarmManager am =( AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent i = new Intent(context, Alarm.class);
        PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);

        //am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+10000, 1000 * 60 * 1, pi); // Millisec * Second * Minute
        am.setInexactRepeating(AlarmManager.RTC,
                System.currentTimeMillis() + 1000, 60*1000, pi);
    }

    public void cancelAlarm(Context context)
    {
        Intent intent = new Intent(context, Alarm.class);
        PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.cancel(sender);
    }
}



 

 

참조 : https://developer.android.com/training/scheduling/alarms
https://androidclarified.com/android-example-alarm-manager-complete-working/

'android' 카테고리의 다른 글

PDK에서 Android studio app을 gradle build 시 tips  (0) 2019.11.27
android internet 연결 확인  (0) 2019.11.27
Android bp usage  (0) 2019.10.15
voice search later Android P  (0) 2019.09.26
Simple requestPermission  (0) 2019.09.26
Posted by easy16
android2019. 10. 15. 12:15

링크 :https://source.android.com/setup/build

'android' 카테고리의 다른 글

android internet 연결 확인  (0) 2019.11.27
android alarm 세팅  (0) 2019.11.27
voice search later Android P  (0) 2019.09.26
Simple requestPermission  (0) 2019.09.26
Android bp cflags 위치  (0) 2019.09.24
Posted by easy16
android2019. 9. 26. 15:55

Android P 이후, voice search는 구글이 정의한 VoBLE를 통해 실행한다.

공개된 코드가 아니므로 추정하자면, GMS package 중 하나인 android katniss (assistant) 내부에 

Gatt profile을 이용해 pcm data를 받는 코드가 있을 것으로 추정함.

로그상 aosp/hardware/interface에 존재하는 r_submix를 태우는 것으로 보아 해당 모듈을 통해

audio data를 gethering 하는 것으로 보임.

 

의도는 당연히 device에 pairing된 모든 RC에 대한 동작을 보장하고 싶어하는 것 같다.

하지만 vendor 마다 동작이나 인식률에 차이가 있는 것으로 볼 때, 퀄을 보장하기 위한 시간이 필요.

 

 

 

 

 

 

 

 

'android' 카테고리의 다른 글

android alarm 세팅  (0) 2019.11.27
Android bp usage  (0) 2019.10.15
Simple requestPermission  (0) 2019.09.26
Android bp cflags 위치  (0) 2019.09.24
LOCAL_SDK_VERSION and LOCAL_PRIVATE_PLATFORM_APIS  (0) 2019.09.18
Posted by easy16
android2019. 9. 26. 15:51

 

 

아래와 같이 추가.

 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 0);
}

 

 

'android' 카테고리의 다른 글

Android bp usage  (0) 2019.10.15
voice search later Android P  (0) 2019.09.26
Android bp cflags 위치  (0) 2019.09.24
LOCAL_SDK_VERSION and LOCAL_PRIVATE_PLATFORM_APIS  (0) 2019.09.18
Build error : X (java:sdk) should not link to Y (java:platform)  (0) 2019.09.18
Posted by easy16
android2019. 9. 24. 09:56

path : system/bt/build/BUILD.gn


  cflags_cc = [
#TODO(jpawlowski): we should use same c++ version as Android, which is c++11,
# but we use some c++14 features. Uncomment when this get fixed in code.:
    "-std=c++14",
    "-fno-exceptions",
    "-fpermissive",
  ]

  defines = [
    "_FORTIFY_SOURCE=2",
    "_GNU_SOURCE",
    "HAS_NO_BDROID_BUILDCFG",
    "LOG_NDEBUG=1",
    "EXPORT_SYMBOL=__attribute__((visibility(\"default\")))",
    "KERNEL_MISSING_CLOCK_BOOTTIME_ALARM=TRUE",

    # This is a macro to that can be used by source code to detect if the
    # current build is done by GN or via Android.mk. This is a temporary
    # workaround until we can remove all Android-specific dependencies.
    "OS_GENERIC",
  ]
}

 

출처 : AOSP

Posted by easy16
android2019. 9. 18. 19:25

LOCAL_SDK_VERSION and LOCAL_PRIVATE_PLATFORM_APIS는 동시 사용불가.

LOCAL_PRIVATE_PLATFORM_APIS := true

지정해야 Hide 처리된 API 사용 가능

Posted by easy16
android2019. 9. 18. 16:00

 

X (java:sdk) should not link to Y (java:platform)

 

 

LOCAL_SDK_VERSION := current
with:
LOCAL_PRIVATE_PLATFORM_APIS := true

 

 

출처 : 

https://stackoverflow.com/questions/55004358/x-javasdk-should-not-link-to-y-javaplatform

 

X (java:sdk) should not link to Y (java:platform)

I am an android firmware developer. I work with source of android 9. I've written a custom network location provider for AOSP firmware, named offline location service. I've added this application to

stackoverflow.com

 

 

 

 

Posted by easy16
android2019. 9. 2. 11:01

//"getApplicationContext"이 아닌 호출하는 activity의 객체를 전달.

 

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


if (mLocalAdapter.isEnabled() == false) {

AlertDialog.Builder builder = new AlertDialog.Builder(/*getApplicationContext()*/MainActivity.this);
builder.setTitle("Warn").setMessage("set bt on") ;

builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mLocalAdapter.enable();
Toast.makeText(getApplicationContext(),"Enabling bluetooth",Toast.LENGTH_LONG).show();
}
});
builder.setNegativeButton("no", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),"continue with disabled bt",Toast.LENGTH_LONG).show();
}
});

AlertDialog alertDialog = builder.create();
alertDialog.show();


}
}


});

Posted by easy16
android2019. 8. 29. 17:17

 

서비스 추가시, AndroidManifest에 하기와 같이 android:process 속성을 추가한다. 

그러면 해당 서비스는 application내의 activity와 async하게 동작하며, 실행 시에도 

pid가 다름을 관찰할 수 있다.

 

<service
android:process="com.test.servicetest.btservice"
android:name=".BluetoothResetService" />

Posted by easy16