小编pau*_*lab的帖子

支持库VectorDrawable Resources $ NotFoundException

我使用的是Design Support Library版本23.4.0.我启用了gradle标志:

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}
Run Code Online (Sandbox Code Playgroud)

我正在使用构建工具版本23.0.2,但仍然,我正在Resources$NotFoundException使用KitKat或更低版本.

它发生在我使用android:drawableLeft或时imageView.setImageResource(R.drawable.drawable_image).

是的,我把它放在我使用drawables的每个活动上

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)

这是支持库的错误吗?

android android-support-library androiddesignsupport android-vectordrawable

67
推荐指数
8
解决办法
3万
查看次数

如何为桌面上的任何应用创建快捷方式?

我想我已经尝试了我在互联网上找到的所有解决方案,但没有人工作 - 没有力量关闭,但桌面上没有任何内容.

现在,我有这个:

private void createShortcutOnDesktop(Application app) {

    Intent shortcutIntent = new Intent();
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, app.getIntentShortcut());
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, app.getName());
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.home_button));
    shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    this.sendBroadcast(shortcutIntent);
    finish();

}
Run Code Online (Sandbox Code Playgroud)

app.getIntentShortcut():

public Intent getIntentShortcut() { 

    Intent i = new Intent();
    i.setClassName(packageName, name);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    return i;
}
Run Code Online (Sandbox Code Playgroud)

并在AndroidManifest.xml文件中:

<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
Run Code Online (Sandbox Code Playgroud)

我错过了什么?谢谢.

android android-permissions android-shortcut

11
推荐指数
1
解决办法
8593
查看次数

通知未出现在 notify() 上

我最近在让许多特定功能在 Android Studio 上工作时遇到了困难。最近我正在尝试显示简单的通知。他们永远不会出现。在这一点上,我觉得我已经尝试了一切。这是我的代码。

public class NotificationReceiver extends BroadcastReceiver {

private final String TAG = NotificationReceiver.class.getSimpleName();

@Override
public void onReceive(Context context, Intent intent) {
    Intent notificationIntent = new Intent(context, ScrollingActivity.class);

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ScrollingActivity.class);
    taskStackBuilder.addNextIntent(notificationIntent);

    PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(100, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "channel");

    Notification notification = builder.setContentTitle("My Test Notification")
            .setContentText("This is some sample test notification. (Congratulations!)")
            .setTicker("New Message Alert!")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentIntent(pendingIntent).build();

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}}
Run Code Online (Sandbox Code Playgroud)

这是我用来调用通知的方法。

 public void setRepeatingNotification(){
    Calendar repeatCalendar = …
Run Code Online (Sandbox Code Playgroud)

notifications android notificationmanager notification-channel

5
推荐指数
1
解决办法
4203
查看次数

如何在Fragments中使用getSupportLoaderManager()?

我想将API中的信息加载到Fragment.

我使用getSupportLoaderManager()但发生错误:

无法解析方法:getSupportLoaderManager()

我搜索这个用途,onActivityCreated()但我有NullPointerException.

你能帮我解决一下这个问题吗?

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class Business extends Fragment implements LoaderManager.LoaderCallbacks<String> {

    ListView listView;   

    public Business() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_business, container, false);
        listView = view.findViewById(R.id.list_item);

        getSupportLoaderManager().initLoader(0, null, getContext()).forceLoad();
        return view;
    }

    @Override
    public Loader<String> onCreateLoader(int id, Bundle args) {
        return null; …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-loadermanager

4
推荐指数
1
解决办法
1162
查看次数

Android AsyncTask通过http Post发送数据

我有这个脚本.

我已经经历了堆栈溢出问题的许多变化,并使用解决方案尝试构建知识来做到这一点,但它似乎每次都失败,有人可以帮忙吗?

public class Main extends Activity implements OnClickListener {

    private EditText value;
    private Button btn;
    private ProgressBar pb;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        value = (EditText) findViewById(R.id.editText1);
        btn = (Button) findViewById(R.id.button1);
        pb = (ProgressBar) findViewById(R.id.progressBar1);
        pb.setVisibility(View.GONE);
        btn.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (value.getText().toString().length() < 1) {
            // out of range
            Toast.makeText(this, "please enter something", Toast.LENGTH_LONG)
                    .show();
        } else …
Run Code Online (Sandbox Code Playgroud)

android httprequest android-asynctask

3
推荐指数
1
解决办法
2万
查看次数

如何使用 Picasso 共享从服务​​器加载的图像?

我需要帮助。
我已经使用网络服务从服务器获取了一张图片,但我不分享这张图片。

我附上了我的代码,请帮我找出错误。

share.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Bitmap bitmap = viewToBitmap(iv, iv.getWidth(), iv.getHeight());
        Intent shareintent = new Intent(Intent.ACTION_SEND);
        shareintent.setType("image/jpeg");
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
        File file = new File(Environment.getExternalStorageDirectory() + 
                             File.separator + "Imagedemo.jpg");
        try {
            file.createNewFile();
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            fileOutputStream.write(byteArrayOutputStream.toByteArray());
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        shareintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/Imagedemo.jpg"));

        startActivity(Intent.createChooser(shareintent,"share image"));
    }
}); 
Run Code Online (Sandbox Code Playgroud)
public static Bitmap viewToBitmap(View view, int width, int height){

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas …
Run Code Online (Sandbox Code Playgroud)

android picasso

3
推荐指数
1
解决办法
1844
查看次数

使用Android操作栏分享意图

我正在使用操作栏上的菜单项,我想通过单击共享图标来共享我的应用程序.当我单击共享图标时,它不起作用.另外,我想"install this app"在共享时添加文字说明.

这是我的代码:

private ShareActionProvider mShareActionProvider;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.mainpage, menu);
    MenuItem item = menu.findItem(R.id.menu_item_share);
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();

    return true;
}

private void setShareIntent(Intent shareIntent) {
    if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(shareIntent);
    }
}
Run Code Online (Sandbox Code Playgroud)

Mainpage.xml菜单:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_item_share"
    android:showAsAction="ifRoom"
    android:title="Share"
    android:icon="@drawable/ic_store"
    android:actionProviderClass="android.widget.ShareActionProvider" />
</menu>
Run Code Online (Sandbox Code Playgroud)

android android-menu android-optionsmenu

2
推荐指数
1
解决办法
1万
查看次数

如何在 Android 中将 MPCharts 的字符串转换为条形条目

在我的 Android 应用程序中,我对图表不熟悉,并且使用MPchart 库来绘制图表。我在 X 轴和 Y 轴上使用字符串数组显示图表。

对于 x 轴,我成功创建了它,但对于 Y 轴,我需要将其转换ArrayList<String>BarData数组列表。我不知道如何转换它。谁能告诉我如何实现这一目标?

对于 X 轴:

private ArrayList<String> getXAxis() {
            ArrayList<String> xAxis = new ArrayList<>();
            xAxis = new ArrayList<String>(Arrays.asList(bar_graph_names)); //converting string to arraylist
            return xAxis;
        }
Run Code Online (Sandbox Code Playgroud)

对于 Y 轴绘图值:

private ArrayList<BarDataSet> getData() {
        ArrayList<String> yAxis_conv = new ArrayList<>();
        yAxis_conv = new ArrayList<String>(Arrays.asList(bar_graph_values));

        ArrayList<BarDataSet> yAxis_Datasets=null;
        ArrayList<BarEntry> yAxis = new ArrayList<>();

        for(int i = 0; i < bar_graph_values.length; i++)
        {
            BarEntry [] barentry = new BarEntry[bar_graph_values.length]; …
Run Code Online (Sandbox Code Playgroud)

android graph mpandroidchart

1
推荐指数
1
解决办法
5317
查看次数