我一直致力于推送通知,我能够实现它并在状态栏上显示它,我面临的问题是我想显示它,即使手机是锁定的,在它所说的锁定屏幕下("拖动解锁"),我已经看过这样的通知,但无法找到任何示例.
示例: 就像您收到未接来电一样,它会在屏幕上的锁定按钮下显示.
码:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon_launcher;
CharSequence tickerText = "MyApplication";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS;;
CharSequence contentTitle = this.title;
CharSequence contentText = this.message;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTICE_ID, notification);
Run Code Online (Sandbox Code Playgroud) 我试图从代码中制作一个框架,以便我可以应用它来制作圆形内角,外部有一个实心填充,内部是透明的.就像一个内部透明椭圆形的实心矩形.附图.我尝试了几种形状组合,所有可用的在线显示外面的角落.

里面应该透明而不是白色.图像来自这篇文章,但这里提出的解决方案不是我想要的我不想使用9补丁drawable但希望在代码中创建.
请仅提供有效答案.
嗨,无论如何提供drawable文件夹中drawable.xml中定义的drawable的宽度和高度.
例:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
Run Code Online (Sandbox Code Playgroud)
我想指定宽度和高度可能以某种方式在其中使用" scale "标签,我试过但没有工作.这是我的代码:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_ratingstar">
<scale android:scaleWidth="20" android:scaleHeight="20" android:drawable="@drawable/icon_ratingstar" />
</item>
</selector>
Run Code Online (Sandbox Code Playgroud) 我试图在列表标题中添加Viewpager(使用支持库4),但它没有显示任何内容.这是我的代码请帮忙.它将在列表标题中不作为项目,因此它不应该是一个问题.
public class CustomActivity extends ListActivity {
private static int NUM_AWESOME_VIEWS = 20;
private Context cxt;
private CustomPageAdapter pageAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] items = { "this", "is", "my", "list", "view", "data" };
this.cxt = this;
ViewPager viewPager = new ViewPager(this);
pageAdapter = new CustomPageAdapter();
viewPager.setAdapter(pageAdapter);
viewPager.requestLayout();
getListView().addHeaderView(viewPager);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
}
private class CustomPageAdapter extends PagerAdapter{
@Override
public int getCount() {
return NUM_AWESOME_VIEWS;
}
/** …Run Code Online (Sandbox Code Playgroud) 我一直在努力实现同样的目标,这正是我想要的: -

我用叠加层实现了googleMapView,我有一个问题,我想在点击每个叠加层时显示一个弹出窗口,当我点击另一个叠加层时,前一个popus应该消失,新的一个应该出现在点击的位置(即投影点).当我点击屏幕上的任何其他地方时弹出窗口不应该出现.我使用onTap事件记录onclick.(map_overlay)是当有人点击地图上的投影点时我想要显示的布局.代码如下,map_overlay.xml可以是任何文件.
类:ItemizedOverlay
public boolean onTap(GeoPoint p, MapView mapView) {
LayoutInflater inflater = (LayoutInflater)cContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, p, LayoutParams.WRAP_CONTENT);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.map_overlay, null);
mapView.removeView(view);
mapView.invalidate();
mapView.addView(view,lp);
mapView.invalidate();
return true;
}
Run Code Online (Sandbox Code Playgroud)
下面是主要类,其中我显示了正常工作的投影点,即时调用我已经在另一个类中实现了onTap事件,如上所示:
public **class MapView** extends MapActivity{
private ArrayList<MyClass> overlayItem ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.large_mapview);
mapView = (MapView) findViewById(R.id.mapview);
// mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mappointer2);
ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable,this);
OverlayItem overlayitem;
GeoPoint point;
double lat;
double lng; …Run Code Online (Sandbox Code Playgroud) 嗨,我想添加Facebook连接到我的Android应用程序,我确实设法发布在我的墙上的应用程序,但当我下载Android Facebook应用程序并登录它但现在我不能发布在我的墙上.我收到此错误:
{"error":{"type":"OAuthException","message":"An active access token
must be used to query information about the current user."}}
Run Code Online (Sandbox Code Playgroud)
码:
公共类FacebookLogin扩展Activity {
private static final String APP_API_ID = "080808998-myappId";
Facebook facebook = new Facebook(APP_API_ID);
private AsyncFacebookRunner mAsyncRunner;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mAsyncRunner = new AsyncFacebookRunner(facebook);
SessionStore.restore(facebook, this);
SessionEvents.addAuthListener(new SampleAuthListener());
Log.i("Error", facebook.getAccessToken()+"tokenId");
facebook.dialog(FacebookLogin.this, "feed", new SampleDialogListener());
}
public void postOnWall(String msg) {
try {
Bundle bundle = new Bundle();
bundle.putString("message", msg);
bundle.putString("from", "fromMe");
bundle.putString("link","facebook.com");
bundle.putString("name","name of the link facebook");
bundle.putString("description","some description …Run Code Online (Sandbox Code Playgroud) 我试图将android代码打包到一个jar文件中,以便我可以在另一个项目中使用它.但是,当我这样做时,我收到以下错误消息.如果有人这样做,我不确定如何正确地做到这一点请发布链接,一些细节将非常有用.
谢谢
Error generating final archive: Found duplicate file for APK: AndroidManifest.xml
Origin 1: C:\Users\Admin\workspace\Test\bin\resources.ap_
Origin 2: C:\Users\Admin\workspace\Test\lib\JarLib.jar
Run Code Online (Sandbox Code Playgroud)
我必须在很多项目中使用它,所以我想将其编译为jar,就像在线提供的其他库一样,如twitter4j,googleAnalytic和androidsupportlibrary,我需要知道哪个文件夹必须包含在Jar文件中.我尝试通过排除resources文件夹并使用eclipse-> export来构建它,虽然它构建了jar但是在另一个测试项目中包含它会显示上面的错误消息.
我正在尝试使用包含数据源的AsynchTaskLoader实现ListFragment但是我在刷新listFragment时遇到了麻烦,因为当我从BaseAsyncTaskLoader中的后台更改数据时它没有得到刷新
代码附后:
加载listfragment的Activity
public class BaseFragmentManager extends FragmentActivity implements ListItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_stack);
Button btnLoadMore = (Button) findViewById(R.id.new_fragment);
btnLoadMore.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent();
i.setAction("com.test.gcc.myintent.loader.BaseAsyncTaskLoader");
i.putExtra("action", "loadmore");
sendBroadcast(i);
}
});
BaseListFragmentActivity fragment = new BaseListFragmentActivity();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
@Override
public void onListItemSelected(int index) {
Log.i("Error", "itemSelected-"+index);
}
}
Run Code Online (Sandbox Code Playgroud)
我的LISTFragment类没有被刷新
public class BaseListFragmentActivity extends ListFragment implements LoaderManager.LoaderCallbacks<ArrayList<MyData>> {
private ListItemSelectedListener selectedListener; …Run Code Online (Sandbox Code Playgroud) 我试图将数据保存到sdCard首先我试图在使用getExternalFilesDir的externalStorage上的app目录中私下保存它但是给了我nullPointerException所以我尝试了下面给出的其他方式它工作但是当我想将文件存储到我想要的自定义目录自己命名它给我错误:
FileOutputStream os;
dirName = "/mydirectory/";
try {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)){
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + dirName);
dir.mkdirs();
//File file = new File(this.getExternalFilesDir(null), this.dirName+fileName); //this function give null pointer exception so im using other one
File file = new File(dir, dirName+fileName);
os = new FileOutputStream(file);
}else{
os = context.openFileOutput(fileName, MODE_PRIVATE);
}
resizedBitmap.compress(CompressFormat.PNG, 100, os);
os.flush();
os.close();
}catch(Exception e){
}
Run Code Online (Sandbox Code Playgroud)
错误日志:
java.io.FileNotFoundException:/mnt/sdcard/mvc/mvc/myfile2.png(没有这样的文件或目录)