Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Friday, 23 December 2016

FCM push notification example

FCM push notification example

Question: What is FCM Messages?
Full form of FCM is Firebase Cloud Messaging.
FCM is a cross-platform messaging solution that lets you reliably deliver messages to android and IOS devices at no cost.
you can notify a client app that new message has been arrived.


Question: How does FCM works?
App server interacts with FCM (HTTP or XMPP protocol) and a client app. You can compose and send messages.
FCM built on Firebase Cloud Messaging.


Question: What is FCM Server?
FCM servers take messages from an app server and send to cient app.
FCM connection servers provided by Google.


Question: What is App Server?
App Server sends data to a client app (via the chosen FCM connection server) using XMPP or HTTP protocol.



Question: What are role of App Server?
  • Communicate with your client
  • Send properly formatted requests to the FCM connection server
  • Securely store the Server key and client registration tokens



Question:How to send notification to android/IOS device with FCM server?
$jsonData='{
  "to": "dhkC5_jTnck:APA91bF7L_KN7GFOPMiVsykjMGqydlftItfapC4Va63hRBuhFCrRKMdUonqhO1qjKT5_OYPMRAZFMA2UDVA1spAw9SpCsLE7B05vGtNttvuykIdxL7jKWWvJkA51T98O8ZZkubhXwQyRx",
  "notification": {
    "body": "New Gr sent you a message",
    "title": "domain.com ",
    "icon": "main_ve_logo",
    "click_action": "com.domain.fcm"
  },
  "data": {
    "type": "message",    
    "avatar": "http://img.domain.com/upload/default.jpg",
    "message_id": 1
  }
}';
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($fields),
    CURLOPT_HTTPHEADER => array(
      "authorization: key=FCM_SERVER_KEY",
      "cache-control: no-cache",
      "content-type: application/json"
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);



Monday, 6 July 2015

Android push notification - Send notification to google when message received


Android push notification api in PHP


Question: What is Push Notification in Android?
Push notifications let your application notify a user of new messages or events even when the user is Offline.


Question: How to get to know Push Notification in Android?
In Android devices, when a device receives a push notification, your application's icon and a message appear in the status bar.


Question: What are basic steps to implements push notifiction in Android Application?
  1. Registering for the Push Service
  2. Application must have the permissions to receive pushes and show notifications.
  3. Choose Your Push Icon
  4. Add your Parse API keys Parse.initialize(this, "YOUR_APP_ID", "YOUR_CLIENT_KEY");
  5. Enable Push Notifications in Mobile


PHP script for send notification to google services when event/message received so that notification start showing on user device.
 // Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$registrationIDs = array('Mobile Device Id1','Mobile Device Id3','Mobile Device Id3');
$message='message_received';
$apiKey='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$fields = array(
    'registration_ids' => $registrationIDs,
    'data' => array( "message" => $message ),
);
$headers = array(
    'Authorization: key=' . $apiKey,
    'Content-Type: application/json'
);

// Open connection
$ch = curl_init();

// Set the URL, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);


Wednesday, 29 April 2015

How to upload Image in Amazon s3 with android SDK 2.0

How to upload Image Aman s3 in android SDK 2.0


Try below code
bucket_name='xxxxxx';
key='xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
images3 = new File(uri.getPath())
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentEncoding("UTF-8");
imageSize = inputStream.available();
metadata.setContentLength(imageSize);
TransferManager transferManager = new TransferManager(credentialsProvider);
Upload upload = transferManager.upload(bucket_name, key, images3, metadata);
upload.waitForCompletion();




>

Tuesday, 28 April 2015

Android Interview Questions and Answers for fresher and Experienced

Android Interview Questions and Answers for fresher and Experienced


Question: What is Android?
Android an open-source operating system used for smartphones and tablet.


Question: How to start anroid development?
1. Download Android Studio.
2. Download the latest SDK tools and platforms.
3. Create a Project(Application) with Android Studio.
4. Now Running Your Application.
5. Install an editor for development (I am using eclipse editor for development).


Question: What main components of Android application?
1. Activities: They dictate the UI and handle the user interaction to the screen.
2. Services: They handle background processing associated with an application.
3. Broadcast Receivers: They handle communication between Android OS and applications.v 4. Content Providers: They handle data and database management stuff.


Question: What is Intent? What are two different type of Intent?
Intent means "intention" to do an action.
Question: Difference between px, sp, dip, dpi and pt in Android?
px is one pixel. px is corresponds to actual pixels on the screen.
sp is scale-independent pixels. SP is like the dp unit, but it is also scaled by the user's font size preference.
dip is Density-independent pixels.
dpi is Dots per inches.
pt is points.


Question: How to Close/hide the Android Soft Keyboard?
Hide the virtual keyboard using the InputMethodManager.


Question: How to Lazy load of images in ListView in Android?
You can use droidQuery.
$.with(myView).image(url);



Question: How to get unique Android device ID?
Settings.Secure#ANDROID_ID 
Will return unique Android device ID.


Question: How to get screen dimensions in pixels in Andorid Devices?
int screenHeight = getResources().getDisplayMetrics().heightPixels;
int screenWidth = getResources().getDisplayMetrics().widthPixels; 



Question: How do I center text horizontally and vertically in a TextView in Android?
<textview android:gravity="center" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="@string/username"></textview>



Question:What is the difference between match_parent and fill_parent?
Both are same thing and are different name in different API version.
match_parent means view should be as big as its parent (minus padding. This name is used in less than API Level 7.
fill_parent means view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.


Question: Is there a way to get the source code from an APK file?
http://stackoverflow.com/questions/3593420/is-there-a-way-to-get-the-source-code-from-an-apk-file


Question: How to set Standard Android Button with a different color?
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));



Question: How to disable landscape mode in Android?
Open AndroidManifest.xml file and set following.
android:screenOrientation="sensorPortait"



Question: How can I open a URL in Android's web browser from my application?
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.web-technology-experts-notes.in/2015/04/to-whom-does-pci-compliance-need-to-apply.html"));
startActivity(browserIntent);



Question: How do you install an APK file in the Android emulator?
http://stackoverflow.com/questions/3480201/how-do-you-install-an-apk-file-in-the-android-emulator


Question: How to Converting pixels to dp and vise versa?
public static float dpFromPx(final Context context, final float px) {
    return px / context.getResources().getDisplayMetrics().density;
}



Question: Can we display HTML in TextView? If yes, then How?
Yes, we can display HTML.
myTextView.setText(Html.fromHtml("<h2>
Web Technology</h2>
This is testing

"));



Question: How to put a border around an android textview?
<textview android:background="@drawable/back" android:text="Some text"></textview>


Monday, 30 March 2015

Android Interview Questions and Answers for Freshers



Question: What is Android?
Open source operating system used for smartphones and tablet computers.


Question: In which languages Android is written?
C, C++, Java


Question: What is Initial release date?
September 23, 2008


Question: What is Latest release of Android?
Version: 6.0.1 "Marshmallow"
Date: December 09, 2015


Question: What is offical website of Android?
http://www.android.com


Question: Who are Inventors of android?
Andy Rubin, Rich Miner, Nick Sears


Question: What are Features of Android OS?
  • Live wallpaper
  • Camera
  • Messaging
  • Music
  • Alarm
  • Bluetooth
  • WIFI
  • Web Browsing



Question: What are Advance Features of Android OS?
  • Google now
  • NFC (Near Field Communication)
  • Use phone by joystick
  • Connect your phone with LED TV via MHL or micro HDMI cable
  • Screen Capture
  • Unlock your phone by your face
  • Multitasking
  • Data Usages



Question: Tools Required for Developing Android Apps?
Java Development Kit (JDK)
Android Development Tools (ADT)
Software Development Kit (SDK)


Question: What is Full form of JDK?
Java Development Kit


Question: What is Full form of ADT?
Android Development Tools


Question: What is Full form of SDK?
Software Development Kit


Question: What is full form of AIDL?
Android Interface Definition Language


Question: What is full form of ANR?
Application Not Responding


Question: What are Advantages of android?
Open-source
Platform-independent


Question: What language you should know to develop android application?
Java
XML


Question: What is Activities?
Activity is a single, focused thing that the user can do.
When ever user click on GUI the next Activity will be start and new GUI set base on coding.


Question: What is AVD?
Full form of AVD is Android Virtual Device (emulator).
Android SDK includes a mobile device that is know as virtual device.


Question: Can you deploy executable JARs on Android? Which packaging is supported by Android?
No


Question: Where can you define the icon for your Activity?
In manifest file.


Question: Where will you declare your activity so the system can access it?
In manifest file.


Question: How will you pass data to sub-activities?
Use Bundles to pass data to sub-activities.


Question: What is an Action?
Action in Android is something that an Intent sender wants to complete.


Question: Can we change the name of an application after its deployment?
Not recommended.


Question: How can two Android applications share same Linux user ID and share same VM?
To do this must sign with the same certificate.


Question: Explain about folder structure in Android development.
Following are different folder in Android
src: Contains the .java source files for your project.
gen: This folder contains the R.java file. It is compiler-generated file that references all the resources found in your project.
Android 4.0 library: This folder contains android.jar file, which contains all the class libraries for an Android application.
assets: This folder contains all the information about HTML file, text files and databases etc.
bin: It contains the .apk file (Android Package).
res: This folder contains all the resource file that is used by android application.


Question: What is Intents in android?
An Android application can contain zero or more activities. If you want to navigate from one activity to another then android provides you Intent class and these class are available inandroid.content.Intent package.


Question: What are the key components of Android Architecture?
  • Linux Kernel
  • Libraries
  • Android Framework
  • Android Applications


Question: What is an Explicit Intent?
Explicit intent specifies the particular activity that should respond to the intent.


Question: When does onResume() method called?
onResume is called when activity come to foreground.


Question: What are the different storage methods in android?
  • Internal Storage
  • External Storage
  • Shared Preferences
  • SQLite Databases