안드로이드 BItmap ImageView Drawable

Programming/Android 2013. 5. 16. 23:37 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

안드로이드 BItmap ImageView Drawable


Bitmap to ImageView


imageView.setImageBitmap(bitmap)


Resource to ImageView


imgView.setBackgroundResource(R.drawable.img1);



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

카메라 인텐트로 띄운후 해당 이미지 ImageView에 띄우기


1. 카메라 인텐트 띄우기


Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);


2. 갤러리 인텐트 띄우기



Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 2);

인텐트 후 Image 불러오기




	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if (resultCode == RESULT_OK)
		{
			if (requestCode == 1) // 1 은 위에서 startActivityForResult(intent, 1);
			{
				ImageView imageView1 = (ImageView)findViewById(R.id.imageView1);
				Bitmap bm = (Bitmap) data.getExtras().get("data");
				imageView1.setImageBitmap(bm);
			}
		}
	}

'Programming > Android' 카테고리의 다른 글

Android SQLite Select Where And &  (0) 2013.05.17
안드로이드 BItmap ImageView Drawable  (0) 2013.05.16
Intent 정리  (0) 2013.05.09
파일 이름 일괄 변경 DarkNamer  (0) 2013.05.05
MyLocation Class  (0) 2013.05.04

Intent 정리

Programming/Android 2013. 5. 9. 21:19 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
//show webapp:

Uri uri = Uri.parse("http://www.google.com");
Intent it  = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

//show maps:
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it); 

//show ways
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);

//call dial program
Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);  
startActivity(it);  

Uri uri = Uri.parse("tel.xxxxxx");
Intent it =new Intent(Intent.ACTION_CALL,uri);
//don't forget add this config:

//send sms/mms
//call sender program
Intent it = new Intent(Intent.ACTION_VIEW);   
it.putExtra("sms_body", "The SMS text");   
it.setType("vnd.android-dir/mms-sms");   
startActivity(it);  

//send sms
Uri uri = Uri.parse("smsto:0800000123");   
Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
it.putExtra("sms_body", "The SMS text");   
startActivity(it);  

//send mms
Uri uri = Uri.parse("content://media/external/images/media/23");   
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra("sms_body", "some text");   
it.putExtra(Intent.EXTRA_STREAM, uri);   
it.setType("image/png");   
startActivity(it); 

//send email
 
Uri uri = Uri.parse("mailto:xxx@abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);

Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");   
it.putExtra(Intent.EXTRA_TEXT, "The email body text");   
it.setType("text/plain");   
startActivity(Intent.createChooser(it, "Choose Email Client"));  

Intent it=new Intent(Intent.ACTION_SEND);     
String[] tos={"me@abc.com"};     
String[] ccs={"you@abc.com"};     
it.putExtra(Intent.EXTRA_EMAIL, tos);     
it.putExtra(Intent.EXTRA_CC, ccs);     
it.putExtra(Intent.EXTRA_TEXT, "The email body text");     
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");     
it.setType("message/rfc822");     
startActivity(Intent.createChooser(it, "Choose Email Client"));   


//add extra
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");   
sendIntent.setType("audio/mp3");   
startActivity(Intent.createChooser(it, "Choose Email Client"));

//play media
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);

Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");   
Intent it = new Intent(Intent.ACTION_VIEW, uri);   
startActivity(it);  

//Uninstall
Uri uri = Uri.fromParts("package", strPackageName, null);   
Intent it = new Intent(Intent.ACTION_DELETE, uri);   
startActivity(it);

//uninstall apk
Uri uninstallUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);

//install apk
Uri installUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);

//play audio
Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
returnIt = new Intent(Intent.ACTION_VIEW, playUri);

//send extra
Intent it = new Intent(Intent.ACTION_SEND);  
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3");  
sendIntent.setType("audio/mp3");  
startActivity(Intent.createChooser(it, "Choose Email Client"));

//search
Uri uri = Uri.parse("market://search?q=pname:pkg_name");  
Intent it = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(it);  
//where pkg_name is the full package path for an application  

//show program detail page
Uri uri = Uri.parse("market://details?id=app_id");  
Intent it = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(it);  
//where app_id is the application ID, find the ID  
//by clicking on your application on Market home  
//page, and notice the ID from the address bar


//search google
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);


Android Battery Monitor

Programming/Android 2013. 4. 29. 18:43 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Android Battery Monitor Code


batteryUsePerSec 를 수정하여 사용하세요



	public TextView batteryUsePerSec; // 배터리 Text View

	public void onCreate(Bundle savedInstanceState) {
		......
		batteryUsePerSec = (TextView) findViewById(R.id.batteryUsePerSec);
		......
        }

	public void onResume() {
		......
		IntentFilter filter = new IntentFilter();
		filter.addAction(Intent.ACTION_BATTERY_CHANGED);
		registerReceiver(mBRBattery, filter);
		......
	}

	BroadcastReceiver mBRBattery = new BroadcastReceiver()
	{

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_BATTERY_CHANGED))
			{
				onBatteryChanged(intent);
			}
		}

		private void onBatteryChanged(Intent intent) {
			// TODO Auto-generated method stub
			int scale, level, ratio;
			scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
			level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100);
			ratio = level * 100 / scale;
			
			batteryUsePerSec.setText(ratio + "");
			Log.d(ActivityTag, "onBatteryChanged()" + ratio);
		}
		
	};


'Programming > Android' 카테고리의 다른 글

파일 이름 일괄 변경 DarkNamer  (0) 2013.05.05
MyLocation Class  (0) 2013.05.04
Android google Map v2  (2) 2013.04.27
안드로이드 APK 추출하기  (0) 2013.04.25
Thread 와 Handler 테스트  (0) 2013.04.13

JAVA MYSQL ANDROID REST 활용

Programming/JAVA,JSP 2013. 4. 28. 17:15 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
REST 사용방법 http://192.168.0.3:8182/books http://192.168.0.3:8182/books/where/OReilly http://192.168.0.3:8182/books/ insert/"제목"/"저자"/"가격' REST 서버
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;

public class test extends Application {
	public static Connection makeConnection() {
		String url = "jdbc:mysql://localhost:3307/book_db";
		String id = "root";
		String password = "green";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공");
		} catch (ClassNotFoundException e) {
			System.out.println("드라이버를 찾을 수 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패하였습니다.");
		}
		return con;
	}

	public static Statement stmt;

	public static void main(String[] args) throws Exception {
		Connection con = makeConnection();
		stmt = con.createStatement();
		Server server = new Server(Protocol.HTTP, 8182);
		server.setNext(new test());
		server.start();
	}

	public static String selectBooks(Statement stmt) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM books");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			String publisher = rs.getString("publisher");
			String year = rs.getString("year");
			if (title != null) {
				result += id + " " + title + " " + publisher + " " + year
						+ "\n";
			}
		}
		return result;
	}

	public static String selectBooks(Statement stmt, String name)
			throws SQLException {
		ResultSet rs = stmt
				.executeQuery("SELECT * FROM books WHERE publisher = '" + name
						+ "'");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			String publisher = rs.getString("publisher");
			String year = rs.getString("year");
			if (title != null) {
				result += id + " " + title + " " + publisher + " " + year
						+ "\n";
			}
		}
		return result;
	}

	@Override
	public Restlet createInboundRoot() {
		Router router = new Router();
		router.attach("http://localhost:8182/books", restlet1);
		router.attach("http://localhost:8182/books/where/{name}", restlet2);
		router.attach(
				"http://localhost:8182/books/insert/{title}/{publisher}/{year}/{price}",
				restlet3);
		router.attach("http://localhost:8182/datas/{year}/{month}/{day}",
				restlet4);
		router.attach("http://192.168.0.3:8182/books", restlet1);
		router.attach("http://192.168.0.3:8182/books/where/{name}", restlet2);
		router.attach(
				"http://192.168.0.3:8182/books/insert/{title}/{publisher}/{year}/{price}",
				restlet3);
		router.attach("http://192.168.0.3:8182/datas/{year}/{month}/{day}",
				restlet4);
		// (title, publisher, year, price)
		return router;
	}

	public Restlet restlet4 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String year = (String) request.getAttributes().get("year");
			String month = (String) request.getAttributes().get("month");
			String day = (String) request.getAttributes().get("day");

			String message = "";
			try {
				message += selectDatas(stmt, year, month, day);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};

	public static String selectDatas(Statement stmt, String year, String month,
			String day) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM datas WHERE year = "
				+ year + " && month =" + month + "&& day=" + day + ";");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("data_id");
			String contents = rs.getString("contents");
			if (contents != null) {
				result += id + " " + year + " " + month + " " + day + " "
						+ contents + "\n";
			}
		}
		return result;
	}

	public Restlet restlet3 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String title = (String) request.getAttributes().get("title");
			String publisher = (String) request.getAttributes()
					.get("publisher");
			String year = (String) request.getAttributes().get("year");
			String price = (String) request.getAttributes().get("price");
			try {
				insertBooks(stmt, title, publisher, year, price);
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}

		private void insertBooks(Statement stmt, String title,
				String publisher, String year, String price)
				throws SQLException {
			// TODO Auto-generated method stub
			// INSERT INTO books (title, publisher, year, price)
			// VALUES('Operating System Concepts', 'Wiley', '2003', 30700);
			stmt.execute("INSERT INTO books (title, publisher, year, price)"
					+ "VALUES('" + title + "','" + publisher + "','" + year
					+ "'," + price + ");");
		}
	};

	public Restlet restlet2 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String name = (String) request.getAttributes().get("name");
			String message = "";
			try {
				message += selectBooks(stmt, name);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
	public Restlet restlet1 = new Restlet() {
		public void handle(Request request, Response response) {
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
}

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA JNI  (0) 2013.05.01
Eclipse Tips  (0) 2013.04.30
JAVA MYSQL 활용 4 Android App  (0) 2013.04.28
JAVA MYSQL 활용 3  (0) 2013.04.28
MYSQL REST 실습 코드 2  (0) 2013.04.28

테이블 동적 생성

Programming/Android 2013. 3. 23. 20:02 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

public class MainActivity extends Activity {

 

        @Override

        protected void onCreate(Bundle savedInstanceState) {

               super.onCreate(savedInstanceState);

               setContentView(R.layout.activity_main);

 

               /* Find Tablelayout defined in main.xml */

               TableLayout tl = (TableLayout) findViewById(R.id.store_table);

              

               /* Create a new row to be added. */

               for (int i = 0; i < 3; i++) {

                       TableRow tr = new TableRow(this);

                       tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,

                                      LayoutParams.WRAP_CONTENT));

                      

                       /* Create a Button to be the row-content. */

                       Button b = new Button(this);

                       b.setText("Dynamic Button");

                       b.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,

                                      LayoutParams.WRAP_CONTENT));

                      

                       /* Add Button to row. */

                      

                       tr.addView(b);

                       Button c = new Button(this);

                       c.setText("Dynamic Button2");

                       c.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,

                                      LayoutParams.WRAP_CONTENT));

                      

                       /* Add Button to row. */

                       tr.addView(c);

                      

                       /* Add row to TableLayout. */

                       tl.addView(tr, new TableLayout.LayoutParams(

                                      LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

               }

        }

}

'Programming > Android' 카테고리의 다른 글

안드로이드 APK 추출하기  (0) 2013.04.25
Thread 와 Handler 테스트  (0) 2013.04.13
TabActivity 사용법  (0) 2013.03.23
다중 액티비티 예제  (0) 2013.03.23
안드로이드 레이아웃 예제  (0) 2013.03.16

Intent 활용하기

Programming/Android 2013. 3. 8. 19:25 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

//show webapp:

 

Uri uri = Uri.parse("http://www.google.com");

Intent it  = new Intent(Intent.ACTION_VIEW,uri);

startActivity(it);

 

//show maps:

Uri uri = Uri.parse("geo:38.899533,-77.036476");

Intent it = new Intent(Intent.Action_VIEW,uri);

startActivity(it);

 

//show ways

Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");

Intent it = new Intent(Intent.ACTION_VIEW,URI);

startActivity(it);

 

//call dial program

Uri uri = Uri.parse("tel:xxxxxx");

Intent it = new Intent(Intent.ACTION_DIAL, uri); 

startActivity(it); 

 

Uri uri = Uri.parse("tel.xxxxxx");

Intent it =new Intent(Intent.ACTION_CALL,uri);

//don't forget add this config:

<uses-permission id="android.permission.CALL_PHONE" />

 

//send sms/mms

//call sender program

Intent it = new Intent(Intent.ACTION_VIEW);  

it.putExtra("sms_body", "The SMS text");  

it.setType("vnd.android-dir/mms-sms");  

startActivity(it); 

 

//send sms

Uri uri = Uri.parse("smsto:0800000123");  

Intent it = new Intent(Intent.ACTION_SENDTO, uri);  

it.putExtra("sms_body", "The SMS text");  

startActivity(it); 

 

//send mms

Uri uri = Uri.parse("content://media/external/images/media/23");  

Intent it = new Intent(Intent.ACTION_SEND);  

it.putExtra("sms_body", "some text");  

it.putExtra(Intent.EXTRA_STREAM, uri);  

it.setType("image/png");  

startActivity(it);

 

//send email

 

Uri uri = Uri.parse("mailto:xxx@abc.com");

Intent it = new Intent(Intent.ACTION_SENDTO, uri);

startActivity(it);

 

Intent it = new Intent(Intent.ACTION_SEND);  

it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");  

it.putExtra(Intent.EXTRA_TEXT, "The email body text");  

it.setType("text/plain");  

startActivity(Intent.createChooser(it, "Choose Email Client")); 

 

Intent it=new Intent(Intent.ACTION_SEND);    

String[] tos={"me@abc.com"};    

String[] ccs={"you@abc.com"};    

it.putExtra(Intent.EXTRA_EMAIL, tos);    

it.putExtra(Intent.EXTRA_CC, ccs);    

it.putExtra(Intent.EXTRA_TEXT, "The email body text");    

it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");    

it.setType("message/rfc822");    

startActivity(Intent.createChooser(it, "Choose Email Client"));  

 

 

//add extra

Intent it = new Intent(Intent.ACTION_SEND);  

it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  

it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");  

sendIntent.setType("audio/mp3");  

startActivity(Intent.createChooser(it, "Choose Email Client"));

 

//play media

Intent it = new Intent(Intent.ACTION_VIEW);

Uri uri = Uri.parse("file:///sdcard/song.mp3");

it.setDataAndType(uri, "audio/mp3");

startActivity(it);

 

Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");  

Intent it = new Intent(Intent.ACTION_VIEW, uri);  

startActivity(it); 

 

//Uninstall

Uri uri = Uri.fromParts("package", strPackageName, null);  

Intent it = new Intent(Intent.ACTION_DELETE, uri);  

startActivity(it);

 

//uninstall apk

Uri uninstallUri = Uri.fromParts("package", "xxx", null);

returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);

 

//install apk

Uri installUri = Uri.fromParts("package", "xxx", null);

returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);

 

//play audio

Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");

returnIt = new Intent(Intent.ACTION_VIEW, playUri);

 

//send extra

Intent it = new Intent(Intent.ACTION_SEND); 

it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); 

it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3"); 

sendIntent.setType("audio/mp3"); 

startActivity(Intent.createChooser(it, "Choose Email Client"));

 

//search

Uri uri = Uri.parse("market://search?q=pname:pkg_name"); 

Intent it = new Intent(Intent.ACTION_VIEW, uri); 

startActivity(it); 

//where pkg_name is the full package path for an application 

 

//show program detail page

Uri uri = Uri.parse("market://details?id=app_id"); 

Intent it = new Intent(Intent.ACTION_VIEW, uri); 

startActivity(it); 

//where app_id is the application ID, find the ID 

//by clicking on your application on Market home 

//page, and notice the ID from the address bar

 

 

//search google

Intent intent = new Intent();

intent.setAction(Intent.ACTION_WEB_SEARCH);

intent.putExtra(SearchManager.QUERY,"searchString")

startActivity(intent);

 


출처 : https://snipt.net/Martin/tag/android/

 

//카카오톡 메세지 Intent

    

    try {

       KakaoLink kakaoLink = KakaoLink

              .getLink(getApplicationContext());

   

       // check, intent is available.

       if (!kakaoLink.isAvailableIntent()) {

           return;

       }

       /**

        * @param activity

        * @param url

        * @param message

        * @param appId

        * @param appVer

        * @param appName

        * @param encoding

        */

       kakaoLink.openKakaoLink(

              MainActivity.this,

              "http://link.kakao.com/?test-android-app",

              "First KakaoLink Message for send url.",

              getPackageName(),

              getPackageManager().getPackageInfo(

                     getPackageName(), 0).versionName,

              "KakaoLink Test App", "UTF-8");

    } catch (Exception e) {

       // TODO Auto-generated catch block

       e.printStackTrace();

    }



KakaoLink.java


'Programming > Android' 카테고리의 다른 글

다중 액티비티 예제  (0) 2013.03.23
안드로이드 레이아웃 예제  (0) 2013.03.16
안드로이드 실습  (0) 2013.03.09
ubuntu 에 jdk 간편하게 설치하기  (0) 2013.02.27
R.java import 에러  (0) 2012.11.27