Thursday, December 17, 2015

How to run Android App with latest Android tools


Google Android info

Android Styling:
 https://blog.stylingandroid.com/percent-part-1/

Install latest Android Studio:

Install latest Android emulator:

Enable Instant run:

Google Android tech docs:


Android developers blog
http://android-developers.blogspot.com/

Android best practices:
https://github.com/futurice/android-best-practices
 http://guides.codepath.com/android

Android devices Dashboard(google)
https://developer.android.com/about/dashboards/index.html


SourceTree uncommit
http://flummox-engineering.blogspot.com/2014/10/how-to-undo-git-commit-in-sourcetree.html

Wednesday, December 16, 2015

Butterknife Library for Android

Butterknife 

Is a view "injection" library for Android. It will reduces boilerplate code.

Example:
  1. Add dependency to app/build.gradle
dependencies {
  compile 'com.jakewharton:butterknife:7.0.1'
}
  1. In main.xml declare an image widget id name "image"
  2. In main.java start using @Bind to declare each variable 

public class Main extends AppCompatActivity {
private static final String ITENT_TAG= "chapter"; 

private Chapter chapter;

@Bind(R.id.button) Button myButton; 

@Bind(R.id.textTextView myText;

@Bind(R.id.image

ImageView myImage;  

@Override public void onCreate(Bundle savedInstanceState) 

{
super.onCreate(savedInstanceState);   setContentView(R.layout.activity_detail);   ButterKnife.bind(this); 

@OnClick(R.id.button) protected void Toast(){

Toast.makeText(getApplicationContext(),"Hello Android Butter Knife",Toast.LENGTH_LONG).show();}

}

myText.setText("Hello!");

res = getResources();
myImage.setImageDrawable(res.getDrawable(R.drawable.myimage));



  • Also initialize ButterKnife in OnCreate:
 ButterKnife.bind(this);


Resources:
http://www.sitepoint.com/tidying-code-with-android-butterknife/
https://guides.codepath.com/android/Reducing-View-Boilerplate-with-Butterknife

Sunday, December 13, 2015

Crashlytics for Android app

What is Crashlytics?

  • It's a great tool for developers; developer can get a lot of statics from the app... it's free.
  • Delivers crash reporting across devices in real-­time. 
  • Performs analysis of every thread on every Android device to identify the most important issues.
**Usage is super easy**

How to Setup:

  1. Register here https://get.fabric.io/
  2. In Android Studio install the Crashlytics plugin -Android Studio -> Preferences -> Plugins -> "Fabric plugin" Install 
  3. Now you will have the Fabric icon in Android Studio (image one below).
  4. Now select your app and enable Crashlytics, everything will be setup automatically just follow the instructions provided.
  5. Done. Build and install your App.
  6. Go to https://fabric.io/ to see the statistics of your app(image two below).
(image one)















(image two)





References:
http://www.crashlytics.com/blog/its-finally-here-announcing-crashlytics-for-android/
https://fabric.io/kits/android/crashlytics/summary

Great tutorial:
http://www.codedevplus.com/integrating-crashlytics-from-fabric-in-android/
https://fabric.io/kits/android/crashlytics/install

Saturday, December 12, 2015

Android and Parse (BAAS)

With Parse you can create apps and no worry to maintain a backend.
More info about parse: www.parse.com git: https://github.com/parseplatform

Getting started (Must do the below tutorial to understand how to setup Parse):
https://parse.com/apps/quickstart#parse_data/mobile/android/native/existing 

https://www.parse.com/docs/android/guide#local-datastore

Great tutorial to save and retrieve data with Parse: http://www.sitepoint.com/creating-cloud-backend-android-app-using-parse/
github to above link: https://github.com/sitepoint-editors/Android-Parse

Todo app: http://blog.revivalx.com/2015/06/09/develop-a-simple-android-mobile-app-todolist-part-1/

Parse dashboard: https://dashboard.parse.com/apps

Login with Facebook: https://github.com/ParsePlatform/ParseFacebookUtils-Android
ex: https://parse.com/docs/android/guide#users-facebook-users

Login with Parse(save users in Parse backend for free): https://github.com/AndreSand/UserParse

Parse Store tutorial: https://github.com/ParsePlatform/ParseStore

Parse Android send notifications (easy setup): https://parse.com/apps/quickstart#parse_push/android/native/existing
https://parse.com/tutorials/android-push-notifications

SETUP:https://parse.com/apps/quickstart#parse_data/mobile/android/native/existing 


.5 Create a test app in Parse dashboard to get AppID and ClientKey (found in: App Settings -> Security and keys)
1. Download the latest Parse.jar, and copy and paste to your app/lib/Parse.jar.
then add:
 dependencies {
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}
to /GradleScripts/build.graddle(app)

2. Now create a new directory ParseApp, here we are going to setup the parse app, Create class ParseSetup ( we will add this class to your Manifest).

public class ParseSetup extends Application {

    @Override    public void onCreate() {
        super.onCreate();
        Parse.enableLocalDatastore(this);
        Parse.initialize(this);        //setupParse();        ParseObject testObject = new ParseObject("TestObject");        testObject.put("foo", "bar222");        testObject.saveInBackground();

    }

}

3. Open AndroidManifest.xml and add the name of the Parse App class here (ParseSetup). ex:
<application    android:name=".ParseApp.ParseSetup"    android:allowBackup="true"    android:icon="@mipmap/ic_gamma"    android:label="@string/app_name"    android:supportsRtl="true"    android:theme="@style/AppTheme">    <activity android:name=".MainActivity">        <intent-filter>            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />        </intent-filter>    </activity>
    <meta-data        android:name="com.parse.APPLICATION_ID"        android:value="your_ID" />    <meta-data        android:name="com.parse.CLIENT_KEY"        android:value="your_key" />

also add the below Permissions:
<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

test

Monday, December 7, 2015

Android M Runtime Permissions (info)

Great read:
http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

ADB commands
Android 6.0 Permissions:
Granting and revoking runtime permissions:
$adb shell pm grant/revoke my.package.name some.permission.NAME

Installing an app with all permissions granted:
$adb install -g my.package.name

Dumping app permission state:
$adb shell dumpsys package my.package.name

Show all Android permissions:
$adb shell pm list permissions -d -g

Wednesday, November 25, 2015

Android tricks

Color your logcat:
github.com/marshall/logcat-color.git

APK analysis:
https://github.com/AndroBugs/AndroBugs_Framework 

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- andressjsu_main_Blog1_1x1_as -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-1942010622975585"
     data-ad-slot="2136421958"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Thursday, November 12, 2015

Open terminal from MacBook folder

1. Go to System Preferences and select Keyboard > Shortcuts > Services. 
2. check box  "New Terminal at Folder"

Done. 
Now right click in a folder -> services -> open "New Terminal at Folder"











Tuesday, November 10, 2015

Android Studio Shortcuts for Mac



 Color Picker
 shift + cmd + a (search color picker)
 Recent Files
 cmd + e
 Open class/file
 cmd + o
 Last edit Location
 cmd + shift + backspace
 Goto Declaration
 cmd + b
 Comment line
 cmd + \
Hide All Panels
fn + cmd + shift + f12
Switch tab
control + tab

Close structure panel
cmd  + 1
Code Format
cmd + opt + l
Search  files
shift + shift
Override method
cmd + shift + a
View switch
control +  `
for loop
fori + enter





Shortcuts:
https://stanfy.com/blog/use-android-studio-like-a-pro/?utm_source=reddit&utm_medium=referral




Reference:
http://www.developerphil.com/android-studio-tips-of-the-day-roundup-5/

http://javapapers.com/wp-content/uploads/2014/08/Android-Studio-Shortcuts-You-Need-the-Most.pdf




https://www.codementor.io/free
Codementor

Saturday, October 24, 2015

Android Tutorial: Share with Facebook, and with other apps.


Android: Share with Facebook

Facebook doesn't work well with normal sharing intents when sharing multiple content elements as discussed in this bug. To share posts with facebook, we need to:
  1. Create a new Facebook app here (follow the instructions)
  2. Add the Facebook SDK to your Android project:
SetUp:
a. App/build.gradle (add below)
repositories { mavenCentral() }

dependencies {
     
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'   
}

b. Add you Facebook app id to strings.xml
<string name="facebook_app_id">1698838388383</string>

c. Add Facebook activity to AndroidManifest.xml, also add <meta-data AppID />
Activity:
<!-- Share to Facebook -->
<activity android:name="com.facebook.FacebookActivity"></activity>
    Meta-data:
    <meta-data    
    android:name="com.facebook.sdk.ApplicationId"    
    android:value="@string/facebook_app_id" />

    b. Add you Facebook Library to your AndroidStudio project.
    1. Download SDK from here: Facebook SDK
    2. unzip
    3. On Android Studio go to: 

    •  File -> New -> New Module
    • Select "Import .JAR/.AAR package"
    • Go to your unzip Facebook SDK, and select facebook-android-sdk-4.7.0.aar

    • Click next. Done :)



    Share from Menu bar:
    ShareFB.java , menu_shareFB.xml
    a. edit menu_shareFB.xml:
    <menu xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto">
        <item        android:id="@+id/action_share"        android:icon="@android:drawable/ic_menu_share"        android:title="Some title"        app:showAsAction="always"        >
            <menu>            <item                android:id="@+id/action_share_Facebook"                android:title="Share with Facebook"/>            <item                android:id="@+id/action_share_other_Apps"                android:title="Share with other Apps"/>
            </menu>
        </item></menu>

    b. Now edit ShareFB.java:
    @Overridepublic boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_campaign_detail, menu);    return true;}
    @Overridepublic boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
    
            case R.id.action_share_Facebook:
            {
                setupFacebookShareIntent();            Toast.makeText(getApplicationContext(), "here facebok", Toast.LENGTH_LONG).show();        }
            break;      //  case  R.id.action_share:        case R.id.action_share_other_Apps:
            {
                setupShareIntent();            Toast.makeText(getApplicationContext(), "here 2", Toast.LENGTH_LONG).show();        }
            break;    }
        return super.onOptionsItemSelected(item);}
    
    //Share with Facebookpublic void setupFacebookShareIntent() {
        ShareDialog shareDialog;    FacebookSdk.sdkInitialize(getApplicationContext());    shareDialog = new ShareDialog(this);
        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentTitle("SumOfUs")
                .setContentDescription(
                        "\"Title Of Test Post\"")
                .setContentUrl(Uri.parse("http://www.sumofus.org"))
                .build();
        shareDialog.show(linkContent);
        //MessageDialog.show(this, linkContent);}
    
    
    
    // Gets the image URI and setup the associated share intent to hook into the provider
    public void setupShareIntent() {
        // Fetch Bitmap Uri locally    ImageView ivImage = (ImageView)findViewById(R.id.ivCampaign);    // Get access to the URI for the bitmap    Uri bmpUri = getLocalBitmapUri(ivImage);    if (bmpUri != null) {
            // Construct a ShareIntent with link to image        Intent shareIntent = new Intent();        shareIntent.setAction(Intent.ACTION_SEND);        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);        shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Title Of Test Post");        shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.sumofus.org");        shareIntent.setType("image/*");        // Launch sharing dialog for image        startActivity(Intent.createChooser(shareIntent, "send"));    } else {
            Toast.makeText(this, "Some error occured during sharing", Toast.LENGTH_LONG).show();
        }
    
    }
    
    // Returns the URI path to the Bitmap displayed in specified ImageView
    public Uri getLocalBitmapUri(ImageView imageView) {
        // Extract Bitmap from ImageView drawable    Drawable drawable = imageView.getDrawable();    Bitmap bmp = null;    if (drawable instanceof BitmapDrawable){
            bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();    } else {
            return null;    }
    
        // Store image to default external storage directory    Uri bmpUri = null;    try {
            File file =  new File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");        file.getParentFile().mkdirs();        FileOutputStream out = new FileOutputStream(file);        bmp.compress(Bitmap.CompressFormat.PNG, 90, out);        out.close();        bmpUri = Uri.fromFile(file);    } catch (IOException e) {
            e.printStackTrace();    }
        return bmpUri;
    }


    TODO:
    add github repo here:

    Reference:

    1. Share using this code snippet:
     public void setupFacebookShareIntent() {
          ShareDialog shareDialog;
          FacebookSdk.sdkInitialize(getApplicationContext());
          shareDialog = new ShareDialog(this);
    
          ShareLinkContent linkContent = new ShareLinkContent.Builder()
                  .setContentTitle("Title")
                  .setContentDescription(
                          "\"Body Of Test Post\"")
                  .setContentUrl(Uri.parse("http://someurl.com/here"))
                  .build();
          
          shareDialog.show(linkContent);
      }

    http://guides.codepath.com/android/Sharing-Content-with-Intents#share-in-facebook