- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 JSON 将数据提取到列表中,并允许用户选择列表项并使用在列表上单击的项目准备文件夹名称,例如:事件 + 名称_日期
举个例子:- 本田汽车_A-05-12-2013
现在我显示相机和 2 个按钮,即:- 查看图库和捕获图像
允许用户捕捉,并在 CaptureImages 目录中创建一个文件夹,名称为:Honda Motors Event_A-05-12-2013
现在,一旦用户点击“查看图库”按钮,就会显示本田汽车 Event_A-05-12-2013 中可用的图像列表,在图库 Activity 中,我还提供返回按钮以返回并捕获更多图像,但是这里我遇到了问题
每当用户返回并拍摄图像时,不要将这些图像放入 Honda Motors Event_A-05-12-2013 文件夹,而是将其保存在另一个文件夹中,文件夹名称如:null Event_null-05-12-2013
CameraLauncherActivity.java:-
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
mCamera = getCameraInstance();
mCameraPreview = new PreviewSurface(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mCameraPreview);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("folder_name");
Log.d(CameraLauncherActivity.LOG_TAG, "folder_name :: " + value);
}
Button captureButton = (Button) findViewById(R.id.btnCapture);
Log.d(CameraLauncherActivity.LOG_TAG, "captureButton :: " + captureButton);
captureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCamera.takePicture(null, null, mPicture);
Log.d(CameraLauncherActivity.LOG_TAG, "mCamera.takePicture :: " + mCamera);
}
});
Button viewButton = (Button) findViewById(R.id.btnView);
Log.d(CameraLauncherActivity.LOG_TAG, "SingleAngelActivityButton :: " + viewButton);
viewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentNewEvent = new Intent(CameraLauncherActivity.this, UploadActivity.class);
String event_id = customFolder;
intentNewEvent.putExtra("event_id", event_id);
startActivity(intentNewEvent);
}
});
cd = new ConnectionDetector(getApplicationContext());
// Check if Internet present
if (!cd.isConnectingToInternet()) {
// Internet Connection is not present
alert.showAlertDialog(CameraLauncherActivity.this, "Internet Connection Error",
"Please connect to working Internet connection", false);
// stop executing code by return
return;
}
// Get event id, angel id
Intent i = getIntent();
event_id = i.getStringExtra("event_id");
angel_id = i.getStringExtra("angel_id");
// calling background thread
new LoadSingleTrack().execute();
}
/**
* Background Async Task to get single angel information
* */
class LoadSingleTrack extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(CameraLauncherActivity.this);
pDialog.setMessage("Initializing Camera...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting angel json and parsing
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// post event id, angel id as GET parameters
params.add(new BasicNameValuePair("event", event_id));
params.add(new BasicNameValuePair("angel", angel_id));
// getting JSON string from URL
String json = jsonParser.makeHttpRequest(URL_angel, "GET",
params);
// Check your log cat for JSON reponse
Log.d("Single Track JSON: ", json);
try {
JSONObject jObj = new JSONObject(json);
if(jObj != null){
angel_name = jObj.getString(TAG_ANGEL);
event_name = jObj.getString(TAG_EVENT);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting angel information
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
TextView txt_angel_name = (TextView) findViewById(R.id.angel_title);
String timeStamp = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
txt_angel_name.setText(event_name + " Event_"+ angel_name + "-" + timeStamp);
customFolder = txt_angel_name.getText().toString();
Log.d(CameraLauncherActivity.LOG_TAG, "customFolder :: " + customFolder);
// Change Activity Title with angel title
setTitle(angel_name);
// folder name
mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"/CaptureImages/"+ customFolder + "/");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("App", "failed to create directory");
}
}
}
});
}
}
/**
* Helper method to access the camera returns null if it cannot get the
* camera or does not exist
*
* @return
*/
private Camera getCameraInstance() {
Camera camera = null;
Log.d(CameraLauncherActivity.LOG_TAG, "getCameraInstance()Camera:: " + camera);
try {
camera = Camera.open(0);
Log.d(CameraLauncherActivity.LOG_TAG, "getCameraInstance()open:: " + camera);
} catch (Exception e) {
// cannot get camera or does not exist
}
return camera;
}
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
pictureFile = getOutputMediaFile();
camera.startPreview();
if (pictureFile == null) {
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
};
static File getOutputMediaFile() {
/* yyyy-MM-dd'T'HH:mm:ss.SSSZ */
timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
// file name
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
return mediaFile;
}
上传.java:-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
// Permission StrictMode
if (android.os.Build.VERSION.SDK_INT > 9)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
TextView textHeading = (TextView) findViewById(R.id.txtEventNameDate);
textHeading.setText(CameraLauncherActivity.customFolder);
final Button button = (Button) findViewById(R.id.buttonBack);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Intent i = new Intent(getApplicationContext(), CameraLauncherActivity.class);
i.putExtra("folder_name", CameraLauncherActivity.customFolder);
startActivity(i);
}
});
/*** Get Images from SDCard ***/
ImageList = getSD();
// ListView and imageAdapter
lstView = (ListView) findViewById(R.id.listView1);
lstView.setAdapter(new ImageAdapter(this));
}
private List <String> getSD()
{
List <String> it = new ArrayList <String>();
String string = "/mnt/sdcard/Pictures/CaptureImages/";
File f = new File (string+ CameraLauncherActivity.customFolder+ "/");
File[] files = f.listFiles ();
for (int i = 0; i <files.length; i++)
{
File file = files[i];
Log.d("Count",file.getPath());
it.add (file.getPath());
}
return it;
}
}
日志:-
12-05 00:12:54.091: I/Choreographer(2284): Skipped 76 frames! The application may be doing too much work on its main thread.
12-05 00:13:08.520: D/CameraLauncherActivity(2284): getCameraInstance()Camera:: null
12-05 00:13:09.380: D/CameraLauncherActivity(2284): getCameraInstance()open:: android.hardware.Camera@41777870
12-05 00:13:09.380: D/CameraLauncherActivity(2284): folder_name :: Honda Motors Event_Angel A-05-12-2013
12-05 00:13:09.390: D/CameraLauncherActivity(2284): captureButton :: android.widget.Button{419fe4d8 VFED..C. ......I. 0,0-0,0 #7f090004 app:id/btnCapture}
12-05 00:13:09.390: D/CameraLauncherActivity(2284): SingleAngelActivityButton :: android.widget.Button{419b2678 VFED..C. ......I. 0,0-0,0 #7f090002 app:id/btnView}
12-05 00:13:09.790: I/Choreographer(2284): Skipped 36 frames! The application may be doing too much work on its main thread.
12-05 00:13:10.490: I/Choreographer(2284): Skipped 169 frames! The application may be doing too much work on its main thread.
12-05 00:13:13.170: W/System.err(2284): org.json.JSONException: End of input at character 0 of
12-05 00:13:14.580: I/Choreographer(2284): Skipped 112 frames! The application may be doing too much work on its main thread.
12-05 00:13:14.660: W/System.err(2284): at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
12-05 00:13:15.070: W/System.err(2284): at org.json.JSONTokener.nextValue(JSONTokener.java:97)
12-05 00:13:15.070: W/System.err(2284): at org.json.JSONObject.<init>(JSONObject.java:154)
12-05 00:13:15.070: W/System.err(2284): at org.json.JSONObject.<init>(JSONObject.java:171)
12-05 00:13:15.150: W/System.err(2284): at com.example.camera.CameraLauncherActivity$LoadSingleTrack.doInBackground(CameraLauncherActivity.java:195)
12-05 00:13:15.280: W/System.err(2284): at com.example.camera.CameraLauncherActivity$LoadSingleTrack.doInBackground(CameraLauncherActivity.java:1)
12-05 00:13:15.400: W/System.err(2284): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-05 00:13:15.540: W/System.err(2284): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-05 00:13:15.690: W/System.err(2284): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-05 00:13:15.690: W/System.err(2284): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-05 00:13:15.690: W/System.err(2284): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-05 00:13:15.730: I/Choreographer(2284): Skipped 41 frames! The application may be doing too much work on its main thread.
12-05 00:13:15.980: I/Choreographer(2284): Skipped 64 frames! The application may be doing too much work on its main thread.
12-05 00:13:16.181: W/System.err(2284): at java.lang.Thread.run(Thread.java:841)
12-05 00:13:16.290: I/Choreographer(2284): Skipped 72 frames! The application may be doing too much work on its main thread.
12-05 00:13:16.560: I/Choreographer(2284): Skipped 68 frames! The application may be doing too much work on its main thread.
12-05 00:13:21.020: D/CameraLauncherActivity(2284): mCamera.takePicture :: android.hardware.Camera@41777870
12-05 00:13:24.110: D/Count(2284): /mnt/sdcard/Pictures/CaptureImages/null Event_null-05-12-2013/IMG_20131205_001321.jpg
12-05 00:13:25.480: D/dalvikvm(2284): GC_FOR_ALLOC freed 147K, 3% free 10392K/10656K, paused 426ms, total 464ms
12-05 00:13:26.340: I/Choreographer(2284): Skipped 493 frames! The application may be doing too much work on its main thread.
将日志添加到自定义文件夹后:-
12-05 01:32:53.360: I/Choreographer(8354): Skipped 79 frames! The application may be doing too much work on its main thread.
12-05 01:32:53.661: D/CameraLauncherActivity(8354): customFolder :: Honda Motors Event_Angel A-05-12-2013
12-05 01:32:53.830: I/Choreographer(8354): Skipped 124 frames! The application may be doing too much work on its main thread.
12-05 01:33:01.250: D/CameraLauncherActivity(8354): mCamera.takePicture :: android.hardware.Camera@416f4c90
12-05 01:33:06.540: D/CameraLauncherActivity(8354): mCamera.takePicture :: android.hardware.Camera@416f4c90
12-05 01:33:09.360: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/Honda Motors Event_Angel A-05-12-2013/IMG_20131205_001237.jpg
12-05 01:33:09.360: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/Honda Motors Event_Angel A-05-12-2013/IMG_20131205_001239.jpg
12-05 01:33:09.389: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/Honda Motors Event_Angel A-05-12-2013/IMG_20131205_001240.jpg
12-05 01:33:09.389: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/Honda Motors Event_Angel A-05-12-2013/IMG_20131205_001242.jpg
12-05 01:33:09.389: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/Honda Motors Event_Angel A-05-12-2013/IMG_20131205_013302.jpg
12-05 01:33:09.389: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/Honda Motors Event_Angel A-05-12-2013/IMG_20131205_013306.jpg
12-05 01:33:09.680: I/Choreographer(8354): Skipped 32 frames! The application may be doing too much work on its main thread.
12-05 01:33:12.000: D/dalvikvm(8354): GC_FOR_ALLOC freed 224K, 7% free 5431K/5780K, paused 488ms, total 516ms
12-05 01:33:12.161: I/dalvikvm-heap(8354): Grow heap (frag case) to 6.587MB for 1228816-byte allocation
12-05 01:33:12.560: D/dalvikvm(8354): GC_FOR_ALLOC freed 2K, 6% free 6629K/6984K, paused 398ms, total 398ms
12-05 01:33:14.320: D/dalvikvm(8354): GC_FOR_ALLOC freed 57K, 6% free 6621K/6984K, paused 165ms, total 199ms
12-05 01:33:14.340: I/dalvikvm-heap(8354): Grow heap (frag case) to 7.750MB for 1228816-byte allocation
12-05 01:33:14.501: D/dalvikvm(8354): GC_FOR_ALLOC freed <1K, 5% free 7821K/8188K, paused 140ms, total 140ms
12-05 01:33:16.050: D/dalvikvm(8354): GC_FOR_ALLOC freed 68K, 4% free 9048K/9392K, paused 161ms, total 162ms
12-05 01:33:17.270: D/dalvikvm(8354): GC_FOR_ALLOC freed 34K, 4% free 10261K/10596K, paused 227ms, total 280ms
12-05 01:33:17.960: D/dalvikvm(8354): GC_FOR_ALLOC freed 34K, 3% free 11474K/11800K, paused 132ms, total 137ms
12-05 01:33:18.550: I/Choreographer(8354): Skipped 2287 frames! The application may be doing too much work on its main thread.
12-05 01:33:22.031: I/Choreographer(8354): Skipped 81 frames! The application may be doing too much work on its main thread.
12-05 01:50:03.100: D/CameraLauncherActivity(8354): getCameraInstance()Camera:: null
12-05 01:50:03.980: D/CameraLauncherActivity(8354): getCameraInstance()open:: android.hardware.Camera@41968f50
12-05 01:50:03.980: D/CameraLauncherActivity(8354): folder_name :: Honda Motors Event_Angel A-05-12-2013
12-05 01:50:03.980: D/CameraLauncherActivity(8354): captureButton :: android.widget.Button{41999820 VFED..C. ......I. 0,0-0,0 #7f090004 app:id/btnCapture}
12-05 01:50:03.980: D/CameraLauncherActivity(8354): SingleAngelActivityButton :: android.widget.Button{41999298 VFED..C. ......I. 0,0-0,0 #7f090002 app:id/btnView}
12-05 01:50:04.801: I/Choreographer(8354): Skipped 124 frames! The application may be doing too much work on its main thread.
12-05 01:50:07.900: I/Choreographer(8354): Skipped 134 frames! The application may be doing too much work on its main thread.
12-05 01:50:08.961: I/Choreographer(8354): Skipped 38 frames! The application may be doing too much work on its main thread.
12-05 01:50:09.252: I/Choreographer(8354): Skipped 41 frames! The application may be doing too much work on its main thread.
12-05 01:50:09.501: I/Choreographer(8354): Skipped 61 frames! The application may be doing too much work on its main thread.
12-05 01:50:09.721: W/System.err(8354): org.json.JSONException: End of input at character 0 of
12-05 01:50:09.780: I/Choreographer(8354): Skipped 69 frames! The application may be doing too much work on its main thread.
12-05 01:50:10.080: I/Choreographer(8354): Skipped 74 frames! The application may be doing too much work on its main thread.
12-05 01:50:10.500: I/Choreographer(8354): Skipped 110 frames! The application may be doing too much work on its main thread.
12-05 01:50:10.771: I/Choreographer(8354): Skipped 66 frames! The application may be doing too much work on its main thread.
12-05 01:50:11.061: I/Choreographer(8354): Skipped 73 frames! The application may be doing too much work on its main thread.
12-05 01:50:11.361: I/Choreographer(8354): Skipped 75 frames! The application may be doing too much work on its main thread.
12-05 01:50:11.550: W/System.err(8354): at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
12-05 01:50:11.550: W/System.err(8354): at org.json.JSONTokener.nextValue(JSONTokener.java:97)
12-05 01:50:11.580: I/Choreographer(8354): Skipped 55 frames! The application may be doing too much work on its main thread.
12-05 01:50:11.590: W/System.err(8354): at org.json.JSONObject.<init>(JSONObject.java:154)
12-05 01:50:11.870: I/Choreographer(8354): Skipped 72 frames! The application may be doing too much work on its main thread.
12-05 01:50:12.091: W/System.err(8354): at org.json.JSONObject.<init>(JSONObject.java:171)
12-05 01:50:12.091: W/System.err(8354): at com.example.camera.CameraLauncherActivity$LoadSingleTrack.doInBackground(CameraLauncherActivity.java:195)
12-05 01:50:12.091: W/System.err(8354): at com.example.camera.CameraLauncherActivity$LoadSingleTrack.doInBackground(CameraLauncherActivity.java:1)
12-05 01:50:12.100: W/System.err(8354): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-05 01:50:12.100: W/System.err(8354): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-05 01:50:12.140: I/Choreographer(8354): Skipped 65 frames! The application may be doing too much work on its main thread.
12-05 01:50:12.360: I/Choreographer(8354): Skipped 55 frames! The application may be doing too much work on its main thread.
12-05 01:50:12.370: W/System.err(8354): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-05 01:50:12.620: I/Choreographer(8354): Skipped 65 frames! The application may be doing too much work on its main thread.
12-05 01:50:12.831: W/System.err(8354): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-05 01:50:12.831: W/System.err(8354): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-05 01:50:12.840: W/System.err(8354): at java.lang.Thread.run(Thread.java:841)
12-05 01:50:12.890: I/Choreographer(8354): Skipped 70 frames! The application may be doing too much work on its main thread.
12-05 01:50:13.200: I/Choreographer(8354): Skipped 82 frames! The application may be doing too much work on its main thread.
12-05 01:50:13.460: D/CameraLauncherActivity(8354): customFolder :: null Event_null-05-12-2013
12-05 01:50:13.460: I/Choreographer(8354): Skipped 65 frames! The application may be doing too much work on its main thread.
12-05 01:50:17.000: D/CameraLauncherActivity(8354): mCamera.takePicture :: android.hardware.Camera@41968f50
12-05 01:50:18.580: D/CameraLauncherActivity(8354): mCamera.takePicture :: android.hardware.Camera@41968f50
12-05 01:50:21.241: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/null Event_null-05-12-2013/IMG_20131205_001321.jpg
12-05 01:50:21.241: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/null Event_null-05-12-2013/IMG_20131205_015017.jpg
12-05 01:50:21.250: D/Count(8354): /mnt/sdcard/Pictures/CaptureImages/null Event_null-05-12-2013/IMG_20131205_015018.jpg
12-05 01:50:21.530: I/Choreographer(8354): Skipped 47 frames! The application may be doing too much work on its main thread.
12-05 01:50:22.900: D/dalvikvm(8354): GC_FOR_ALLOC freed 180K, 3% free 12821K/13128K, paused 589ms, total 619ms
12-05 01:50:24.810: D/dalvikvm(8354): GC_FOR_ALLOC freed 56K, 3% free 14012K/14332K, paused 626ms, total 662ms
12-05 01:50:26.550: D/dalvikvm(8354): GC_FOR_ALLOC freed 34K, 2% free 15225K/15536K, paused 569ms, total 570ms
12-05 01:50:26.800: I/Choreographer(8354): Skipped 1372 frames! The application may be doing too much work on its main thread.
12-05 01:50:28.980: I/Choreographer(8354): Skipped 70 frames! The application may be doing too much work on its main thread.
最佳答案
在此处查找 CameraLauncherActivity.java 的更新代码:
static boolean isReturning = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
mCamera = getCameraInstance();
mCameraPreview = new PreviewSurface(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mCameraPreview);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("folder_name");
isReturning = extras.getBoolean("isReturning");
Log.d(CameraLauncherActivity.LOG_TAG, "folder_name :: " + value);
}
Button captureButton = (Button) findViewById(R.id.btnCapture);
Log.d(CameraLauncherActivity.LOG_TAG, "captureButton :: " + captureButton);
captureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCamera.takePicture(null, null, mPicture);
Log.d(CameraLauncherActivity.LOG_TAG, "mCamera.takePicture :: " + mCamera);
}
});
Button viewButton = (Button) findViewById(R.id.btnView);
Log.d(CameraLauncherActivity.LOG_TAG, "SingleAngelActivityButton :: " + viewButton);
viewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentNewEvent = new Intent(CameraLauncherActivity.this, UploadActivity.class);
String event_id = customFolder;
intentNewEvent.putExtra("event_id", event_id);
startActivity(intentNewEvent);
}
});
cd = new ConnectionDetector(getApplicationContext());
// Check if Internet present
if (!cd.isConnectingToInternet()) {
// Internet Connection is not present
alert.showAlertDialog(CameraLauncherActivity.this, "Internet Connection Error",
"Please connect to working Internet connection", false);
// stop executing code by return
return;
}
// Get event id, angel id
Intent i = getIntent();
event_id = i.getStringExtra("event_id");
angel_id = i.getStringExtra("angel_id");
// calling background thread
new LoadSingleTrack().execute();
}
/**
* Background Async Task to get single angel information
* */
class LoadSingleTrack extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(CameraLauncherActivity.this);
pDialog.setMessage("Initializing Camera...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting angel json and parsing
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// post event id, angel id as GET parameters
params.add(new BasicNameValuePair("event", event_id));
params.add(new BasicNameValuePair("angel", angel_id));
// getting JSON string from URL
String json = jsonParser.makeHttpRequest(URL_angel, "GET",
params);
// Check your log cat for JSON reponse
Log.d("Single Track JSON: ", json);
try {
JSONObject jObj = new JSONObject(json);
if(jObj != null){
angel_name = jObj.getString(TAG_ANGEL);
event_name = jObj.getString(TAG_EVENT);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting angel information
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
TextView txt_angel_name = (TextView) findViewById(R.id.angel_title);
String timeStamp = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
txt_angel_name.setText(event_name + " Event_"+ angel_name + "-" + timeStamp);
if(!isReturning){
customFolder = txt_angel_name.getText().toString();
}else{
customFolder = extras.getString("folder_name");
}
Log.d(CameraLauncherActivity.LOG_TAG, "customFolder :: " + customFolder);
// Change Activity Title with angel title
setTitle(angel_name);
// folder name
mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"/CaptureImages/"+ customFolder + "/");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("App", "failed to create directory");
}
}
}
});
}
}
/**
* Helper method to access the camera returns null if it cannot get the
* camera or does not exist
*
* @return
*/
private Camera getCameraInstance() {
Camera camera = null;
Log.d(CameraLauncherActivity.LOG_TAG, "getCameraInstance()Camera:: " + camera);
try {
camera = Camera.open(0);
Log.d(CameraLauncherActivity.LOG_TAG, "getCameraInstance()open:: " + camera);
} catch (Exception e) {
// cannot get camera or does not exist
}
return camera;
}
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
pictureFile = getOutputMediaFile();
camera.startPreview();
if (pictureFile == null) {
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
};
static File getOutputMediaFile() {
/* yyyy-MM-dd'T'HH:mm:ss.SSSZ */
timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
// file name
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
return mediaFile;
}
现在在 Upload.java 下:
final Button button = (Button) findViewById(R.id.buttonBack);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Intent i = new Intent(getApplicationContext(), CameraLauncherActivity.class);
i.putExtra("folder_name", CameraLauncherActivity.customFolder);
i.putExtras("isReturning", true);
startActivity(i);
}
});
就是这样。现在它应该可以按需工作了!希望这有帮助
关于android - onCreate() 中附加项的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20326120/
在我最新版本的应用程序中,开发者控制台中报告的一些崩溃让我感到抓狂。 它们显示为 java.lang.IllegalStateException 并且似乎 Application.onCreate 在
在阅读《你好,Android》这本书时,我注意到: each java file with onCreate(Bundle savedInstanceState) method, has protec
我对 Android 编程还是个新手,所以这个问题很基础。我在 Internet 上看到很多代码示例,其中 UI 组件(如 TextView)在 Activity 的 onCreate() 方法中被初
在某些情况下,我可以看到 Activity.onCreate 在 Application 对象被创建之前被调用(在 Application.onCreate 被调用之前)。那有可能吗? 最佳答案 可能
我发现 MyApplication#onCreate 和 MyActivity#onCreate 之间有 200 毫秒或更多的延迟。在那段时间里有什么重要的事情发生吗? 最佳答案 根据 Applica
我正在创建一个具有带有 fragment 的抽屉导航 Activity 的应用程序。在应用程序的每次冷启动时,我都会执行一些初始化代码,在其中加载以下内容: 用户 session (无论用户是否登录)
我正在使用处理程序在 onCreate 内部调用 Runnable,并希望通过在 onCreate 外部使用 onBackPressed 来停止它。如何在 onCreate 之外停止 Runnable
在崩溃日志中,我发现了非常奇怪的应用程序错误,该错误发生在 Android 7.0-8.0 上,对于一些少量用户来说,但非常频繁。我无法重现该问题,这里的代码反射(reflect)了当前应用程序的状态
我正在使用 FragmentActivity 和 Fragments。 应用程序启动时: FragmentActivity onCreate() <------ FragmentActivity on
我在 AndroidManifest.xml 中注册了一个 ContentProvider,并且在 Application.onCreate() 之前调用了 ContentProvider.onCre
我希望我的数据库创建一次,它不会改变,但是当我在 onCreate() 时我不能创建数据...... public class EventsData extends SQLiteOpenHelper
最近我遇到了一个难以重现的问题。当 fragment 尝试使用来自 Activity 的数据初始化 ArrayAdapter 时,会发生 NPE。在Activity的onCreate方法中初始化的默认
我尝试通过单击导航从 EditText-Element 添加文本。我尝试在 Java 类中排除对 ListView 元素的访问(其中应添加文本),并在我的主 Activity 中对其进行初始化。如果我
当主 Activity 在安装应用程序后第一次尝试打开数据库时,会触发 SQLiteHelper Oncreate 方法(正如人们所期望的那样)。我想在 OnCreate 中创建数据表后填充数据库,但
我试图更好地理解声明和初始化,但并不真正理解为什么您可以在 OnClick 中更改按钮的文本,即使它无权访问 OnCreate,因为它是另一个函数。 当还在 onCreate 中声明变量时,它不起作用
这很奇怪。我有一个简单的应用程序,一旦登录就会显示 Activity 中的一个 fragment 。该应用程序也有一个不活动的“超时”,在该时间之后它完成 Activity 并显示登录屏幕——如果超时
我在我的 Android 项目中使用 AspectJ,我想编写一个 pointcut 来捕获对 onCreate() 和 的所有调用>onDestroy() 我的 Activity 。我对 Aspec
初始问题 (18/05/2020): 所以最新的更新来自 androidx.fragment:fragment:1.3.0- alpha07 到 androidx.fragment:fragment:
当我的应用程序“在顶部”运行时锁定屏幕时,系统几乎立即调用 onCreate(屏幕仍然是黑色的)。这种破坏性行为的原因可能是什么? 最佳答案 对我来说 android:configChanges="o
我浏览了其他 SO 帖子,但没有找到与我的问题相关的任何内容。 我正在尝试创建一个应用程序,该应用程序将获取用户上次重新启动后的步数。这是我的主要 Activity : package com.ass
我是一名优秀的程序员,十分优秀!