gpt4 book ai didi

android - onCreate() 中附加项的空值

转载 作者:太空狗 更新时间:2023-10-29 16:39:31 24 4
gpt4 key购买 nike

  1. 使用 JSON 将数据提取到列表中,并允许用户选择列表项并使用在列表上单击的项目准备文件夹名称,例如:事件 + 名称_日期

    举个例子:- 本田汽车_A-05-12-2013

  2. 现在我显示相机和 2 个按钮,即:- 查看图库和捕获图像

  3. 允许用户捕捉,并在 CaptureImages 目录中创建一个文件夹,名称为:Honda Motors Event_A-05-12-2013

  4. 现在,一旦用户点击“查看图库”按钮,就会显示本田汽车 Event_A-05-12-2013 中可用的图像列表,在图库 Activity 中,我还提供返回按钮以返回并捕获更多图像,但是这里我遇到了问题

  5. 每当用户返回并拍摄图像时,不要将这些图像放入 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com