我在linux(ubuntu)上,并且在使用public class MainActivity extends AppCompatActivity {
TextView show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
show=findViewById(R.id.calls_text);
if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CALL_LOG ) != PackageManager.PERMISSION_GRANTED)
{
if(ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,Manifest.permission.READ_CALL_LOG))
{
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_CALL_LOG},1);
}
else
{
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_CALL_LOG},1);
}
}
else
{
getCallDetails();
String calls = getCallDetails();
show.setText(calls);
}
}
String getCallDetails()
{
StringBuilder sbin=new StringBuilder();
StringBuilder sbout=new StringBuilder();
StringBuilder missed=new StringBuilder();
StringBuilder sb=new StringBuilder();
sbin.append("Incoming Calls :\n");
sbout.append("Outgoing Calls :\n");
missed.append("Missed Calls :\n");
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,null,null,null,null);
assert managedCursor != null;
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
while(managedCursor.moveToNext())
{
String pnumber = managedCursor.getString(number);
String ctype = managedCursor.getString(type);
String cdate = managedCursor.getString(date);
Date cdaydate = new Date(Long.parseLong(cdate));
SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yy HH:mm");
String cdatetime = formater.format(cdaydate);
String cduration = managedCursor.getString(duration);
String dir="";
int dircode = Integer.parseInt(ctype);
switch (dircode)
{
case CallLog.Calls.OUTGOING_TYPE:
dir+="OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir+="INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir+="MISSED";
break;
}
if(dir.equalsIgnoreCase("OUTGOING"))
sbout.append("\nPhoneNumber: ").append(pnumber).append("\ntype: ").append(dir).append("\ndate : ").append(cdatetime).append("\nduration : ").append(cduration).append("\n\n");
if(dir.equalsIgnoreCase("INCOMING"))
sbin.append("\nPhoneNumber: "+pnumber+"\ntype: "+dir+"\ndate : "+cdatetime+"\nduration : "+cduration+"\n\n");
if(dir.equalsIgnoreCase("MISSED"))
missed.append("\nPhoneNumber: "+pnumber+"\ntype: "+dir+"\ndate : "+cdatetime+"\nduration : "+cduration+"\n\n");
}
managedCursor.close();
sbout.append("-------------------------\n");
sbin.append("-------------------------\n");
missed.append("-------------------------\n");
sb.append(sbin);
sb.append(sbout);
sb.append(missed);
return sb.toString();
}
}
创建项目后运行了npx react-native start
和npx react-native run-android
,但是我正在用手机运行该应用程序,但是当我打开它,我得到此页面https://imgur.com/a/t1CJh1Q,然后得到一个白色页面,如何使它工作?
答案 0 :(得分:1)
我是本机反应的新手,并且在物理设备上遇到相同的错误。 经过几次试验后解决了该问题,我断开了设备的连接,并再次处于开发人员模式,然后将其连接。我在使用expo,所以清除了expo缓存。