Showing posts with label Android Studio. Show all posts
Showing posts with label Android Studio. Show all posts
Tuesday, 23 June 2015
Issues with Animators
Well today in this post I will not talk about these, instead I will put light on some issues that I faced while working and came to know about the reason very late.
1. I cannot reuse an ObjectAnimator and AnimatorSet object to get it usable for multiple views.
Wednesday, 1 April 2015
Simplest steps to integrate Parse for push notifications in Android
This blog entry is about how to fastly integrate Parse for push notifications in android. It only provide information on how to get started with the Parse's sample and the flow for most basic configurations.
2. Select the Push options.
3. Select Android
4. Out of the two options : Create a new project and Add to existing project. Choose what you want to do ?
5. Choosing New Project will take you to https://www.parse.com/apps/quickstart#parse_push/android/new
Follow the steps on this page to make respective changes in the source files : Well you can find this step defined in the app properly
5.1 Download the the project and import it in the android studio.
5.2 We will need to connect to parse. This will require us to edit some of the files in the project.
5.2.1 Edit the Application class's onCreate() method
5.2.2 Add the following service and broadcast receiver definitions to AndroidManifest.xml immediately before the closing </application> tag:
Change the android:name attribute of <category> element above to match your application's package name.
Also add the permissions below, typically immediately before the opening <application> tag:
Change the android:name attribute of <category> element above to match your application's package name.
5.2.3 Compile and run.
6. Similarly follow all the substeps just as in step 5 to do the Parse integration in android sdk.
7. Navigate to https://www.parse.com/apps to open dashboard containing all your projects created till now. Select the current project and the select the "Push" option.
7.1 Now here you will find an option/button to send a push message. You can also see the notification history if any notifications send previously.
7.2 Once selected one can also find a box to create a message to be sent. And the settings to choose the devices that can receive the notifications.
7.3 Also you can update the time of delivery of notification
7.4 Once message is configured properly, it can be pushed to the devices.
This is just a brief walk through of Parse for push notifications in android. It is a very big thing in itself. Parse is a collection of multiple sdks for various platform.
References: https://www.parse.com/
Source: https://github.com/Keshava11/parsecheck
Prerequisites :
Signup into the www.parse.com. Create a project which will generate few keys like APPLICATION ID and CLIENT KEY to be used later in the project while integrating sdk.Integration and Configuration:
1. Make a quickstart by navigating to this url https://www.parse.com/apps/quickstart2. Select the Push options.
3. Select Android
4. Out of the two options : Create a new project and Add to existing project. Choose what you want to do ?
5. Choosing New Project will take you to https://www.parse.com/apps/quickstart#parse_push/android/new
Follow the steps on this page to make respective changes in the source files : Well you can find this step defined in the app properly
5.1 Download the the project and import it in the android studio.
5.2 We will need to connect to parse. This will require us to edit some of the files in the project.
5.2.1 Edit the Application class's onCreate() method
public void onCreate() { // Replace the APPLICATION ID and CLIENT KEY with the one created for a project Parse.initialize(this, "APPLICATION ID", "CLIENT KEY"); }
5.2.2 Add the following service and broadcast receiver definitions to AndroidManifest.xml immediately before the closing </application> tag:
<service android:name="com.parse.PushService" /> <receiver android:name="com.parse.ParseBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver> <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false"> <intent-filter> <action android:name="com.parse.push.intent.RECEIVE" /> <action android:name="com.parse.push.intent.DELETE" /> <action android:name="com.parse.push.intent.OPEN" /> </intent-filter> </receiver> <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. --> <category android:name="com.parse.starter" /> </intent-filter> </receiver>
Change the android:name attribute of <category> element above to match your application's package name.
Also add the permissions below, typically immediately before the opening <application> tag:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below to match your app's package name + ".permission.C2D_MESSAGE". --> <permission android:protectionLevel="signature" android:name="com.parse.starter.permission.C2D_MESSAGE" /> <uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
Change the android:name attribute of <category> element above to match your application's package name.
5.2.3 Compile and run.
6. Similarly follow all the substeps just as in step 5 to do the Parse integration in android sdk.
Testing for push notifications :
OK, now you are done with the most basic integration so you are good to go for testing.7. Navigate to https://www.parse.com/apps to open dashboard containing all your projects created till now. Select the current project and the select the "Push" option.
7.1 Now here you will find an option/button to send a push message. You can also see the notification history if any notifications send previously.
7.2 Once selected one can also find a box to create a message to be sent. And the settings to choose the devices that can receive the notifications.
7.3 Also you can update the time of delivery of notification
7.4 Once message is configured properly, it can be pushed to the devices.
8. If everything is fine, app will receive the notifications and on clicking notification it will launch the application with the launcher activity.
Ok ,you are done here with the integration of Parse for push notifications in android.
Wait .... We are missing something .... ?
Don't you want to use one of the icon for the notification from your app reserve rather than default icon ? I know you are dying to add .
Don't you want to an implementation specific to your app like an desired activity to be launched. Yes you always wanted to drive
So we will do it in our app by creating our app's version of class com.parse.ParsePushBroadcastReceiver which allows to customize notification and implementation on receiving push message.
public class MyReceiver extends ParsePushBroadcastReceiver { @Override protected Notification getNotification(Context context, Intent intent) { final Notification notification = super.getNotification(context, intent); // TODO Update this notification here return notification; } @Override protected void onPushOpen(Context context, Intent intent) { //TODO For app specific implementation comment the following line calling super version of this method // super.onPushOpen(context, intent); //TODO Add App Specific implementation below Intent lastIntent = new Intent(context,SecondActivity.class); lastIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(lastIntent); } }
This is just a brief walk through of Parse for push notifications in android. It is a very big thing in itself. Parse is a collection of multiple sdks for various platform.
References: https://www.parse.com/
Source: https://github.com/Keshava11/parsecheck
Thursday, 27 November 2014
Android project import error for source-set with updated gradle tools
This blog post is about a very frequent error occurring with the updated version of gradle tools in Android Studio and its resolution.
This issue mainly occurs while importing an android project in android studio with updated gradle tools.
When we create a gradle based project in android studio, it generates the project with a defined structure, so that build.gradle can access all the source sets while building project.
In other words, a gradle based android project when created in the Android Studio IDE represents a particular hierarchy in which various components(various modules, library modules, directories containing generated code, gradle system specific directories and files) of a particular project is defined.
Or more precisely we are talking about the SourceSets.
SourceSet
A source-set in a gradle build system is a logical grouping of sources and resources and that confirms/corresponds to a hierarchy when a new project is created in android IDE.
As long as the source-set is defined according to the default structure, it will never complain for the build failed due to missing source sets.
Well this logical grouping could be changed as per the development requirements but then it would require some changes in the build.gradle to provide the proper path for the source sets required for proper build. An example of modified SourceSets is as follows :
Now if a project was created with updated source-sets using the older gradle (0.9.1) the only change in build.gradle that got it working was :
android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' res.srcDirs = ['res'] assets.srcDirs = ['assets'] java.srcDirs = ['src'] } ......... } ......... }
Project use to get imported successfully and so did the build process.
But the same project when was imported into studio with the updated gradle (0.13.2 [at time of writing]) was failing with the following error for the source-set paths. To get the project imported and build successfully we were required to provide source-set path accurately.
android { sourceSets { main { // Complete path to the source was required here. manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src/main/java'] assets.srcDirs = ['assets'] res.srcDirs = ['res'] } ......... } .......... }
References :
http://www.gradle.org/docs/current/dsl/index.html
Subscribe to:
Posts (Atom)
