ラベル Android の投稿を表示しています。 すべての投稿を表示
ラベル Android の投稿を表示しています。 すべての投稿を表示

2017年11月23日木曜日

android adb 複数TCPIP链接

android adb 複数TCPIP链接


C:\> adb -s cc1394de tcpip 5555
restarting in TCP mode port: 5555

C:\> adb connect 192.168.11.111:5555
connected to 192.168.11.111:5555

C:\> adb devices
List of devices attached
192.168.11.111:5555     device
192.168.11.109:5556     device


2017年11月17日金曜日

BroadcastReceiver 监听

protected void bttest() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            switch (intent.getAction()) {
                case BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED:
                    int x = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, 99);
                    if (x == BluetoothAdapter.STATE_CONNECTED) {
                        System.out.println("--------------2222222222222222------4-----");
                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                        System.out.println(device.getAddress());
                        System.out.println(device.getName());
                        System.out.println(device.getBondState());
                        System.out.println(device.getBluetoothClass());
                    }

                    break;
                case BluetoothAdapter.ACTION_STATE_CHANGED:
                    //Bluetooth has been turned on or off.
                    System.out.println("---------ACTION_STATE_CHANGED---------------------------------------------");
                    System.out.println(intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 22));
                    break;

                case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
                    System.out.println("--------本地蓝牙适配器已完成设备发现过程。----------------");
                    break;

                case BluetoothAdapter.ACTION_DISCOVERY_STARTED:
                    System.out.println("-------------本地蓝牙适配器已启动远程设备发现过程。------------");
                    break;
                   
                case BluetoothDevice.ACTION_FOUND:
                    System.out.println("---------------------发现远程设备。---------------------");
                    System.out.println(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE));
                    BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    System.out.println(bluetoothDevice.getName());
                    System.out.println(bluetoothDevice.getAddress());
                    break;
            }
        }
    };

    IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    IntentFilter intentFilter1 = new IntentFilter(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
    IntentFilter intentFilter2 = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    IntentFilter intentFilter3 = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    IntentFilter intentFilter4 = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    registerReceiver(broadcastReceiver, intentFilter);
    registerReceiver(broadcastReceiver, intentFilter1);
    registerReceiver(broadcastReceiver, intentFilter2);
    registerReceiver(broadcastReceiver, intentFilter3);
    registerReceiver(broadcastReceiver, intentFilter4);
}

2017年11月5日日曜日

Wifi 一覧

Wifi 一覧


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


protected void show_wifi_ssid() {
    WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (wifiManager.isWifiEnabled()) {
        List<ScanResult> scanResults = wifiManager.getScanResults();
        for (ScanResult x : scanResults) {
            System.out.println("--------------------------------------------");
            System.out.println(x.toString());
            System.out.println(x.BSSID);
            System.out.println(x.SSID);
            System.out.println(x.capabilities);
        }
    } else {
        Toast.makeText(this, "WifiNull", Toast.LENGTH_SHORT).show();
    }
}



I/System.out: SSID: AirPort61998, BSSID: 34:76:c5:5e:f2:2e, capabilities: [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS], level: -87, frequency: 2432, timestamp: 413176363535, distance: ?(cm), distanceSd: ?(cm), wpsState :configured, wpsDeviceName :I-O DATA 802.11n AP Router
I/System.out: 34:76:c5:5e:f2:2e
I/System.out: AirPort61998
I/System.out: [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]









2017年10月29日日曜日

SupportActionBar 背景色変更

SupportActionBar 背景色変更


android.support.v7.app.ActionBar actionBar = getSupportActionBar();
int color = android.R.color.black;
Drawable backgroundDrawable = getApplicationContext().getResources().getDrawable(color);
actionBar.setBackgroundDrawable(backgroundDrawable);


2017年10月16日月曜日

assets フォルダ内の画像を読み込み

assets フォルダ内の画像を読み込み


AssetManager assetManager = getAssets();
ImageView imageView = (ImageView) findViewById(R.id.imageView);
InputStream inputStream = null;
try {
     inputStream = assetManager.open("g1213.png");
} catch (IOException e) {
     e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
imageView.setImageBitmap(bitmap);


2017年8月30日水曜日

多言語化

多言語化


res/values/strings.xml - 英語
res/values-ja/strings.xml - 日本語
res/values-zh/strings.xml - 中国語(簡体)
res/values-zh-rTW/strings.xml - 中国語:台湾(繁體)
res/values-zh-rHK/strings.xml - 中国語:香港(繁體)
res/values-zh-rMO/strings.xml - 中国語:マカオ(繁體)
res/values-zh-rSG/strings.xml - 中国語:シンガポール(簡体)

2017年8月28日月曜日

Android 通知音

Android 通知音

RingtoneManager



    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == 999) {
            Uri uri = (Uri) data.getExtras().get(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri);
            String name = ringtone.getTitle(getActivity());
            System.out.println(name);
            System.out.println(uri);
            set_sound_url(id, uri.toString());

            TextView select_Sound = (TextView) view.findViewById(R.id.select_sound);
            select_Sound.setText(get_sound_url_title(id));
        }
    }

    protected void lin2(String id) {
        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.select_sound_title));
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); 
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM); 
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
        startActivityForResult(intent, 999);
    }

2017年7月31日月曜日

Android SoundPool soundPool



public class MainActivity extends AppCompatActivity {
    protected SoundPool soundPool;
    protected int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        test();

        AssetManager am = getAssets();
        try {
            id = soundPool.load(am.openFd("PCM-M10_441kHz16bit.wav"), 1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                Toast.makeText(MainActivity.this, "9999999999999", Toast.LENGTH_SHORT).show();
                soundPool.play(id, 1, 1, 1, 1, 1);
            }
        });
    }

    protected void test() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            SoundPool.Builder spb = new SoundPool.Builder();
            AudioAttributes.Builder b = new AudioAttributes.Builder();
            b.setUsage(AudioAttributes.USAGE_MEDIA);
            b.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
            AudioAttributes a = b.build();
            spb.setAudioAttributes(a);
            spb.setMaxStreams(12);
            soundPool = spb.build();
        }
    }
}

2017年6月2日金曜日

android Bitmap to File

android Bitmap to File


    case REQUEST_IMAGE_CAPTURE:
        File f = getFilesDir();
        Bitmap bit = data.getExtras().getParcelable("data");
        ImageView imageView = (ImageView) findViewById(R.id.bit);
        imageView.setImageBitmap(bit);

        try {
            FileOutputStream fileOutputStream = new FileOutputStream(f.getPath() + "/xxx.jpg");
            bit.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;

2017年5月31日水曜日

android 裁剪图片库图片

android 裁剪图片库图片





package com.kankanla.m0531a;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_IMAGE_SELECT = 1;
    private static final int REQUEST_IMAGE_CAPTURE = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setCutimg();
    }

    protected void setCutimg() {
        Intent intent = new Intent();
        intent.setAction(intent.ACTION_OPEN_DOCUMENT);
        intent.setType("image/*");
        startActivityForResult(intent, REQUEST_IMAGE_SELECT);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQUEST_IMAGE_SELECT:
                    Intent intent = new Intent("com.android.camera.action.CROP");
                    Uri uri = data.getData();
                    intent.setData(uri);
                    intent.putExtra("outputX", 200);
                    intent.putExtra("outputY", 200);
                    intent.putExtra("aspectX", 1);
                    intent.putExtra("aspectY", 1);
                    intent.putExtra("scale", true);
                    intent.putExtra("return-data", true);
                    startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
                    break;
                case REQUEST_IMAGE_CAPTURE:
                    Bitmap bit = data.getExtras().getParcelable("data");
                    ImageView imageView = (ImageView) findViewById(R.id.bit);
                    imageView.setImageBitmap(bit);
                    break;
            }
        }
    }
}



2017年5月9日火曜日

Android 片段的生命周期(其 Activity 运行时)

片段的生命周期(其 Activity 运行时)

https://developer.android.com/guide/components/fragments.html


第一次启动
....m.out: Item_list--------------onAttach----------------
....m.out: Item_list--------------onCreate----------------
....m.out: Item_list--------------onCreateView----------------
....m.out: Item_list--------------onActivityCreated----------------
....m.out: Item_list--------------onStart----------------
....m.out: Item_list--------------onResume----------------


关闭屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------

从新开屏幕
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------



反转屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
....nla.m0417b I/System.out: Item_list--------------onDestroyView----------------
....nla.m0417b I/System.out: Item_list--------------onDetach----------------
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------


退回到上一Activety
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
....nla.m0417b I/System.out: Item_list--------------onDestroyView----------------
....nla.m0417b I/System.out: Item_list--------------onDestroy----------------
....nla.m0417b I/System.out: Item_list--------------onDetach----------------


从概览屏幕中返回
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreate----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------

打开概览屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------

打开其他Activety

在概览屏幕中删除
....m.out: Item_list--------------onDestroyView----------------
....m.out: Item_list--------------onDestroy----------------
....m.out: Item_list--------------onDetach----------------


按图标重新启动
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreate----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------

2017年4月6日木曜日

Android Intent 文件存储 找到文件

Intent 文件存储 找到文件

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>





    protected void t1() {
        int cc = 100;
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.setType("audio/*");
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(intent, cc);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100 && resultCode == RESULT_OK) {
            Uri uri = data.getData();
            System.out.println(uri);
            Fpath(uri);
        }
    }

    protected void Fpath(Uri uri) {
        ContentResolver contentResolver = getContentResolver();
        long id = ContentUris.parseId(uri);

//      1.  select _id,_data from uri while _id = id;
        String[] select = new String[]{"_id","_data"};
        Cursor cursor = contentResolver.query(uri, select, "_id = " + id, null, null);

//      2.  select * from uri while _id = id;
//        Cursor cursor = contentResolver.query(uri, null, "_id = " + id, null, null);
//      3.  select * from uri;
//        Cursor cursor = contentResolver.query(uri, null, null, null, null);

        while (cursor.moveToNext()) {
            int cont = cursor.getColumnCount();
            for (int i = 0; i < cont; i++) {
                System.out.print(cursor.getColumnName(i) + ">> ");
                System.out.println(cursor.getString(i));
            }
        }
    }


2017年4月5日水曜日

Android MediaPlayer 播放指定文件夾

Android MediaPlayer 播放指定文件夾

   public void PlayList(File file) {
        if (file.isFile()) {
            if (file.isFile()) {
                fileDir = file.getParentFile();
                fileName = file.getName();
            } else {
                fileDir = file;
                fileName = null;
            }
            fileArray = new ArrayList<String>();
            fileDir.list(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    if (name.endsWith(".mp3") || name.endsWith(".mp4") || name.endsWith(".wav")) {
                        if ((new File(dir, name)).isFile()) {
                            fileArray.add(name);
                            return true;
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }
                }
            });

            PlayFile(fileName);
        } else {
            Log.i(TAG, "nofindthefile...................................................");
        }
    }

    public void PlayFile(final String fileName) {
        Log.i(TAG, "FileName" + fileName);
        intNum = fileArray.indexOf(fileName);
        if (intNum == -1) {
            intNum = 0;
        }
        Uri uri = Uri.fromFile(new File(fileDir, fileArray.get(intNum)));
        if (intNum < fileArray.size() - 1) {
            intNum++;
        } else {
            intNum = 0;
        }
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.reset();
        try {
            mediaPlayer.setDataSource(context, uri);
            mediaPlayer.prepare();
        } catch (IOException e) {
            e.printStackTrace();
            PlayFile(fileArray.get(intNum));
        }
        mediaPlayer.start();
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                PlayFile(fileArray.get(intNum));
            }
        });
    }





2017年3月31日金曜日

Android 卡拉OK

Android 卡拉OK


protected void arp() {
        int sampleRateInHz = 44100;
        int rec_bufsize = AudioRecord.getMinBufferSize(sampleRateInHz, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
        int play_bufsize = AudioTrack.getMinBufferSize(sampleRateInHz, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
//        MediaRecorder.AudioSource.MIC
        AudioRecord audioRecord = new AudioRecord(
                MediaRecorder.AudioSource.MIC,
                sampleRateInHz,
                AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                rec_bufsize);
        AudioTrack audioTrack = new AudioTrack(
                AudioManager.STREAM_MUSIC,
                sampleRateInHz,
                AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                play_bufsize,
                AudioTrack.MODE_STREAM);
        byte[] temp = new byte[16];
        audioRecord.startRecording();
        audioTrack.play();
        while (!stop) {
            audioRecord.read(temp, 0, temp.length);
            audioTrack.write(temp, 0, temp.length);
        }
        audioTrack.stop();
        audioRecord.stop();
        audioRecord.release();
    }



2017年3月30日木曜日

Android AoundTrack

Android AoundTrack


package com.example.kankanla.start;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.makeText(this, "AudioTrack.demo", Toast.LENGTH_LONG).show();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    AP();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    protected void AP() throws IOException {
        int sampleRateInHz = 44100;
        int buferSize = AudioTrack.getMinBufferSize(
                sampleRateInHz,
                AudioFormat.CHANNEL_IN_STEREO,
                AudioFormat.ENCODING_PCM_16BIT);
        AudioTrack audioTrack = new AudioTrack(
                AudioManager.STREAM_MUSIC,
                sampleRateInHz,
                AudioFormat.CHANNEL_IN_STEREO,
                AudioFormat.ENCODING_PCM_16BIT,
                buferSize, AudioTrack.MODE_STREAM);

        FileInputStream fileInputStream = new FileInputStream(new File(Environment.getExternalStorageDirectory().toString(), "PCM-D50_441kHz16bit.wav"));
        byte[] buffer = new byte[buferSize];
        int lens = 0;
        audioTrack.play();
        while ((lens = fileInputStream.read(buffer)) != -1) {
            audioTrack.write(buffer, 0, lens);
        }
        System.out.println(audioTrack.getPlayState());
        audioTrack.stop();
        System.out.println(audioTrack.getPlayState());
        System.out.println(Thread.currentThread().getName());

//        public static final int PLAYSTATE_STOPPED = 1;  // matches SL_PLAYSTATE_STOPPED
//        /** indicates AudioTrack state is paused */
//        public static final int PLAYSTATE_PAUSED  = 2;  // matches SL_PLAYSTATE_PAUSED
//        /** indicates AudioTrack state is playing */
//        public static final int PLAYSTATE_PLAYING = 3;  // matches SL_PLAYSTATE_PLAYING
    }
}

2017年3月26日日曜日

Android ContentProvider 内容提供程序單元測試

ContentProvider 内容提供程序單元測試

public class youContentProviderTest {
    @Test
    public void delete() throws Exception {
        Context context = InstrumentationRegistry.getContext();
        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse("content://com.kankanla.e560.m0325a.youContentProvider/categoly/delete/");
        int i = contentResolver.delete(uri, "rowid > ?", new String[]{"10"});
        System.out.println("77777777777777777777777777777777");
        System.out.println(i);
    }

    @Test
    public void insert() throws Exception {
        Context context = InstrumentationRegistry.getContext();
        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse("content://com.kankanla.e560.m0325a.youContentProvider/category/insert/1");
        System.out.println("11111111111111111111111111111111111111111");
        System.out.println(uri.getAuthority());
        System.out.println(uri.getPath());
        System.out.println(uri.getPathSegments());
        System.out.println("2222222222222222222222222222222222222222222");
        ContentValues contentValues = new ContentValues();
        contentValues.put("category_name", "日本語");
        for (int i = 0; i < 10; i++) {
            Uri uri1 = contentResolver.insert(uri, contentValues);
            System.out.println(uri1.toString());
        }
    }

}




package com.kankanla.e560.m0325a;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Created by E560 on 2017/03/25.
 */

public class youContentProvider extends ContentProvider {
    private static final String TAG = "youContentProvider";
    private static YouDB youDB;
    private static UriMatcher uriMatcher;
    private static final String AUTHORITY = "com.kankanla.e560.m0325a.youContentProvider";

    private static final int insert_category = 1;
    private static final int select_category = 2;
    private static final int insert_list = 3;
    private static final int select_list = 4;
    private static final int matcher_all = 5;
    private static final int del_category = 6;
    private static final int error = 9;

    static {
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(AUTHORITY, "list/insert", insert_list);
        uriMatcher.addURI(AUTHORITY, "category/insert", insert_category);
        uriMatcher.addURI(AUTHORITY, "category/insert/#", insert_category);
        uriMatcher.addURI(AUTHORITY, "category/delete/", del_category);
        uriMatcher.addURI(AUTHORITY, "*/*/*", error);
    }

    @Override
    public boolean onCreate() {
        youDB = new YouDB(getContext());
        SQLiteDatabase sqLiteDatabase = youDB.getReadableDatabase();
        sqLiteDatabase.isReadOnly();
        System.out.println("888888888888888888888888888888888888888888");
        Log.i(TAG, String.valueOf(sqLiteDatabase.isOpen()));
        return sqLiteDatabase.isOpen();
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
        return null;
    }

    @Nullable
    @Override
    public String getType(@NonNull Uri uri) {
        return null;
    }

    @Nullable
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
        Uri uri1 = Uri.parse(uri.getAuthority() + uri.getPath());
        int i = uriMatcher.match(uri);
        System.out.println(i);
        long cont = 0;
        System.out.println("000000000000000000000000000000000000000000000000");
        SQLiteDatabase sqLiteDatabase = youDB.getWritableDatabase();
        switch (i) {
            case insert_category:
                cont = sqLiteDatabase.insert("category", null, values);
                uri1 = ContentUris.withAppendedId(Uri.parse(uri.getAuthority() + uri.getPath()), cont);
                break;
            case insert_list:
                cont = sqLiteDatabase.insert("list", null, values);
                uri1 = ContentUris.withAppendedId(Uri.parse(uri.getAuthority() + uri.getPath()), cont);
                break;
        }
        System.out.println(uri1.toString());
        sqLiteDatabase.close();
        return uri1;
    }

    @Override
    public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
        int flag = uriMatcher.match(uri);
        int con = 0;
        SQLiteDatabase sqLiteDatabase = youDB.getWritableDatabase();
        switch (flag) {
            case del_category:
                con = sqLiteDatabase.delete("category", selection, selectionArgs);
                break;
        }
        sqLiteDatabase.close();
        return con;
    }

    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) {
        return 0;
    }

    private class YouDB extends SQLiteOpenHelper {
        private static final String name = "m0325.db";
        private static final int version = 1;

        public YouDB(Context context) {
            super(context, name, null, version);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            String sql_category = "create table category(rowid INTEGER PRIMARY KEY AUTOINCREMENT, category_name TEXT NOT NULL)";
            String sql_index = "create table list (rowid INTEGER PRIMARY KEY AUTOINCREMENT, category_id INTEGER NOT NULL,comment TEXT)";
            db.execSQL(sql_category);
            db.execSQL(sql_index);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        }
    }

}





2017年3月19日日曜日

android adb error (10061)

解決步驟

C:\Users>adb devices
List of devices attached
cc13094de        device

C:\Users>adb connect 192.168.11.100
unable to connect to 192.168.11.100:5555: cannot connect to 192.168.11.100:5555: 対象のコンピューターによって拒否された ため、接続できませんでした。 (10061)

C:\Users>adb kill-server

C:\Users>adb usb
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
restarting in USB mode

C:\Users>adb tcpip 5555
restarting in TCP mode port: 5555

C:\Users>adb connect 192.168.11.100
connected to 192.168.11.100:5555

C:\Users>adb devices
List of devices attached
192.168.11.100:5555     device
cc13094de        device

2017年3月17日金曜日

Andriod Intent Camera

Andriod Intent Camera



public class MainActivity extends AppCompatActivity {
    protected File file;
    protected Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t1();
    }

    protected void t1() {
        file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "00000aaaa.jpg");
        uri = Uri.fromFile(file);
        Intent intent = new Intent();
        intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, 99);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 99 && resultCode == RESULT_OK) {
            view2();
        }
    }

    protected void view2() {
        Display display = getWindowManager().getDefaultDisplay();
        Point p = new Point();
        display.getSize(p);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getAbsolutePath(), options);

        int samsize = Math.max(options.outHeight / p.y, options.outWidth / p.x);
        options.inJustDecodeBounds = false;
        options.inSampleSize = samsize;

        ImageView imageView = (ImageView) findViewById(R.id.vvvv);
        Bitmap bt = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
        imageView.setImageBitmap(bt);
    }
}

2017年3月13日月曜日

2017年3月12日日曜日

intent Camera

intent Camera



    protected void t1() {
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        ImageView imageView = (ImageView) findViewById(R.id.imageView);
        Bundle bu = data.getExtras();
        Bitmap bt = (Bitmap) bu.get("data");
        imageView.setImageBitmap(bt);
    }


https://developer.android.com/training/camera/photobasics.html

static final int REQUEST_IMAGE_CAPTURE = 1;

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);
    }
}