2019年10月20日日曜日

在前台运行服务

在前台运行服务

https://developer.android.com/guide/components/services#Foreground

Intent notificationIntent = new Intent(this, ExampleActivity.class);
PendingIntent pendingIntent =
        PendingIntent.getActivity(this, 0, notificationIntent, 0);

Notification notification =
          new Notification.Builder(this, CHANNEL_DEFAULT_IMPORTANCE)
    .setContentTitle(getText(R.string.notification_title))
    .setContentText(getText(R.string.notification_message))
    .setSmallIcon(R.drawable.icon)
    .setContentIntent(pendingIntent)
    .setTicker(getText(R.string.ticker_text))
    .build();

startForeground(ONGOING_NOTIFICATION_ID, notification);

2019年10月8日火曜日

网络安全配置

网络安全配置

https://developer.android.com/training/articles/security-config


NetworkSecurityConfig: No Network Security Config specified, using platform default

res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">ekidata.jp</domain>
    </domain-config>
</network-security-config>


<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
     <application android:networkSecurityConfig="@xml/network_security_config"
                        ... >
            ...
    </application>
</manifest>
   




2019年9月1日日曜日

android 音声の周波数を作成

android 音声の周波数を作成

byte b = (byte)(Math.sin(bufferIndex/2*Math.PI(SamplingRate /Frequency))

角度 =bufferIndex /2*Math.PI(4400/800);
byte値(音声のビット、B辺) = (byte) (Math.sin(temp) * 120(C辺);

    private void hz() {
        byte[] bs = new byte[44100];
        Double temp;
        for (int i = 0; i < bs.length; i++) {
            temp = i / 2 * Math.PI / (44100 / Double.parseDouble("800"));
            bs[i] = (byte) (Math.sin(temp) * 120);
        }
        audioTrack.play();
        while (true) {
            audioTrack.write(bs, 0, bs.length);
        }
    }


    private void hz() {
        byte[] bs = new byte[44100];
        Double temp;
        for (int i = 0; i < bs.length; i++) {
            temp = i / 2 * Math.PI / (44100 / Double.parseDouble("800"));
            bs[i] = (byte) (Math.sin(temp) * 120);
        }
        audioTrack.play();
        while (true) {
            audioTrack.write(bs, 0, bs.length);
        }
    }
SamplingRate =44100
Frequency =800

SamplingRate =44100
Frequency =44100

SamplingRate =360
Frequency =4

https://docs.google.com/spreadsheets/d/1IvCVmJ_WYIhO6PaumFV5mpf3XDIjgu4TwmDbSwwLuK8/edit?usp=sharing




2019年8月9日金曜日

minSdkVersion 28

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.kankanla.pi28"
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

compileSdkVersion 29

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.kankanla.pi292"
        minSdkVersion 29
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

2019年8月5日月曜日

DialogFragment 生命周期

DialogFragment  生命周期

 I/###  DialogF: onCreate 1
 I/###  DialogF: onGetLayoutInflater 2
 I/###  DialogF: onCreateDialog 3
 I/###  DialogF: onCreateView 4
 I/###  DialogF: onStart 5
 I/###  DialogF: onResume 6


 I/###  DialogF: onCancel 7
 I/###  DialogF: onPause 8
 I/###  DialogF: onStop 9
 I/###  DialogF: onDestroyView 10
 I/###  DialogF: onDestroy 11
 I/###  DialogF: onDetach 12



2019年7月11日木曜日

Understand the Activity Lifecycle 生命周期




生命周期

package com.kankanla.m20190711m_recorder;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    private final String T = "###  MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i(T, "1 onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStart() {
        Log.i(T, "2 onStart");
        super.onStart();
    }

    @Override
    protected void onResume() {
        Log.i(T, "3 onResume");
        super.onResume();
    }

    @Override
    protected void onPostResume() {
        Log.i(T, "4 onPostResume");
        super.onPostResume();
    }

    @Override
    protected void onPause() {
        Log.i(T, "5 onPause");
        super.onPause();
    }

    @Override
    protected void onStop() {
        Log.i(T, "6 onStop");
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        Log.i(T, "7 onDestroy");
        super.onDestroy();
    }

    @Override
    protected void onRestart() {
        Log.i(T, "8 onRestart");
        super.onRestart();
    }
}