參考資料 : Android Tabs Example – With Fragments and ViewPager
參考資料 : TabLayout (Android Design Library) Text Color
2015年11月26日 星期四
2015年11月25日 星期三
2015年11月22日 星期日
Android-AndroidStudio GCM
更新日期 : 20160318_新增註冊ID內容
使用 AndroidStudio 為 App 添加 GCM( Google Cloud Message )
想必大大對 GMC 不陌生吧
如果不知道的沒關係
以下舉例您可能馬上就知道
1 . 安裝應用 App 三不五時就會收到擾人的通知
2 . 安裝應用 遊戲 後,突然收到開戰通知!!!
這些大多都是 推播 ( 以GCM為例 )!!!
為啥要以 GCM 為範例?
其實微軟、亞馬遜也有提供
但是以大眾來講 GCM 是最普及的
進入重點
是如何動作的
1 . 開發者向 Google 申請序號
2 . 在 App 內放置序號並且實作 GCM
3 . 成功之後會回傳 Token
4 . 開發者將 Token 傳送到指定位置存放
5 . 開發者將指定 Token 配合並發送,使用者手機就可收到訊息
步驟
1 . 申請專案序號
連結 : GoogleDevelopersConsole
參考資料 : android-gcm-tool
參考資料 : Push Notification using GCM in Android Studio | Google Cloud Messaging
使用 AndroidStudio 為 App 添加 GCM( Google Cloud Message )
想必大大對 GMC 不陌生吧
如果不知道的沒關係
以下舉例您可能馬上就知道
1 . 安裝應用 App 三不五時就會收到擾人的通知
2 . 安裝應用 遊戲 後,突然收到開戰通知!!!
這些大多都是 推播 ( 以GCM為例 )!!!
為啥要以 GCM 為範例?
其實微軟、亞馬遜也有提供
但是以大眾來講 GCM 是最普及的
進入重點
是如何動作的
1 . 開發者向 Google 申請序號
2 . 在 App 內放置序號並且實作 GCM
3 . 成功之後會回傳 Token
4 . 開發者將 Token 傳送到指定位置存放
5 . 開發者將指定 Token 配合並發送,使用者手機就可收到訊息
步驟
1 . 申請專案序號
連結 : GoogleDevelopersConsole
參考資料 : android-gcm-tool
參考資料 : Push Notification using GCM in Android Studio | Google Cloud Messaging
2015年11月21日 星期六
Java-日期/時間 格式轉換
更新日期 : 20151212 ( 新增流程 )
流程 :
1 . 資料來源
2 . 來源格式
3 . 目的格式
4 . 將來資料來源轉換成 Date (parse)
5 . 將 來源Date 套用在 目的格式 (format)
6 . 轉換成字串
歡迎轉載,請註明出處。
流程 :
1 . 資料來源
2 . 來源格式
3 . 目的格式
4 . 將來資料來源轉換成 Date (parse)
5 . 將 來源Date 套用在 目的格式 (format)
6 . 轉換成字串
try {
// 1 ( 二選一 )
// 自定義
String date = "2015/12/12 07:07:07";
// 系統時間
DateFormat dateFormat_1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String date = dateFormat_1.format(new Date());
System.out.println(date);
// 2
DateFormat dateFormat_1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
// 3
DateFormat dateFormat_2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 4
Date date_org = dateFormat_1.parse(date);
// 5 . 6
String myDate = dateFormat_2.format(date_org);
System.out.println(myDate);
} catch (ParseException e) {
e.printStackTrace();
}
歡迎轉載,請註明出處。
2015年11月18日 星期三
Android-左右滑動圖片 Image ViewPager
參考資料 : 使用ViewPager实现左右滑动效果
參考資料 : Android实现左右滑动指引效果
參考資料 : Android通过ViewPager实现左右滑动切换图片
參考資料 : Android 基于ImageSwitcher实现的左右切换图片
參考資料 : Android Image Slideshow using ViewPager with PagerAdapter
( 有成功,但是沒壓縮造成反應遲緩,無引導點 )
若改無限制
參考資料 : Android UI设计——ViewPager中设置底部显示圆点焦点(二)
( 引導點 )
參考資料 : 用ViewPager实现欢迎引导页面
( 帶有引導點,可動態增加圖片 )
參考資料 : Android Image Slideshow using ViewPager with PagerAdapter
( 有成功,但是沒壓縮造成反應遲緩,無引導點 )
若改無限制
@Override
public int getCount() {
return mResources.length;
}
圖片來源記得要取餘數,不然會 Exception參考資料 : Android UI设计——ViewPager中设置底部显示圆点焦点(二)
( 引導點 )
參考資料 : 用ViewPager实现欢迎引导页面
( 帶有引導點,可動態增加圖片 )
2015年11月13日 星期五
Android-Google Ads 廣告置入 範例 Sample
20170311 新增:整頁廣告
想必大家都聽過寫 App 然後靠廣告賺錢
1 . 在 Gradle 內加入
2 . 在要呈現的版面新增元件
3 . 宣告元件
4 . 將 AdMob 給的序號添加在 String.xml
序號來源 以下有教學
----------------------------------------------------------------
關於廣告帳號註冊
1 . 申請 Ads 帳號
首頁
https://apps.admob.com/#home
註冊Key
https://apps.admob.com/#monetize/pubcontrols:urls
參考資料: Interstitial Ads
參考資料:Interstitial Ads 無法顯示的問題
歡迎轉載,請註明出處。
想必大家都聽過寫 App 然後靠廣告賺錢
那要如何把廣告植入在我們的心血?
其實沒有我們想像的困難
此 Sample 是以 AndroidStudio 版本為主 : 連結
如果大大是以 Eclipse 開發 請參考 : 連結
雖然網路以上有流程
但只需要自己所要的部分
1 . 在 Gradle 內加入
compile 'com.google.android.gms:play-services-ads:7.8.0'
2 . 在要呈現的版面新增元件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
.
.
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
3 . 宣告元件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
.
.
}
4 . 將 AdMob 給的序號添加在 String.xml
序號來源 以下有教學
<resources>
<string name="banner_ad_unit_id">ca-app-pub-111222333444555666/555444111</string>
</resources>
----------------------------------------------------------------
關於廣告帳號註冊
1 . 申請 Ads 帳號
https://apps.admob.com/#home
註冊Key
https://apps.admob.com/#monetize/pubcontrols:urls
參考資料: Interstitial Ads
參考資料:Interstitial Ads 無法顯示的問題
歡迎轉載,請註明出處。
Android-Parse Push ParsePushBroadcastReceiver ( 三 )
在前面兩個章節有介紹如何 :
You can add key in onReciver
- String strChannel = intent.getExtras().getString("com.parse.Channel");
- String strData = intent.getExtras().getString("com.parse.Data");
2 . 將原先的註冊的 Receiver 更改
( 更改成剛剛繼承的 Receiver )
3 . 如果覺得原生的 Notification 太單調,也可以改成自己的
歡迎轉載,請註明出處。
- 初始化 Parse
- 接收 Parse Push Message
- 發送 Push Message
這次我們要做第二點的延伸
延伸?
簡單的說,Parse SDK 有預設
但我們想自己做 Design 這樣可以嗎??
Notification Icon、Notification Message ...etc.
Notification Icon、Notification Message ...etc.
當然是可以的
1 . extends ParsePushBroadcastReceiver
( ex : is ParsePushBroadcastReceiver, isn't ParseBroadcastReceiver )
( ex : is ParsePushBroadcastReceiver, isn't ParseBroadcastReceiver )
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.parse.ParsePushBroadcastReceiver;
public class MyParseReceiver extends ParsePushBroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("MyParseReceiver", "action:" + action);
}
}
You can add key in onReciver
- String strChannel = intent.getExtras().getString("com.parse.Channel");
- String strData = intent.getExtras().getString("com.parse.Data");
2 . 將原先的註冊的 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.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
( 更改成剛剛繼承的 Receiver )
<receiver
android:name="MyParseReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
3 . 如果覺得原生的 Notification 太單調,也可以改成自己的
// 將提醒功能取消
@Override
protected Notification getNotification(Context context, Intent intent) {
return null;
}
private void myNotification(...){
Notification...
}
歡迎轉載,請註明出處。
訂閱:
意見 (Atom)



