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:
publicclassHelperClassextendsPluginimplementsOnClickListenerprotectedstaticfinalStringTAG=null;
private DroidGap mGap;
publicHelperClass(DroidGap gap, WebView view)
{
mGap = gap;
}
@OverridepublicvoidonCreate(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);
}
publicvoidonClick(View v) {
switch(v.getId()) {
case R.id.start_file_picker_button:
Intentintent=newIntent(this, FilePickerActivity.class);
startActivityForResult(intent, REQUEST_PICK_FILE);
break;
}
}
@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
switch(requestCode) {
case REQUEST_PICK_FILE:
if(data.hasExtra(FilePickerActivity.EXTRA_FILE_PATH)) {
selectedFile = newFile(data.getStringExtra(FilePickerActivity.EXTRA_FILE_PATH));
mFilePathTextView.setText(selectedFile.getPath());
}
}
}
}
@Overridepublic PluginResult execute(String arg0, JSONArray arg1, String arg2) {
// TODO Auto-generated method stubreturnnull;
}
}
then your main activity needs to be something like:
publicclassMainActivityextendsDroidGap {
/** Called when the activity is first created. */
HelperClass cna;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
cna = newHelperClass(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?"