How To Call Android Activities Into Phonegap Html?
I have recently started working on phonegap and i came across a task in which i need to browse for a file from android mobile and display the path of selected file. I've searched a
Solution 1:
You need to create a helper class something like:
public class HelperClass extends Plugin implements OnClickListener
protected static final String TAG = null;
private DroidGap mGap;
public HelperClass(DroidGap gap, WebView view)
{
mGap = gap;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mFilePathTextView = (TextView)findViewById(R.id.file_path_text_view);
mStartActivityButton = (Button)findViewById(R.id.start_file_picker_button);
mStartActivityButton.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.start_file_picker_button:
Intent intent = new Intent(this, FilePickerActivity.class);
startActivityForResult(intent, REQUEST_PICK_FILE);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
switch(requestCode) {
case REQUEST_PICK_FILE:
if(data.hasExtra(FilePickerActivity.EXTRA_FILE_PATH)) {
selectedFile = new File(data.getStringExtra(FilePickerActivity.EXTRA_FILE_PATH));
mFilePathTextView.setText(selectedFile.getPath());
}
}
}
}
@Override
public PluginResult execute(String arg0, JSONArray arg1, String arg2) {
// TODO Auto-generated method stub
return null;
}
}
then your main activity needs to be something like:
public class MainActivity extends DroidGap {
/** Called when the activity is first created. */
HelperClass cna;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
cna = new HelperClass(this, appView);
appView.addJavascriptInterface(cna, "HelperClass");
super.loadUrl("file:///android_asset/www/index.html");
}
}
Post a Comment for "How To Call Android Activities Into Phonegap Html?"