Reference:
https://developers.google.com/maps/documentation/android-api/controls#toolbar
Code sinppet:
mMap.getUiSettings().setMapToolbarEnabled(false);
2016年1月25日 星期一
2016年1月11日 星期一
[Exception] couldn't find class 'com.google.android.gms.measurement.internal.zzz'
References:
http://stackoverflow.com/questions/33196015/error-on-some-devices-couldnt-find-class-com-google-android-gms-measurementError log:
01-12 14:45:58.910 4347-4347/? E/dalvikvm﹕ Could not find class 'com.google.android.gms.measurement.internal.zzx', referenced from method com.google.android.gms.measurement.internal.zzt.zzaUjava.lang.VerifyError: com/google/android/gms/measurement/internal/zzt
at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
at android.app.ActivityThread.installProvider(ActivityThread.java:4897)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4487)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4427)
at android.app.ActivityThread.access$1500(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1302)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613)
at dalvik.system.NativeStart.main(Native Method)
Code snippet:
MyApplication.javapublic class MyApplication extends Application {
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
AndroidManifest.xml
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/xxxxxx"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
Solution:
This happens because of multi-dexing. When your code is so big that it can't be compiled with a single dex file, we use multidexing. But after that it wouldn't run on all phones2016年1月10日 星期日
Get application directory
Reference:
http://stackoverflow.com/questions/5527764/get-application-directoryCode snippet:
PackageManager m = getPackageManager();String s = getPackageName();
try {
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.dataDir;
} catch (PackageManager.NameNotFoundException e) {
Log.w("yourtag", "Error Package name not found ", e);
}
2016年1月8日 星期五
Open Google Play Store for your application
Reference:
http://stackoverflow.com/questions/11753000/how-to-open-the-google-play-store-directly-from-my-android-applicationCode snippet:
String appPackageName = "Your app package name";try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
2015年12月27日 星期日
Center text on a bitmap
Reference:
http://www.skoumal.net/en/android-how-draw-text-bitmap/Code snippet:
Bitmap cloneMarkerBitmap = oriMarkerBitmap.copy(Bitmap.Config.ARGB_8888,true);Canvas canvas = new Canvas(cloneMarkerBitmap);
Paint textPaint = new Paint();
textPaint.setColor(mResources.getColor(R.color.white));
textPaint.setTextSize(convertDpToPixel(12));
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
// draw text to the Canvas center
String markerNumber = Integer.toString(number);
Rect bounds = new Rect();
textPaint.getTextBounds(markerNumber, 0, markerNumber.length(), bounds);
int x = (cloneMarkerBitmap.getWidth())/2;
int y = (cloneMarkerBitmap.getHeight() + bounds.height())/2;
canvas.drawText(markerNumber, x, y, textPaint);
...............
public float convertDpToPixel(float dp) {
DisplayMetrics metrics = mResources.getDisplayMetrics();
float px = dp * metrics.density;
return px;
}
Multi-line in EditText
Reference:
http://stackoverflow.com/questions/4233626/allow-multi-line-in-edittext-view-in-android
Code snippet:
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|left" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="fill_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>
http://stackoverflow.com/questions/4233626/allow-multi-line-in-edittext-view-in-android
Code snippet:
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|left" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="fill_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>
Send SMS message and get the result
Code snippet:
public void sendSmsMessage(String phoneNumber,String message){
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> messageList = smsManager.divideMessage(message);
PendingIntent mPI = PendingIntent.getBroadcast(MainEntryActivity.this, 0, new Intent("SMS_SENT"), PendingIntent.FLAG_UPDATE_CURRENT);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
for(int i=0;i<messageList.size();i++){
sentIntents.add(mPI);
}
registerReceiver(smsSentReceiver, new IntentFilter("SMS_SENT"));
smsManager.sendMultipartTextMessage (phoneNumber, null, messageList, sentIntents, null);
}
private BroadcastReceiver smsSentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String result = "";
switch(getResultCode()) {
case Activity.RESULT_OK:
result = "Transmission successful";
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
result = "Transmission failed";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
result = "Radio off";
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
result = "No PDU defined";
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
result = "No service";
break;
}
Log.d(TAG, "send sms result: " + result);
}
};
@Override
protected void onDestroy() {
try{
unregisterReceiver(smsSentReceiver);
} catch(IllegalArgumentException iae){
Log.d(TAG,"Receiver not registered");
iae.printStackTrace();
}
}
public void sendSmsMessage(String phoneNumber,String message){
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> messageList = smsManager.divideMessage(message);
PendingIntent mPI = PendingIntent.getBroadcast(MainEntryActivity.this, 0, new Intent("SMS_SENT"), PendingIntent.FLAG_UPDATE_CURRENT);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
for(int i=0;i<messageList.size();i++){
sentIntents.add(mPI);
}
registerReceiver(smsSentReceiver, new IntentFilter("SMS_SENT"));
smsManager.sendMultipartTextMessage (phoneNumber, null, messageList, sentIntents, null);
}
private BroadcastReceiver smsSentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String result = "";
switch(getResultCode()) {
case Activity.RESULT_OK:
result = "Transmission successful";
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
result = "Transmission failed";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
result = "Radio off";
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
result = "No PDU defined";
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
result = "No service";
break;
}
Log.d(TAG, "send sms result: " + result);
}
};
@Override
protected void onDestroy() {
try{
unregisterReceiver(smsSentReceiver);
} catch(IllegalArgumentException iae){
Log.d(TAG,"Receiver not registered");
iae.printStackTrace();
}
}
訂閱:
意見 (Atom)