Tag: android

如何在服务器上显示或使用从Android手机接收的图像

我正在从Android手机向服务器发送一个图像,但是现在我对如何在服务器中使用图像感到困惑 我发送图片的android手机代码是 Log.i(“sAMPLE”,”Info:” ); //String postURL = HOST_SERVER_URL + HOST_PHOTO_UPLOAD_URI; String postURL =”http://10.0.2.2:8080/SimpleServlet/simple-servlet”;//server URL HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(postURL); ByteArrayBody bab = new ByteArrayBody(imageBytes, “file_name_ignored”); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart(“source”, bab); postRequest.setEntity(reqEntity); HttpResponse response = httpClient.execute(postRequest); 我在服务器中处理图像的代码是这样的 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { boolean isMultipart […]

如何从Android应用程序访问Oracle数据库。

Android应用程序将在数据库服务器中显示来自外部数据库(Oracle)的数据。只能使用Web服务(RESTful) ,因此我决定使用Java / Java EE本身开发Web服务。 我不想使用PHP或其他一些技术。请建议我继续这个。

BitmapFactory.decodeFile返回null

我想从网络上的照片创建一个位图。 首先,我尝试使用BitmapFactory.decodeStream但由于存在错误而返回null(http://code.google.com/p/android/issues/detail?id=6066)。 现在我保存图像然后使用BitmapFactory.decodeFile但它仍然返回null。 任何想法是错误的还是其他解决方法? 谢谢! try { URL uri = new URL(“http://sofzh.miximages.com/java/scooter-dj-munchen.jpg”); URLConnection connection = uri.openConnection(); Log.i(TAG, “connecting…”); connection.connect(); InputStream is = connection.getInputStream(); //BufferedInputStream bis = new BufferedInputStream(is, 8 * 1024); File myfile = new File(getApplicationContext().getCacheDir(), “wallpaper.tmp”); myfile.createNewFile(); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(myfile)); byte buf[]=new byte[1024]; int len; while((len=is.read(buf))>0) out.write(buf,0,len); out.close(); is.close(); Log.d(TAG, String.valueOf(myfile.exists())); […]

如何更改字符串样式

我们可以将java中的String Style从normal更改为bold吗? 示例:我希望将字符串“Name”从普通样式更改为粗体样式。 java中包含的任何默认方法?

Android Java ServerSocket端口号不是它应该的

嗨,我正在进行android开发,并在使用套接字API时发现了一些奇怪的东西。 在我创建的套接字之间 ServerSocket server = new ServerSocket(4444); Socket client = server.accept(); 和 client.getPort(); 不是4444。 由于端口号几乎是随机的,因此客户端无法与服务器应用程序通信。 任何信息或建议都会有所帮助! 完整的示例项目在这里。 http://vext.eclipselabs.org.codespot.com/files/SocketTest.zip 提前致谢!

当我试图从mainactivity获取Fragment中的textview值时,我的应用程序无效

//这是Mainactivity java类,这里我从username获取edittext值 public class Home_Foodcourt extends AppCompatActivity implements View.OnClickListener { EditText username,userpassword; Button user_login; TextView user_register; FoodCourt_UserLoginDatabase foodCourt_userDatabase; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home__foodcourt); foodCourt_userDatabase=new FoodCourt_UserLoginDatabase(this); username=(EditText)findViewById(R.id.username); userpassword= (EditText) findViewById(R.id.loginpassword); user_login=(Button)findViewById(R.id.login_submit); user_register= (TextView) findViewById(R.id.user_newregister); user_register.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i=new Intent(Home_Foodcourt.this,FoodCourt_Register.class); startActivity(i); } }); user_login.setOnClickListener(this); } @Override public […]

SQLite查询:获取一行的所有列(android)?

这是架构: SQL查询是:SELECT * from unjdat,其中col_1 =“myWord”; 即,我想显示col_1为myWord的行的所有列。 int i; String temp; words = new ArrayList(); Cursor wordsCursor = database.rawQuery(“select * from unjdat where col_1 = \”apple\” “, null); //myWord is “apple” here if (wordsCursor != null) wordsCursor.moveToFirst(); if (!wordsCursor.isAfterLast()) { do { for (i = 0; i < 11; i++) { temp = wordsCursor.getString(i); words.add(temp); […]

从文件视图的url设置typeFace的任何方法?

我想从url中设置typeType,如: https : //github.com/anak10thn/frontend-homepage/raw/master/font/helvetica-regular.otf 你知道有什么办法吗? 我试过这个: Typeface tf = Typeface.createFromFile(“https://github.com/anak10thn/frontend-homepage/raw/master/font/helvetica-regular.otf”); tv.setTypeface(tf); 它不起作用。 我有这个错误: 03-24 04:46:59.931 1314-1314/bya.fchps.buildyourapp E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: bya.fchps.buildyourapp, PID: 1314 java.lang.RuntimeException: Unable to start activity ComponentInfo{bya.fchps.buildyourapp/com.fchps.buildyourapp.views.ClassicView}: java.lang.RuntimeException: native typeface cannot be made at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) […]

使用Scribe在LinkedIn中发布消息,向LinkedIn发送消息

以下是发送post消息的代码。 在我的屏幕上,我有一个EditText部分,允许用户输入文本,当他们点击后,调用sendMessage函数。 我一直在回应中得到这个。 我也尝试过URLEncode.encode(有效载荷,“UTF-8”)来获取一个编码的字符串,以便添加到正文并且不起作用。 任何见解都会有所帮助。 04-19 18:24:50.570: D/response(693): 04-19 18:24:50.570: D/response(693): 400 04-19 18:24:50.570: D/response(693): 1334859891007 04-19 18:24:50.570: D/response(693): WJPI8VXQME 04-19 18:24:50.570: D/response(693): 0 04-19 18:24:50.570: D/response(693): Couldn’t parse share document: error: Unexpected end of file after null 04-19 18:24:50.570: D/response(693): 这是代码: private static final String SendMessage = “https://api.linkedin.com/v1/people/~/shares”; public void sendMessage(View view) { //Get […]

如何格式2016-02-12T15:23:20 + 02:00时间

我从我们的网络服务获得上述日期格式。 我对如何格式化日期有一个想法,我只是对它作为一个字符串的事实有问题。 我试过这个,但我需要将它作为String返回,这在某种程度上不是问题。 这是我尝试过但它引发了一个exception: java.text.ParseException:无法解析的日期:“2016-02-26T00:00:00 + 02:00”(偏移4处) 码: public static String formatDate(String unFormattedTime) { String formattedTime; try { SimpleDateFormat sdf = new SimpleDateFormat(“dd MMM HH:mm”); Date date = sdf.parse(unFormattedTime); formattedTime = sdf.format(date); return formattedTime; } catch (ParseException e) { e.printStackTrace(); } return “”; } 我怎么能用像dd MMM HH:mm这样的格式来格式化它?