Android未显示权限

时间:2017-04-14 05:43:19

标签: java android permissions

我已经制作了一个请求互联网权限的应用,但它在应用信息位置没有显示请求的权限。 这是清单文件。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myartsonline.bharath.lowloss">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是我的MainActivity.java文件

package com.myartsonline.bharath.lowloss;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CalendarView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import com.myartsonline.bharath.lowloss.RewardsRecyclerView.Data;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    private static final int INTERNET_PERMISSION = 0;
    LinearLayout home,calendar,rewards,help;
    CalendarView calendarView;
    RecyclerView rewardsRecView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        home=(LinearLayout)findViewById(R.id.homeLayout);
        calendar=(LinearLayout)findViewById(R.id.calendarLayout);
        rewards=(LinearLayout)findViewById(R.id.rewardsLayout);
        help=(LinearLayout)findViewById(R.id.helpLayout);
        calendarView=(CalendarView)findViewById(R.id.calendarView);
        rewardsRecView=(RecyclerView)findViewById(R.id.rewardsRecView);
        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.INTERNET)!= PackageManager.PERMISSION_GRANTED)
        {
            ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.INTERNET}, INTERNET_PERMISSION);
        }
        Data d=new Data(this);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "fab", Toast.LENGTH_SHORT).show();
            }
        });
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
                Toast.makeText(MainActivity.this, i2+"", Toast.LENGTH_SHORT).show();
            }
        });
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.nav_home) {
            calendar.setVisibility(View.GONE);
            rewards.setVisibility(View.GONE);
            help.setVisibility(View.GONE);
            home.setVisibility(View.VISIBLE);
        } else if (id == R.id.nav_calendar) {
            calendar.setVisibility(View.VISIBLE);
            rewards.setVisibility(View.GONE);
            help.setVisibility(View.GONE);
            home.setVisibility(View.GONE);
        } else if (id == R.id.nav_rewards) {
            calendar.setVisibility(View.GONE);
            rewards.setVisibility(View.VISIBLE);
            help.setVisibility(View.GONE);
            home.setVisibility(View.GONE);
        } else if (id == R.id.nav_about) {
            calendar.setVisibility(View.GONE);
            rewards.setVisibility(View.GONE);
            help.setVisibility(View.VISIBLE);
            home.setVisibility(View.GONE);
        }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

2 个答案:

答案 0 :(得分:1)

无需检查互联网许可。

并且 $response_data=array('response'=>0,'message'=>'This is already added in db'); echo json_encode($response_data); die; 需要一个名为{"response":"already added","message":"This is already added in db"}

的回调

答案 1 :(得分:1)

如果您希望自己的应用检查互联网连接,可以使用此代码

boolean isInternet = isInternetOn();
if (isInternet) {  //write your code here    }

然后在您想要检查上述方法的互联网连接呼叫的任何地方

@Plan:name('ExecutionPlan')

@Import('InputStream:1.0.0')
define stream InputStream (id string, temp int);

/* Filter events with temp > 90 */
from InputStream[temp > 90]
insert into CriticalStream;

/* Aggregate within a lengthBatch window, while group by id*/
from CriticalStream#window.lengthBatch(2)
select id, temp, count() as count
group by id
insert into EventReporter;

/* Just for logging the result in the cosole */
from EventReporter#log("Logging EventReporter : ")
insert into #temp;