Skip to content

Instantly share code, notes, and snippets.

@aberteau
Last active December 5, 2017 15:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aberteau/c41d8b42056b97cda4958c6e97d6401c to your computer and use it in GitHub Desktop.
Save aberteau/c41d8b42056b97cda4958c6e97d6401c to your computer and use it in GitHub Desktop.
Android Things - How to exit Android Date Settings screen (stackoverflow.com/questions/46138662)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.techeasy.androidsamples.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
<Button
android:id="@+id/show_datesettings_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date Settings" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.techeasy.androidsamples">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.IOT_LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.things"/>
</application>
</manifest>
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.techeasy.androidsamples"
minSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
provided 'com.google.android.things:androidthings:0.5-devpreview'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
package com.techeasy.androidsamples;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import java.util.Calendar;
public class MainActivity extends Activity implements View.OnClickListener {
private static final String TAG = "MainActivity";
private Button showDateSettingsButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDateSettingsButton = findViewById(R.id.show_datesettings_btn);
showDateSettingsButton.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if(view == showDateSettingsButton){
showDateSettings();
}
}
private void showDateSettings() {
startActivityForResult(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS), 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment