Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

August 3, 2012

[SOLVED]Connect Nexus 7 and/or Galaxy Nexus to ubuntu

You want to develop on your new shiny Nexus 7 and
adb devices

keeps giving you
???????? device

oprn your rules file
gksu gedit /etc/udev/rules.d/51-android.rules

probably you will see following line (if you already configured your Galaxy nexus) If not add it to the file, just in case
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="YOUR_USER_ID"

Now we should get the idVendor and idProduct from the Nexus 7. Connect it to your computer and
lsusb

you will see something like
Bus 001 Device 013: ID 18d1:4e42 Google Inc.

we need this two values

paste this string with proper values to 51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0666", OWNER="YOUR_USER_ID"

Save the file. Do the
sudo service udev restart

Now run
adb devices

you should see your device
List of devices attached
015d172c98280c0b device

Happy developing

Source: http://govfate.iteye.com/blog/1608379

January 9, 2011

[SOLVED] Android: Get an string array from an array.xml resource

Here you can see how to retrieve values from array.xml
Log.i("test",getImageQualityAsString(1));

array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="image_export_list_preference">
<item>480x320</item>
<item>800x480</item>
<item>1024x768</item>
</string-array>
<string-array name="entryvalues_image_export_list_preference">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>

Function:
private String getImageQualityAsString(int sizeItem){

try {
String[] bases = getResources().getStringArray(R.array.image_export_list_preference);

return bases[sizeItem];

} catch (Exception e) {
return "";
}

}

Source: stackoverflow.com

December 9, 2010

[SOLVED] PHP: Why 2 !=2 aka "never compare floating point numbers for equality"

“never compare floating point numbers for equality”.

The reason (19.6*100) !== (double)1960, is because inside a computer they are not equal.

Try this:

<?php

printf("%.15f", (19.6*100));

?>

Outputs: 1960.000000000000227 (not 1960 as somewhat expected)

If comparison is required a few options come to mind (other than BCMath):

1) Round numbers before comparison:

<?php

$sig_figs = 5;
echo (round((19.6*100), $sig_figs) !== round((double)1960, $sig_figs)) ? 'not equal' : 'equal';

?>

Outputs: equal

Source: php.net

November 16, 2010

[SOLVED] Android - Arrange two buttons next to each other and to center them horizontally.

Arrange two buttons next to each other and to center them horizontally.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="horizontal"
    android:background="@android:drawable/bottom_bar" android:paddingLeft="4.0dip"
    android:paddingTop="5.0dip" android:paddingRight="4.0dip"
    android:paddingBottom="1.0dip" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_below="@+id/TextView01">
    <Button android:id="@+id/allow" android:layout_width="0.0dip"
        android:layout_height="fill_parent" android:text="Allow"
        android:layout_weight="1.0" />
    <Button android:id="@+id/deny" android:layout_width="0.0dip"
        android:layout_height="fill_parent" android:text="Deny"
        android:layout_weight="1.0" />
</LinearLayout>

 

Source: stackoverflow.com

November 15, 2010

July 27, 2010

[SOLVED] PHP: How upload file using cURL?


<?php
$request_url = ‘http://www.akchauhan.com/test.php’;
$post_params['name'] = urlencode(’Test User’);
$post_params['file'] =@.'demo/testfile.txt’;
$post_params['
submit'] = urlencode(’submit’);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$result = curl_exec($ch);
curl_close($ch);
?>


Source: How upload file using cURL?.

May 23, 2010

[SOLVED] Show web pages in Activity -Hello, WebView

WebView allows you to create your own web browser Activity. In this tutorial, we'll create a simple Activity that can view web pages.

Source: Hello, WebView | Android Developers.

May 9, 2010

[SOLVED] Android: Set Admob programmatically into test mode


(6) When integrating AdMob ads into your application it is recommended to use test mode. In test mode test, ads are always returned.


Test mode is enabled on a per-device basis. To enable test mode for a device, first request an ad, then look in LogCat for a line like the following:



  To get test ads on the emulator use AdManager.setTestDevices...

Once you have the device ID you can enable test mode by calling AdManager.setTestDevices:



  AdManager.setTestDevices( new String[] {                 
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );



Source: Android - Admob For Developers.

May 5, 2010

[SOLVED] Android: How to stress/test your app with random streams of user events

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.


$ adb shell monkey -p your.package.name -v 500



UI/Application Exerciser Monkey Android Developers.

May 1, 2010

[SOLVED] Error on creating custom dialog

> Use dialog = new Dialog(this);
> instead of
> dialog = new Dialog(getApplicationContext());


private void showAbout() {
showDialog(DIALOG_ABOUT_ID);
}

protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_ABOUT_ID:
dialog = new Dialog(this);

dialog.setContentView(R.layout.about);
dialog.setTitle("Custom Dialog");
dialog.setOwnerActivity(this);

TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_contact_picture);

break;
// case DIALOG_GAMEOVER_ID:
// // do the work to define the game over Dialog
// break;
default:
dialog = null;
}
return dialog;
}






Source: Custom Dialog - Android Developers | Google Groups.

[SOLVED]Android: How to Make an Activity Fullscreen



  1. public class FullScreen extends Activity {

  2. @Override

  3. public void onCreate(Bundle savedInstanceState) {

  4. super.onCreate(savedInstanceState);


  5. requestWindowFeature(Window.FEATURE_NO_TITLE);

  6. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

  7. WindowManager.LayoutParams.FLAG_FULLSCREEN);


  8. setContentView(R.layout.main);

  9. }

  10. }




Source: Android Snippets: How to Make an Activity Fullscreen.

April 29, 2010

[SOLVED] Android: Convert dip to px.


It uses pixels, but I'm sure you're wondering how to use dips instead. The answer is inTypedValue.applyDimension()Here's an example of how to convert dips to px in code:



// Converts 14 dip into its equivalent px
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics());



Source: Does setWidthint pixels use dip or px? - Stack Overflow.

January 7, 2010

[SOLVED]Using jQuery with Other Libraries


<html>
<head>
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
var $j = jQuery.noConflict();

// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});

// Use Prototype with $(...), etc.
$('someid').hide();
</script>
</head>
<body></body>
</html>


via Using jQuery with Other Libraries - jQuery JavaScript Library.

January 3, 2010

[SOLVED]Attach a file from SD Card to email




Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent
.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "user@host.com" });
sendIntent
.putExtra(Intent.EXTRA_SUBJECT, "Photo");
sendIntent
.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/dcim/Camera/filename.jpg"));
sendIntent
.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity
(Intent.createChooser(sendIntent, "Email:"));


Trying to attach a file from SD Card to email - Stack Overflow.

[SOLVED] Set Screen Orientation Programmatically


There are times where you need to ensure that your application is displayed only in a certain orientation. For example, suppose you are writing a game that should only be viewed in landscape mode. In this case, you can programmatically force a change in orientation using the setRequestOrientation() method of the Activity class:

package net.learn2develop.OrientationAware;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

public class Orientation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//---change to landscape mode---
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}

To change to portrait mode, use the ActivityInfo.SCREEN_ORIENTATION_PORTRAIT constant:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);




Developing Orientation-Aware Android Applications.