2013年5月24日 星期五

android

1.camera 要定焦的方法

2.camera 可setPreviewSize 設定秀在螢幕上的size, setPictureSize 設定儲存照片的size,
但是這個size不能隨便亂設,必須由getSupportedPreviewSizes/getSupportedPictureSizes從中挑一組出來



2013年5月22日 星期三

to use startActivity post message to Line

Line跟facebook一樣在安裝了 Line/Facebook app後, 可以簡單的利用startActivity來進行一些簡單的PO文動作, 也就是藉由他本身的app去執行api。
相反來說, 若是想利用自己的app去發request 就要去add naver/facebook 的library, 這樣能做到的事更多, 但是較為麻煩。

這邊將介紹如何透過簡單的方式來PO文到line上

//判斷是否安裝了line
private boolean checkLineInstalled(){
PackageManager pm = getPackageManager();
m_appList = pm.getInstalledApplications(0);
boolean lineInstallFlag = false;
for (ApplicationInfo ai : m_appList) {
if(ai.packageName.equals(PACKAGE_NAME)){
lineInstallFlag = true;
break;
}
}
return lineInstallFlag;
}



//PO文字
public static final String PACKAGE_NAME = "jp.naver.line.android";
public static final String CLASS_NAME = "jp.naver.line.android.activity.selectchat.SelectChatActivity";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, sendText);
startActivity(intent);



//PO圖片
String fname = "send_image.jpg";
String fileFullPath = Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + fname;


Uri uri = Uri.fromFile(new File(fileFullPath));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);



Reference: https://gist.github.com/ekos/3993270


帶出所以有可以share的app


Reference:http://orgcent.com/android-app-intent-share-list/

2013年5月16日 星期四

Facebook search

http://developers.facebook.com/docs/reference/api/search/#results



Session session = Session.getActiveSession();
Bundle params = new Bundle();
params.putString("fields", "picture,name");
params.putString("q", "淡水");
params.putString("type", "place");
Request request = new Request(session, "search", params, HttpMethod.GET, callback);
RequestAsyncTask task = new RequestAsyncTask(request);    
task.execute();



主要在Bundle的"fields"選擇要filter的資料,"q"為要搜尋的字串, "type"為搜尋類型

use Facebook graph api to delete object on android

在graph api中的Request 共有三個HttpMethod  (GET、POST、DELETE),也就是用來-->

1.搜尋資料,http://tang0110.blogspot.tw/2013/05/to-get-facebook-data-by-facebook-sdk-in.html
    支前在這篇文章已經詳加說明了如何透過tool去找尋路徑到object(nodes), 並挑選需要的fields。




Bundle params = new Bundle();
Request request = new Request(session, OBJECT_ID, params, HttpMethod.DELETE, callback);
RequestAsyncTask task = new RequestAsyncTask(request);    
task.execute();

2.刪除資料,OBJECT_ID要填入id,但是如果是要unlikes就必須填入OBJECT_ID/likes,因為likes這個node沒有ID只好用connection連過去


3.增加資料,http://developers.facebook.com/docs/reference/api/post/




2013年5月14日 星期二

To get Facebook data by facebook SDK in android

利用此tool(http://developers.facebook.com/tools/explorer) 下指令去取得資料(綠點), 以檢視是否有自己所需要的資訊




1.必須先get access token,選擇所要的permission, 這是因為不論人、 apppages 要使用facebook, 都必須給予一個token
 
=======================================================================

Session session = Session.getActiveSession();
Bundle params = new Bundle();
params.putString("fields", "source, link");
Request request = new Request(session, "OBJECT_ID/photos", params, HttpMethod.GET, callback);
RequestAsyncTask task = new RequestAsyncTask(request);   
task.execute();
2.會有fieldsconnections可以選擇(紅點)
 fields相當於是在這open graph nodes的屬性,可用Bundle來選擇  connnections意思是連到open graph 中另一個node,可用RequestgraphPath來決定
(nodes-connection->nodes  , 10150153595592320/photos)

或者可以寫成

params.putString("fields""photos.fields(source,link)");
Request request = new Request(session, "OBJECT_ID", params, HttpMethod.GET, callback);



=======================================================================

JSONObject  json=  response.getGraphObject().getInnerJSONObject();
JSONArray  jsonArrayData=json.getJSONArray("data");
for(int i=0;i<jsonArrayData.length();i++)
{
     JSONObject jsonObjectImages = (JSONObject)jsonArrayData.opt(i);
     Log.d("AAA","json:"+jsonObjectImages.getString("source"));
}
3.最後在callback的地方會得到JSON的資料格式,大括弧包起來的轉成JSONObject,中括弧包起來的轉成JSONArray  

2013年5月8日 星期三

Facebook login

這裡會提到幾個讓你的APP登入FB的幾個要點

1.需要import FacebookSDK專案, 並讓你的project add lib
2. 在程式碼裡加入該加的loginButton及callBack等..
(http://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/)

3.在facebook developer上要申請 app的開發網頁,會產生一組app_id, 在manifest要加入login的activity以及appid

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>   
        <activity
            android:name="com.facebook.LoginActivity">
       </activity>

4.並且要用電腦裡的keystore 透過openssl產生key hashes填入facebook developer, 或者從callback中回報的錯誤getMssage得到key hashes

(http://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/)
(http://changyy.pixnet.net/blog/post/29201245-android-%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8%98---%E4%BD%BF%E7%94%A8-facebook-sdk)






2013年4月29日 星期一

本身app呼叫android系統app的方式

http://ysl-paradise.blogspot.tw/2008/12/intent.html


開啟簡訊夾的簡訊清單

public static void recallSMSAp(Context mContext)
{
ComponentName comp = new ComponentName("com.android.mms", "com.android.mms.ui.ConversationList");
Intent intent = new Intent();
intent.setComponent(comp);
intent.setAction("android.intent.action.VIEW");
mContext.startActivity(intent);
}


直接進入簡訊夾內的某一thread

public static void recallSMSApThread(Context mContext, int threadId) 
{
Intent defineIntent = new Intent(Intent.ACTION_VIEW);
defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+ threadId));
defineIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(defineIntent);
}

2013年3月19日 星期二

android multiScreen

長度單位有dp, px
文字大小單位有sp,pt

為了在相同螢幕下不同解析度依然維持相同大小,
長度單位需使用dp
文字大小單位需使用sp
如果螢幕長寬比例不同, 則需要利用公式去計算比例關係


一般來說要去設定長度或文字大小有以下三種方法
1. 從程式設定
2. 從xml
3. 從dimens

2013年3月12日 星期二

java Interface, Abstract

 Interface和Abstract都不能直接實體化

Interface 和 Abstract 方法大同小異, 但是主要是要符合ISP(Interface Segregation Priciple),
Abstract是為了讓子類別還具備保留父類別的抽象概念,
而因為java 不能多重繼承, 也是為了讓子類別有單獨承接父類別的概念,
但是為了有多重繼承的效果, 也就有了interface替abstract class添加新功能/屬性的概念
implements Interface 要override裡面的method
public interface DemoInterface
{
 
     final int x=0;
void a();
void b();
void c();
}
extends Abstract 要override裡面的abstract method,
而Interface 不能描述方法, Abstract 則可以如a()

public abstract DemoAbstract
{
   int y;  
  void a(){...};  
  abstract void b(); 
abstract void c();

2013年3月2日 星期六

Android onInterceptTouchEvent&onTouchEvent

在ViewGroup中可以override onInterceptTouchEvent與onTouchEvent這兩個物件,
而View中只可以override onTouchEvent這個物件,接下來將會說明他們的功能為何。

假設有 RelativeLayoutA,  RelativeLayoutB,  ButtonC

當我們在點擊ButtonC時, 會先由parent view收到訊息, 然後開始往child view傳。







        首先,A的onInterceptTouchEvent收到down event後return false,然後會把down event會傳給的B的onInterceptTouchEvent,然後B發現它下面沒有groupview了就把down event傳給C的onTouchEvent, 如果C return true也就是告訴系統接下來的action event 都是由她處理,直接傳給他就可以了。
         所以越上層的view會有優先決定處理action event的機會,那麼view的onTouchEvent何時會return true呢? 當我們在設置view的listener時,系統會認為這個view是有要處理action event的。





2013年3月1日 星期五

android focusable

在這裡的說明, 純粹是依我對focusable的了解, 所謂的focus也就是你目前注視著哪個view, 這樣的說法很抽象, 我在這裡舉個例子:

        比如使用google chrom時, 有兩個tab一頁是google一頁是yahoo, 當我們取得焦點是在yahoo那頁的【網頁搜尋】UI, 我們可以藉由按鍵盤上的tab鍵來改變焦點, 或者也可以用滑鼠直接去點選。講到這裡我們得出一個結論, 能夠取得焦點的, 才能夠點選, 而以目前來說我們的焦點無法指到google那一頁面, 也就是說google 的【網頁搜尋】UI是接收不到我們的click event。
        而在這例子中的google&yahoo首頁, 就是相當於android中的layout.xml,經常有人利用在自行定義listview時, 發生listitem的button搶掉listview的事件, 這原因就是在於focus原本屬於mainLayout.xml (google首頁)所以在點選listview可以去做判斷你點了什麼, 而因為自行訂定了listitem而導致焦點被自行定義的item.xml(yahoo首頁)給搶走了。

2013年2月25日 星期一

android facebook post to wall


Request request = new Request(Session.getActiveSession(), "me/feed", postParams,                               HttpMethod.POST, new Request.Callback(){...});
RequestAsyncTask task = new RequestAsyncTask(request); 
task.execute();
這裡的postParams 是 Bundle postParams = new Bundle();
而po出的文會成為什麼樣子則要看我們利用postParam填入什麼屬性。
postParams.putString("name", "Facebook SDK for Android");





linkThe link attached to this post (點選name或圖片會跳過去link)

pictureThe URL of a picture attached to this post. The picture must be at least 50px by 50px (though minimum 200px by 200px is preferred) and have a maximum aspect ratio of 3:1
(圖片上的那塊藍綠圖)

sourceThe URL of a media file (either SWF or MP3) attached to this post. If both source and picture are specified, only source is used.

nameThe name of the link attachment.(圖片上的Facebook Dialog)

captionThe caption of the link (appears beneath the link name). If not specified, this field is automatically populated with the URL of the link.(圖片上的Reference Documentation)

descriptionThe description of the link (appears beneath the link caption). If not specified, this field is automatically populated by information scraped from the link, typically the title of the page.
(圖片上的Using Dialogs to interact with users)

propertiesA JSON object of key/value pairs which will appear in the stream attachment beneath the description, with each property on its own line. Keys must be strings, and values can be either strings or JSON objects with the keys text and href.
(會接在圖片上description後面)
actionsA JSON array containing a single object describing the action link which will appear next to the "Comment" and "Like" link under posts. The contained object must have the keys name and link.
"{'name'='text', 'link'='URL'}"
(會在圖片上like, comment的右邊然後文字為text,連結為URL)



http://developers.facebook.com/docs/reference/dialogs/feed/
https://developers.facebook.com/docs/reference/dialogs/

Facebook LoginButton Permissions

在新增LoginButton時,可設定可被公開的權限,那一總共有哪些
final List<String> PERMISSIONS_PUBLISH = Arrays.asList("publish_actions", "publish_checkins");
LoginButton authButton=(LoginButton)findViewById(R.id.authButton);authButton.setPublishPermissions(PERMISSIONS_PUBLISH);

PermissionDescription
read_friendlists讓你可取得使用者的好友名單

read_insights讓你可取得使用者允許的可視資料, 應用程式, 網域(domains the user owns)

read_mailbox讓你可取得使用者的收件匣資訊

read_requests讓你可取得使用者的好友所發出的請求

read_stream
讓你可取得使用者塗鴉牆上的News feed, 甚至具備搜尋的能力

xmpp_loginProvides applications that integrate with Facebook Chat the ability to log in users.
ads_managementProvides the ability to manage ads and call the Facebook Ads API on behalf of a user.
create_eventEnables your application to create and modify events on the user's behalf
manage_friendlists讓你的程式可以建立與編輯使用者朋友群組

manage_notificationsEnables your app to read notifications and mark them as read. Intended usage: This permission should be used to let users read and act on their notifications; it should not be used to for the purposes of modeling user behavior or data mining. Apps that misuse this permission may be banned from requesting it.
user_online_presenceProvides access to the user's online/offline presence
friends_online_presenceProvides access to the user's friend's online/offline presence
publish_checkins讓你的程式可以打卡

publish_actionsEnables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends. This requires extra permissions from a person using your app. However, please note that Facebook recommends a user-initiated sharing model. Please read the Platform Policies to ensure you understand how to properly use this permission. Note, you do not need to request the publish_stream permission in order to use the Feed Dialog, the Requests Dialog or the Send Dialog.
rsvp_eventEnables your application to RSVP to events on the user's behalf



https://developers.facebook.com/docs/reference/login/extended-permissions/