Thursday, December 17, 2015

Grant Permission Android 6.0

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_PERMISSION_READ_CONTACT);    }
}

@Override    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case REQUEST_CODE_PERMISSION_READ_CONTACT:
                for (int i = 0; i < grantResults.length; i++) {
                    Log.i("GRANT_RESULT", i + ":" + grantResults[i]);                }
                Log.i("GRANT_RESULT", "Contact:" + String.valueOf(grantResults[0] == PackageManager.PERMISSION_GRANTED));                Log.i("GRANT_RESULT", "Local:" + String.valueOf(grantResults[1] == PackageManager.PERMISSION_GRANTED));
                // OTHER WAY//                if(checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED){//                    Toast.makeText(this, "Deny", Toast.LENGTH_SHORT).show();//                }//                else {//                    Toast.makeText(this, "Allow", Toast.LENGTH_SHORT).show();//                }                break;            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);        }
    }




  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
                Intent intent = new Intent(MainActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });
 

Friday, November 27, 2015

Test

Nature and the Environment
Unit 3 Ants, Ants, Everywhere!

G: Hello, Mrs. Wilson. How are you?\n
W: I’m worried, Brianna. Thousands of ants are all over my patio!\n
G: That’s quite a problem. \n
W: What’s worse is that my daughter’s birthday party is in a few days and I wanted to have it on the patio. \n
G: Why don’t you call an exterminator?\n
W: I would, but I don’t want all those hazardous chemicals around my children. It’s harmful and unhealthy. I also don’t want dangerous substances
to seep into the garden. \n
G: I usually don’t have problems with ants, and I don’t use any chemicals. \n
W: What’s your secret?\n
G: Well, ants are difficult to control, so I planted a lot of mint plants near my deck. I also use cinnamon and cayenne pepper. I just sprinkle them around the places I don’t want ants. Some people have tried it and said it worked. Others said that they needed to try something else.\n
W: I think it’s worth a try. I would rather use cinnamon and mint around my patio than some hazardous chemicals. Besides, I don’t mind having the ants in the yard. I simply don’t want them coming to the birthday party. Would you mind helping me?\n
G: It would be a pleasure. I have a lot of cinnamon at home and I can run to the store to get the plants for you. \n
W: Thank you, Brianna. You’re such a thoughtful person.\n

Thursday, August 27, 2015

Thứ 5

Sắp cuối tuần rồi, nốt mai nữa :)))