發表文章

目前顯示的是 11月, 2016的文章

Notification 改新寫法

Notification Noti=new Notification(); Intent i = new Intent(this, MainActivity.class);    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);               Noti.icon =   R . drawable . notification_icon ; // notification icon id Noti.tickerText=mc.getResources().getString(R.string.app_name); Noti.when=System.currentTimeMillis();      Noti.flags=Notification.FLAG_ONGOING_EVENT;     // setLatestEventInfo 已被放棄 Noti.setLatestEventInfo( mc, mc.getResources().getString( "My notification" ), mc.getResources().getString( "Hello World!" ) , PendingIntent.getActivity(this, 0,i, 0) ); NotificationManager myNM = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); myNM.notify(0,Noti); 改成如下 NotificationCompat . Builder mBuilder =         new NotificationCompat . Builder ( this )         . setSmallIcon ( R . drawable . notification_icon )         . setCont

android studio signed apk

圖片
有時候我們會希望每次編譯出來的 apk 都是有 sign 過的,Android Studio 提供了這樣的選擇。 方法如下,當然也可以直接在Gradle中寫好。 不過我們還是用用圖形介面比較方便。 一、點擊左下方的Build Variants,會跳出側邊欄位如下。在跳出來的欄位裡面Build Variant中選release。 二、我們到app資料匣,點右鍵,選Open Module Settings。如下 三、先選Signing,自己新增一個認證。 Name,key Alias,key Password, Store File, Store Password, 這幾項都填一填。 四、再選Build Types, 先選release ,在 Signing Config 中選第三個步驟中自己新增的認證,剛剛的 Name 會出現在下拉選單中。 五、最後,按OK。這樣就大功告成。接下來每次編譯就會直接給出 sign 過的 apk。