Android AdMob広告
build.gradle
dependencies {
...
implementation 'com.google.android.gms:play-services-ads:11.8.0'
}
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
protected void admo() {
// xmlns:ads="http://schemas.android.com/apk/res-auto"
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
AdView adView = new AdView(this);
adView.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
adView.setLayoutParams(layoutParams);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
viewGroup.addView(adView);
}
https://developers.google.com/admob/android/banner
Set Up Google Play Services
https://developers.google.com/android/guides/setup
AdRequest.Builder adRequest = new AdRequest.Builder();
adRequest.addTestDevice("7026FA2EC1DC7E60FBEA02C64D33BD8B"); //asus
adRequest.addTestDevice("53185CF5BFA5B2121DF7FA86E7064C22"); //huawei
adView.loadAd(adRequest.build());
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="[ADMOB_APP_ID]"/>
</application>
</manifest>
public class MainActivity extends AppCompatActivity {
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
}
...
}
https://developers.google.com/admob/android/test-ads
Enable test devices
2017年2月25日土曜日
2017年2月24日金曜日
Android MediaPlayer
Android MediaPlayer
protected void t1() {
try {
String url = "http://www.ne.jp/asahi/music/myuu/wave/menuettm.mp3";
// Uri mu = Uri.parse("http://www.ne.jp/asahi/music/myuu/wave/menuettm.mp3");
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
// mediaPlayer.setDataSource(getApplicationContext(), mu);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setDataSource(url);
} catch (IOException e) {
e.printStackTrace();
}
}
protected void t1() {
try {
String url = "http://www.ne.jp/asahi/music/myuu/wave/menuettm.mp3";
// Uri mu = Uri.parse("http://www.ne.jp/asahi/music/myuu/wave/menuettm.mp3");
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
// mediaPlayer.setDataSource(getApplicationContext(), mu);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setDataSource(url);
} catch (IOException e) {
e.printStackTrace();
}
}
2017年2月7日火曜日
2017年1月26日木曜日
RTX1100 接続アドレス
telnet fe80::2a0:deff:fe37:****
LAN 2 fe80::2a0:deff:fe37:****
LAN1-1 fe80::2a0:deff:fe37:****
2017年1月23日月曜日
Android Dialog Title 非显现
Android Dialog Title 非显现
protected void dia() {
NDaig nDaig = new NDaig(this);
nDaig.requestWindowFeature(Window.FEATURE_NO_TITLE);
nDaig.show();
}
protected void dia() {
NDaig nDaig = new NDaig(this);
nDaig.requestWindowFeature(Window.FEATURE_NO_TITLE);
nDaig.show();
}
2017年1月16日月曜日
Java 回调
Java 回调
https://paiza.io/projects/3KFF7-6l4pA4pvijDyvPiw
public class CB2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
CBB2 cb = new CBB2();
cb.tt(new CBB2.CallBack() {
@Override
public void start() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName());
}
});
}
}
class CBB2{
public interface CallBack{
public void start();
}
public void tt(CallBack cb){
t1 tt1 = new t1(cb);
tt1.start();
}
public class t1 extends Thread{
private CallBack cb;
public t1(CallBack cb) {
this.cb = cb;
}
public void run(){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cb.start();
}
}
}
https://paiza.io/projects/3KFF7-6l4pA4pvijDyvPiw
public class CB2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
CBB2 cb = new CBB2();
cb.tt(new CBB2.CallBack() {
@Override
public void start() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName());
}
});
}
}
class CBB2{
public interface CallBack{
public void start();
}
public void tt(CallBack cb){
t1 tt1 = new t1(cb);
tt1.start();
}
public class t1 extends Thread{
private CallBack cb;
public t1(CallBack cb) {
this.cb = cb;
}
public void run(){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cb.start();
}
}
}
2017年1月12日木曜日
Java 线程同步。
Java 线程同步。
要锁定都一个资源。
public class T1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TX re = new TX();
T2 t2 = new T2(re);
Thread t = new Thread(t2);
t.start();
T3 t3 = new T3(re);
Thread tt = new Thread(t3);
tt.start();
}
}
class TX {
public String name;
public String sex;
}
class T2 implements Runnable {
private TX r;
public T2(TX r) {
this.r = r;
}
@Override
public void run() {
// TODO Auto-generated method stub
int i = 0;
while (true) {
synchronized (r) {
if (i == 0) {
r.name = "AAAA";
r.sex = "FFFFF";
} else {
r.name = "BBB";
r.sex = "mmmmmmmmmmmmmmmmmmmm";
}
}
i = (i + 1) % 2;
}
}
}
class T3 implements Runnable {
private TX r;
public T3(TX r) {
this.r = r;
}
@Override
public void run() {
// TODO Auto-generated method stub
while (true) {
synchronized (r) {
System.out.println(r.name + "---------" + r.sex);
}
}
}
}
要锁定都一个资源。
public class T1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TX re = new TX();
T2 t2 = new T2(re);
Thread t = new Thread(t2);
t.start();
T3 t3 = new T3(re);
Thread tt = new Thread(t3);
tt.start();
}
}
class TX {
public String name;
public String sex;
}
class T2 implements Runnable {
private TX r;
public T2(TX r) {
this.r = r;
}
@Override
public void run() {
// TODO Auto-generated method stub
int i = 0;
while (true) {
synchronized (r) {
if (i == 0) {
r.name = "AAAA";
r.sex = "FFFFF";
} else {
r.name = "BBB";
r.sex = "mmmmmmmmmmmmmmmmmmmm";
}
}
i = (i + 1) % 2;
}
}
}
class T3 implements Runnable {
private TX r;
public T3(TX r) {
this.r = r;
}
@Override
public void run() {
// TODO Auto-generated method stub
while (true) {
synchronized (r) {
System.out.println(r.name + "---------" + r.sex);
}
}
}
}
登録:
投稿 (Atom)