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

    Sunday, October 4, 2015

    Android webView Tutorial

    Basic app the opens a webView.

    Main.java
    webView = (WebView) findViewById(R.id.webview);webView.getSettings().setJavaScriptEnabled(true);webView.setWebViewClient(new MyBrowser());webView.loadUrl("https://github.com/login");

    activity_main.xml
    <WebView  xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/webview"    android:layout_marginTop="60dp"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:focusable="true"  />

    Add Internet permission to Manifest.
    <uses-permission android:name="android.permission.INTERNET" />

    Done :-)

    Download code here: https://github.com/AndreSand/NoteGit