2016年1月30日 星期六

Android 開發者 如何從自己開發的程式賺取利潤 AdLocus 篇 1-1


有些Android 開發者 自己開發了應用程式 放上 GooglePlay 上 ,有些可以說是興趣或者是自學 放上去得, 但是算一算 自己也是花了時間 精神 電費 哩哩摳摳的一堆東西 可以說是都是花了成本, 現在交一些開發者 可以自己在 自己的APP上安置廣告 雖然說小咖開發者可能初期賺不到什錢,但是總比放上去  GooglePlay  都沒賺錢都來的好吧!

現在 介紹 手機廣告平臺 AdLocus   開發者可以先去 註冊帳號

第一步:
點取 右上角的註冊
之後就開始填寫一些基本資料



填寫完畢就有一個自己開發者的平臺

然後可以點選應用程式 就可以為自己開發的程式 申請一個 編碼 這是要安置在APP上的 這後面會解釋 


這樣申請帳號 還有 申請APP 廣告編碼 都弄好了 就可以在自己開發的APP 加入廣告
後面會跟大家 說明如何 在APP 上安置廣告 如何加入CODE 如何測試成功 下一篇文章都會解釋給大家聽




2016年1月26日 星期二

Android scheme 用法

在 androidManifest 宣告

先找到 宣告 <action android:name="android.intent.action.MAIN" /> 的地方

之後


    <intent-filter android:label="@string/filter_title_viewrecipe">
         <action android:name="android.intent.action.VIEW" />
         <category android:name="android.intent.category.DEFAULT" />
         <category android:name="android.intent.category.BROWSABLE" />
         <!-- Accepts URIs that begin with "recipe-app://recipes" -->
         <data android:scheme="recipe-app"
               android:host="recipes" />
     </intent-filter>
     <intent-filter android:label="@string/filter_title_viewrecipes">
         <action android:name="android.intent.action.VIEW" />
         <category android:name="android.intent.category.DEFAULT" />
         <category android:name="android.intent.category.BROWSABLE" />
         <!-- Accepts URIs that begin with "http://recipe-app.com/recipes" -->
         <data android:scheme="http"
               android:host="recipe-app.com"
               android:pathPrefix="/recipes" />
     </intent-filter>

加上這段Code

之後 手機只要點擊 recipe-app://recipes 連結 就會開啟APP

但是要先安裝該APP 才會打開

2016年1月25日 星期一

Android 排序 用法

先繼承
implements Comparable<ResultData>

之後就會 導入

@Override
public int compareTo(ResultData another) {
// TODO Auto-generated method stub
return this.KmList -another.KmList;
}
這個方法

- another   意思是 由小排到大
相反則 是 大排到小

 
但還要在妳的 頁面宣告一個新的 Gson  

這邊是宣告 int kmList

Activity



  float listdistance = 0;
if (Latitude != null && Longitude != null) {
 Cal_TWD97_To_lonlat(Double.parseDouble(data.TW97X),                                               Double.parseDouble(data.TW97Y));
               
                   Location crntLocation = new Location("");
                   crntLocation.setLatitude(Double.parseDouble(Latitude));
                   crntLocation.setLongitude(Double.parseDouble(Longitude));
                   Location newLocation = new Location("");
                   newLocation.setLatitude(latList);
                   newLocation.setLongitude(lonList);
                       listdistance = crntLocation.distanceTo(newLocation); // in m
//                    listdistance = listdistance / 1000;//km
                      data.KmList = (int) listdistance;
               }
               Log.e("Jack",data.KmList+"");
              
allData.add(data);
Collections.sort(allData);


這邊是用距離去排序

所以要用現在距離 去算撈取來JSON的距離

之後 塞回kmlsit 這個Gson 裡面

因為
我們的格式是 ArrayList<ResultData> allData 

所以必須用 Collections.sort(allData); 這個方式  Collections.sort(List<T> lsit)
'
這樣就可以看到妳的list 頁面呈現出 近到遠的 畫面了

之後 可以 將 kmlist 這個當作 距離 多遠去使用他

"距離:" + new DecimalFormat("0.0").format(data.KmList);

這邊是沒除於1000  所以拿出來是公尺

2016年1月22日 星期五

Android W97D 格式 轉經緯度

private double lon0 = 121 * Math.PI / 180;
private double k0 = 0.9999;
private int dx = 250000;
 private int dy = 0;
 private static double a = 6378137.0;
 private static double b = 6356752.3142451;
 private double e = 1 - Math.pow(b, 2) / Math.pow(a, 2);
 private double e2 = (1 - Math.pow(b, 2) / Math.pow(a, 2)) / (Math.pow(b, 2) / Math.pow(a, 2));


 private String Cal_TWD97_To_lonlat(double x, double y)
 {
   x -= dx;
   y -= dy;

   // Calculate the Meridional Arc
   double M = y / k0;

   // Calculate Footprint Latitude
   double mu = M / (a * (1.0 - e / 4.0 - 3 * Math.pow(e, 2) / 64.0 - 5 * Math.pow(e, 3) / 256.0));
   double e1 = (1.0 - Math.sqrt(1.0 - e)) / (1.0 + Math.sqrt(1.0 - e));

   double J1 = (3 * e1 / 2 - 27 * Math.pow(e1, 3) / 32.0);
   double J2 = (21 * Math.pow(e1, 2) / 16 - 55 * Math.pow(e1, 4) / 32.0);
   double J3 = (151 * Math.pow(e1, 3) / 96.0);
   double J4 = (1097 * Math.pow(e1, 4) / 512.0);

   double fp = mu + J1 * Math.sin(2 * mu) + J2 * Math.sin(4 * mu) + J3 * Math.sin(6 * mu) + J4 * Math.sin(8 * mu);

   // Calculate Latitude and Longitude
   double C1 = e2 * Math.pow(Math.cos(fp), 2);
   double T1 = Math.pow(Math.tan(fp), 2);
   double R1 = a * (1 - e) / Math.pow((1 - e * Math.pow(Math.sin(fp), 2)), (3.0 / 2.0));
   double N1 = a / Math.pow((1 - e * Math.pow(Math.sin(fp), 2)), 0.5);

   double D = x / (N1 * k0);

   // 計算緯度
   double Q1 = N1 * Math.tan(fp) / R1;
   double Q2 = (Math.pow(D, 2) / 2.0);
   double Q3 = (5 + 3 * T1 + 10 * C1 - 4 * Math.pow(C1, 2) - 9 * e2) * Math.pow(D, 4) / 24.0;
   double Q4 = (61 + 90 * T1 + 298 * C1 + 45 * Math.pow(T1, 2) - 3 * Math.pow(C1, 2) - 252 * e2) * Math.pow(D, 6) / 720.0;
   double lat = fp - Q1 * (Q2 - Q3 + Q4);

   // 計算經度
   double Q5 = D;
   double Q6 = (1 + 2 * T1 + C1) * Math.pow(D, 3) / 6;
   double Q7 = (5 - 2 * C1 + 28 * T1 - 3 * Math.pow(C1, 2) + 8 * e2 + 24 * Math.pow(T1, 2)) * Math.pow(D, 5) / 120.0;
   double lon = lon0 + (Q5 - Q6 + Q7) / Math.cos(fp);

   lat = (lat * 180) / Math.PI; //緯度
   lon = (lon * 180) / Math.PI; //經度

   String lonlat = lon + "," + lat;
   Log.e("Jack",lonlat);
   return lonlat;
 }



2016年1月21日 星期四

Android 倒數計時器 CountDownTimer

new CountDownTimer(10000, 1000) {

 @Override

 public void onTick(long millisUntilFinished) {
                //倒數秒數中要做的事
  textView.setText("倒數時間:" + new SimpleDateFormat("s").format(millisUntilFinished));
 }

 @Override
 public void onFinish() {
                 //倒數完成後要做的事
 }
}.start();



第一個參數是總共計時幾秒,以0.001為單位,因此要讓它倒數10秒就要乘上10*1000,
第二個參數是每隔幾秒跳一次,一樣以0.001為單位,因此每隔一秒跳一次就是傳入1000。

2016年1月12日 星期二

Android 取得目前位置

1. 在 AndroidManifest
宣告
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Activty
implements android.location.LocationListener


onCreate 


this.locationMgr = (LocationManager) this.getSystemService(LOCATION_SERVICE);


@Override
protected void onResume() {
super.onResume();
// mAdapter.updateData(mAllData);
// 取得位置提供者,不下條件,讓系統決定最適用者,true 表示生效的 provider
String provider = this.locationMgr.getBestProvider(new Criteria(), true);
if (provider == null) {
Log.e("jack","沒有 location provider 可以使用");
return;
}
Log.e("jack","取得 provider - " + provider);
this.locationMgr.requestLocationUpdates(provider, 0, 0, this);
Location location = this.locationMgr.getLastKnownLocation(provider);
if (location == null) {
Log.e("jack","未取過 location");
 location=this.locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
 this.onLocationChanged(location);
return;
}
Log.e("jack","取得上次的 location");
this.onLocationChanged(location);
}
@Override
protected void onPause() {
super.onPause();
Log.e("jack","removeUpdates...");
this.locationMgr.removeUpdates(this);
}




@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onLocationChanged(Location location) {
Log.e("Jack", "onLocationChanged...");
String msg = "經度: " + location.getLongitude() + ", 緯度: "
+ location.getLatitude();
Log.e("Jack", msg);

}


//取得系統定位服務
LocationManager status = (LocationManager) (this.getSystemService(Context.LOCATION_SERVICE));
if (status.isProviderEnabled(LocationManager.GPS_PROVIDER) || status.isProviderEnabled(LocationManager.NETWORK_PROVIDER))

{

Log.e("Jack","有開啟定位服務");
} else {
Log.e("Jack","請開啟定位服務");
Toast.makeText(this, "請開啟定位服務", Toast.LENGTH_LONG).show();
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); //開啟設定頁面
}

Google Analytics 如何透過google 分析

1. 新增一個 Class
public class URGAManager {

    private static Tracker TRACKER;

    public synchronized static Tracker getTracker(Context context)
    {
        if (TRACKER == null)
        {
            String trackerId = context.getResources().getString(R.string.ga_trackingId);
            TRACKER = GoogleAnalytics.getInstance(context).newTracker(trackerId);
            TRACKER.enableExceptionReporting(true);
            TRACKER.enableAdvertisingIdCollection(true);
            TRACKER.enableAutoActivityTracking(true);
        }

        return TRACKER;
    }

    public static void sendScreenName(Context context, String name)
    {
        Tracker tracker = getTracker(context);
//        tracker.setScreenName(name);        tracker.send(new HitBuilders.ScreenViewBuilder().set(name, null).build());
    }
}

之後就可以在 Activity Oncreate 中 呼叫 

URGAManager.sendScreenName(this, String Name);

2. 在 Values 下 新增一個 xml


<?xml version="1.0" encoding="utf-8"?><resources>

    <!-- Replace placeholder ID with your tracking ID -->    <string name="ga_trackingId">UA-67880020-1</string>

    <!-- Enable automatic activity tracking -->    <bool name="ga_autoActivityTracking">true</bool>

    <!-- Enable automatic exception tracking -->    <bool name="ga_reportUncaughtExceptions">true</bool>

    <item name="ga_dispatchPeriod" format="integer" type="integer">3</item>

</resources>


3. 在AndroidManifest 中 宣告

<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"    android:enabled="true">
    <intent-filter>
        <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
    </intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.AnalyticsService"    android:enabled="true"    android:exported="false"/>

4. compile 'com.google.android.gms:play-services-analytics:8.1.0'


這樣就可以在後台 看到GOOGLE 分析了