Android Studio add library dependencies to module project
- File->Project Structure Ctrl + Alt + Shift + S
- Select module and Dependencies Tab
- Click on + PLUS button (right upper corner)
- Select library
Click OK, OK
396LW NO topic_id
AD
Další témata ....(Topics)
In your project AndroidManifest.xml you can set permission of Android application example source code.
For example if you want allow your application connection to INTERNET you have to permit this in AndroidManifest.xml.
WebViev show error: Website Not Available you have to permit INTERNET
For example if you want allow your application connection to INTERNET you have to permit this in AndroidManifest.xml.
WebViev show error: Website Not Available you have to permit INTERNET
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.GET_ACCOUNTS" />
<uses-permission
android:name="android.permission.USE_CREDENTIALS" />
<uses-permission
android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission
android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS" />
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission
android:name="android.permission.READ_CONTACTS" />
<uses-permission
android:name="android.permission.WRITE_CONTACTS" />
<uses-permission
android:name="android.permission.READ_SYNC_STATS" />
<uses-permission
android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission
android:name="android.permission.WRITE_SYNC_SETTINGS" />
Update TextView by runnable. Handler, runnable, timer Android example.
main.xml
public class TimerActivity extends Activity {
TextView hTextView;
Button hButton, hButtonStop;
private Handler mHandler = new Handler();
private int nCounter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hTextView = (TextView)findViewById(R.id.idTextView);
hButton = (Button)findViewById(R.id.idButton);
hButton.setOnClickListener(mButtonStartListener);
hButtonStop = (Button)findViewById(R.id.idButtonStop);
hButtonStop.setOnClickListener(mButtonStopListener);
} // end onCreate
View.OnClickListener mButtonStartListener = new OnClickListener() {
public void onClick(View v) {
try {
mHandler.removeCallbacks(hMyTimeTask);
// Parameters
// r The Runnable that will be executed.
// delayMillis The delay (in milliseconds) until the Runnable will be executed.
mHandler.postDelayed(hMyTimeTask, 1000); // delay 1 second
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
private Runnable hMyTimeTask = new Runnable() {
public void run() {
nCounter++;
hTextView.setText("Hallo from thread counter: " + nCounter);
}
};
/**
*
*/
View.OnClickListener mButtonStopListener = new OnClickListener() {
public void onClick(View v) {
mHandler.removeCallbacks(hMyTimeTask);
}
};
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/idTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:text="Button"
android:id="@+id/idButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/idButtonStop"
android:text="Stop"></Button>
</LinearLayout>
Generate random number Android Java example source code.
Random rand = new Random();
int i = rand.nextInt() % 256; // range -255 +255
System.out.print(i + "
"); // -184
i = Math.abs(rand.nextInt() % 12); // range 0 +11
System.out.print(i); // 7
// Math.random() start with 0. e.g. 0.35981234
int nRan = (int) (Math.random()*10); // 0 - 10
// nextDouble(), nextFloat(), nextInt(), nextLong() returns 0 - 10
import java.util.Random;´
Random r = new Random();
int nRan = r.nextInt(); // 0 - 10
double dRan = r.nextDouble() * 10; // e.g. 7.496285271597397
nextDouble – return 0 - 1
nextFloat – same as double
nextInt – -2147483648 +2147483647
nextLong – -922337203685775808 +9223372036854775807
nextGaussian – 0.0 aberation 1.0.
How to resize an image in ImageView Android source code.
Resize imageview layout and image will resize too:
Resize imageview layout and image will resize too:
public void resizeImageView(int width, int height) {
final ImageView picture1 = (ImageView)findViewById(R.id.imageView1);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, height);
picture1.setLayoutParams(layoutParams);
}
You can get list by class Build
For example:
List of Build class getting from emulator:
"BOARD=unknown
BRAND=generic
CPU_ABI=armeabi
DEVICE=generic
DISPLAY=sdk-eng 2.1-update1 ECLAIR 35983 test-keys
FINGERPRINT=generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys
HOST=android-test-13.mtv.corp.google.com
ID=ECLAIR
MANUFACTURER=unknown
MODEL=sdk
PRODUCT=sdk
TAGS=test-keys
TIME=1273161972000
TYPE=eng
USER=android-build
"
For example:
if(Build.MANUFACTURER.equals("unknown")) {
// Emulator
}
List of Build class getting from emulator:
"BOARD=unknown
BRAND=generic
CPU_ABI=armeabi
DEVICE=generic
DISPLAY=sdk-eng 2.1-update1 ECLAIR 35983 test-keys
FINGERPRINT=generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys
HOST=android-test-13.mtv.corp.google.com
ID=ECLAIR
MANUFACTURER=unknown
MODEL=sdk
PRODUCT=sdk
TAGS=test-keys
TIME=1273161972000
TYPE=eng
USER=android-build
"
Editace: 2015-11-27 11:35:10
Počet článků v kategorii: 396
Url:android-studio-add-library-dependencies-to-module-project