我希望我的应用能够识别用户在手机屏幕上从右向左滑动的时间.
这该怎么做?
我的主要活动有一些代码,可以进行一些不应该被中断的数据库更改.我正在另一个线程中进行繁重的工作,并使用我设置为不可取消的进度对话框.但是,我注意到如果我旋转手机,它会重新启动对正在运行的进程非常不好的活动,并且我会收到强制关闭.
我想要做的是以编程方式禁用屏幕方向更改,直到我的进程完成,此时方向更改已启用.
我正在使用Android应用程序来显示网络错误.
NetErrorPage.java
package exp.app;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class NetErrorPage extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.neterrorlayout);
Button reload=(Button)findViewById(R.id.btnReload);
reload.setOnClickListener(this);
showInfoMessageDialog("Please check your network connection","Network Alert");
}
public void onClick(View arg0)
{
if(isNetworkAvailable())
{
Intent myIntent = new Intent((Activity)NetErrorPage.this, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
((Activity)NetErrorPage.this).startActivity(myIntent);
finish();
}
else
showInfoMessageDialog("Please check your network connection","Network Alert");
}
public …Run Code Online (Sandbox Code Playgroud) 我正在使用google place api并想要获取最近的餐厅和咖啡馆但是当我使用进度条获取该数据时出现一个错误
class LoadPlaces extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage(Html.fromHtml("<b>Search</b><br/>Loading Places..."));
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting Places JSON
* */
protected String doInBackground(String... args) {
// creating Places class object
googlePlaces = new GooglePlaces();
try {
// Separeate your place types by PIPE symbol "|"
// If you want all types places make it as null …Run Code Online (Sandbox Code Playgroud) 我正在创建一个需要将大图像解码为位图的应用程序,以便在ImageView中显示.
如果我只是尝试将它们直接解码为位图,我会收到以下错误"位图太大而无法上传到纹理中(1944x2592,max = 2048x2048)"
因此,为了能够使用以下方法显示分辨率过高的图像:
Bitmap bitmap = BitmapFactory.decodeFile(path);
if(bitmap.getHeight()>=2048||bitmap.getWidth()>=2048){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
bitmap =Bitmap.createScaledBitmap(bitmap, width, height, true);
}
Run Code Online (Sandbox Code Playgroud)
这有效,但我真的不想像现在的if语句那样对2048的最大值进行硬编码,但是我无法找到如何获得设备位图的最大允许大小
有任何想法吗?
如何将Facebook Connect和API与Android应用程序集成?
我正在使用eneter框架来处理我的android应用程序中的通信; 问题是当我尝试填充微调器时,将适配器设置为微调器会导致未定义的异常
这里的代码
public void populateSpinner(TypedResponseReceivedEventArgs<String> arg1){
List<String> list = new ArrayList<String>();
String listf = arg1.getResponseMessage();
//sendToDebug(listf);
StringTokenizer tokenizer = new StringTokenizer(listf,",");
while(tokenizer.hasMoreElements()){
list.add((String)tokenizer.nextElement());
}
//EditText text = (EditText)findViewById(R.id.number2EditText);
//text.setText(list.size());
//text.setText(listf);
Spinner forfait = (Spinner)findViewById(R.id.forfaitsSpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
forfait.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud) 我想发送包含电子邮件和姓名等视频和数据的多部分表单.以下是我的代码,它不起作用,没有来自服务器的响应
File file =new File(VideoPath);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Name", "LDGHT"));
nameValuePairs.add(new BasicNameValuePair("Email", "hhh@example.com"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.setEntity(new FileEntity(file, "video/mp4"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
Run Code Online (Sandbox Code Playgroud) 我看了整个互联网,似乎无法找到我正在寻找...
我只是想找到一个网站,上面有一些关于如何使用OFFICIAL facebook android SDK的例子http://github.com/facebook/facebook-android-sdk
具体来说,我想看一些关于通知使用和简单照片上传的例子.但我会采取任何措施来帮助您了解使用SDK.
如果有人知道任何例子,请分享非常感谢!
我想在SD卡上创建一个sqlite数据库(不想用尽用户的内部存储).我熟悉OpenHelper模式:
public DatabaseFoo(Context context) {
OpenHelper openHelper = new OpenHelper(context);
mDb = openHelper.getWritableDatabase();
}
private static class OpenHelper extends SQLiteOpenHelper {
public OpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
...
Run Code Online (Sandbox Code Playgroud)
所以,如果我们想在SD卡上创建,我认为我们必须使用:
public static SQLiteDatabase openOrCreateDatabase (String path,
SQLiteDatabase.CursorFactory factory);
Run Code Online (Sandbox Code Playgroud)
但是什么是"工厂"的说法,应该使用什么工厂?
还有点担心如果用户在我的应用程序正在使用时删除SD卡会发生什么.
谢谢