Showing posts with label PhoneGap. Show all posts
Showing posts with label PhoneGap. Show all posts

Sunday, 1 May 2016

HB Blog 109: Content Assist - The Developer's Friend.

Android Studio and similar other IDE's provide various features to developers which make a comfort environment for them. Hence, it is called as Integrated Development Environment (IDE). More technical, an integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development. One of the most helpful feature is the content assist.

Content/Code assist helps the developer to write code faster and more efficiently. This is achieved by simplifying the task of coding to allow it to focus on the business task being coded. Based on the context of the code, content assist provides the developer with a list of accessible keywords according to a programming language specification, variable, methods, data types.
Autocomplete: - Autocomplete, or word completion, is a feature in which an IDE predicts the rest of a word a user is typing.

For example, in an XML context, when the developer types an opening tag "<" he is offered a list of tags via autocomplete, contextualized following the DTD or XML schema of the document. As the developer types more letters, the offered choices are filtered to only retain the relevant completions. When the developer finally completes the tag, the editor automatically generates the closing tag.

Another example, a developer can just type in the first letter if lowercase and the uppercase letters from a type/variable name then press Ctrl+space to be offered all the choices that match the entered letters that are valid for the current context (class name, interface name, variable or field names).

Code snippet/templates: - Code snippets allow the developer to add a complex coding structure by typing a minimal amount of text. Code snippets can only be used in a valid context (statements snippets are only offered when you can insert statements).

Specifically, in Android Studio ctrl+space (content assist) does 50% work of the developer's work.
Android studio has few more interesting features as well which makes development pretty simple.

Refer below link to meet Android studio,
https://developer.android.com/studio/intro/index.html

Monday, 6 October 2014

HB Blog 25: How to take picture from camera programmatically using phonegap/cordova and javascripts?

The mobile application development landscape is filled with many ways to build a mobile app.
Among the most popular are:
    Native iOS,
    Native Android,
    PhoneGap,
    PhoneGap Android Cordova Library,
    Appcelerator Titanium,
    and many more.

PhoneGap Android Cordova Library:- 
Refer the below link for starting with phonegap:-
http://docs.phonegap.com/en/2.0.0/guide_getting-started_android_index.md.html

Step by step guide for integrating camera using cordova library:-

 

Step I :- Download and add cordova library into libs folder.
Step II :- You need few javascript and other supportive files to support cordova library. can download them from below link.
Download Support Files
Step III :- Add the supportive files www name folder into your project assets folder.
Step IV :- Observe index.html file. It is your main file for implementing camera functionality.

Refer the below link for complete sample code:- 
Download Sample Code
Download Apk File

Have a look on few code snippets,

index.html 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Take picture using device camera and retrieve image as base64-encoded string
 function capturePhoto() {
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
    }

// Retrieve image file location from specified source
function getPhoto(source) {
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

Step V :- Load index.html file into your activity java class which should extend DroidGap class of cordova library as shown below

MainActivity.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// extend DroidGap class of coirdova library
public class MainActivity extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.setIntegerProperty("splashscreen", R.drawable.ic_launcher);
        super.loadUrl("file:///android_asset/www/index.html");
    }
} 

Wednesday, 23 July 2014

HB Blog 5: How to send sms programmatically using phonegap and android?

The mobile application development landscape is filled with many ways to build a mobile app.
Among the most popular are:

    Native iOS,
    Native Android,
    PhoneGap,
    PhoneGap Android Cordova Library,
    Appcelerator Titanium.

1)PhoneGap Android Cordova Library:-

 Refer the below link for starting with phonegap:-

    http://docs.phonegap.com/en/2.0.0/guide_getting-started_android_index.md.html

Refer the below link for complete sample code:-
Download Sample Code
Download Apk File



 Few important snippets for sms:-

   MainActivity.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
public class MainActivity extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html")
    }
}
  
  smsplugin.js
1
2
3
4
5
6
7
var SmsPlugin = function () {};
SmsPlugin.prototype.send = function (phone, message, method, successCallback, failureCallback) {   
    return PhoneGap.exec(successCallback, failureCallback, 'SmsPlugin', "SendSMS", [phone, message, method]);
};
PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin("sms", new SmsPlugin());
});
  
  index.html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<script type="text/javascript">
         $(document).ready(function() {
             //leave empty for sending sms using default intent
             $("#btnDefaultSMS").click(function(){
                 var number = $("#numberTxt").val();
                 var message = $("#messageTxt").val();
                SmsPlugin.prototype.send(number, message, '',
                    function () {
                       alert('Message sent successfully'); 
                    },
                    function (e) {
                        alert('Message Failed:' + e);
                    }
                );              
             });
         });
      </script>
2)Native Android:-

 Refer the below link for starting with android:-

   https://developer.android.com/training/index.html

Refer the below link for complete sample code:-
Download Sample Code
Download Apk File



 Few important snippets for sms:-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
public void sendSMS(String phoneNumber,String message) {
        SmsManager smsManager = SmsManager.getDefault();
         String SENT = "SMS_SENT";
         String DELIVERED = "SMS_DELIVERED";
            SmsManager sms = SmsManager.getDefault();
            ArrayList<String> parts = sms.divideMessage(message);
            int messageCount = parts.size();        
     Log.i("Message Count", "Message Count: " + messageCount);    
         ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
            ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(); 
            PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
            PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
            for (int j = 0; j < messageCount; j++) {
                sentIntents.add(sentPI);
                deliveryIntents.add(deliveredPI);
            }
            // ---when the SMS has been sent---
            registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context arg0, Intent arg1) {
                    switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off",
                                Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }, new IntentFilter(SENT));

            // ---when the SMS has been delivered---
            registerReceiver(new BroadcastReceiver() {
               @Override
                public void onReceive(Context arg0, Intent arg1) {
                    switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered",
                                Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }, new IntentFilter(DELIVERED));         
            smsManager.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
           /* sms.sendMultipartTextMessage(phoneNumber, null, parts, sentIntents, deliveryIntents); */
    }